--- parser3/src/classes/table.C 2016/07/29 13:30:42 1.315 +++ parser3/src/classes/table.C 2016/08/15 15:14:26 1.318 @@ -22,7 +22,7 @@ #define USE_STRINGSTREAM #endif -volatile const char * IDENT_TABLE_C="$Id: table.C,v 1.315 2016/07/29 13:30:42 moko Exp $"; +volatile const char * IDENT_TABLE_C="$Id: table.C,v 1.318 2016/08/15 15:14:26 moko Exp $"; // class @@ -73,9 +73,7 @@ static Table::Action_options get_action_ if(soffset == "cur") result.offset=source.current(); else - throw Exception(PARSER_RUNTIME, - &soffset, - "must be 'cur' string or expression"); + throw Exception(PARSER_RUNTIME, &soffset, "must be 'cur' string or expression"); } else result.offset=r.process_to_value(*voffset).as_int(); } @@ -109,9 +107,7 @@ struct TableSeparators { if(Value* vseparator=options.get(PA_COLUMN_SEPARATOR_NAME)) { scolumn=&vseparator->as_string(); if(scolumn->length()!=1) - throw Exception(PARSER_RUNTIME, - scolumn, - "separator must be one character long"); + throw Exception(PARSER_RUNTIME, scolumn, "separator must be one character long"); column=scolumn->first_char(); result++; } @@ -121,9 +117,7 @@ struct TableSeparators { encloser=0; } else { if(sencloser->length()!=1) - throw Exception(PARSER_RUNTIME, - sencloser, - "encloser must be one character long"); + throw Exception(PARSER_RUNTIME, sencloser, "encloser must be one character long"); encloser=sencloser->first_char(); } result++; @@ -149,9 +143,7 @@ static void _create(Request& r, MethodPa if(params[0].is_string()){ // can be nameless only const String& snameless=params.as_string(0, "called with more then 1 param, first param may be only string 'nameless' or junction"); if(snameless!="nameless") - throw Exception(PARSER_RUNTIME, - &snameless, - "table::create called with more then 1 param, first param may be only 'nameless'"); + throw Exception(PARSER_RUNTIME, &snameless, "table::create called with more then 1 param, first param may be only 'nameless'"); nameless=true; data_param_index++; } @@ -169,9 +161,7 @@ static void _create(Request& r, MethodPa options=new HashStringValue(*options); separators.load(*options); if(separators.encloser){ - throw Exception(PARSER_RUNTIME, - 0, - "encloser not supported for table::create yet"); + throw Exception(PARSER_RUNTIME, 0, "encloser not supported for table::create yet"); } } @@ -583,9 +573,7 @@ static void _save(Request& r, MethodPara } if(param_indexvalue_type) { case C_STRING: { - size_t index=info->value_fields->get(0); - exist=info->hash->put_dont_replace(*key, (index < row->count()) ? new VString(*row->get(index)) : new VString()); + if(info->value_fields->count()){ + size_t index=info->value_fields->get(0); + exist=info->hash->put_dont_replace(*key, (index < row->count()) ? new VString(*row->get(index)) : VString::empty()); + } else { + exist=info->hash->put_dont_replace(*key, VString::empty()); + } break; } case C_HASH: { @@ -899,10 +886,12 @@ static void _hash(Request& r, MethodPara throw Exception(PARSER_RUNTIME, 0, "you can't specify value field(s) with option $.distinct[tables] or $.type[tables]"); Value& value_fields_param=params[1]; - if(value_fields_param.get_junction()){ + if(value_fields_param.get_junction()){ // code specified value_code=&value_fields_param; } else if(value_fields_param.is_string()) { // one column as string was specified - value_fields+=self_table.column_name2index(*value_fields_param.get_string(), true); + const String &field_name=*value_fields_param.get_string(); + if(!field_name.is_empty()) + value_fields+=self_table.column_name2index(field_name, true); } else if(Table* value_fields_table=value_fields_param.get_table()) { // list of columns were specified in table for(Array_iterator i(*value_fields_table); i.has_next(); ) { const String& value_field_name =*i.next()->get(0); @@ -1083,7 +1072,6 @@ static void _foreach(Request& r, MethodP Table& table=GET_SELF(r, VTable).table(); size_t saved_current=table.current(); - size_t size=table.count(); const String* rownum_var_name=rownum_name.is_empty()? 0 : &rownum_name; const String* value_var_name=value_name.is_empty()? 0 : &value_name; @@ -1092,7 +1080,7 @@ static void _foreach(Request& r, MethodP if(delim_maybe_code) { // delimiter set bool need_delim=false; - for(size_t row=0; row