Diff for /parser3/src/classes/table.C between versions 1.313 and 1.314

version 1.313, 2016/03/31 21:46:20 version 1.314, 2016/07/28 21:48:57
Line 781  static void table_row_to_hash(Table::ele Line 781  static void table_row_to_hash(Table::ele
                         for(Array_iterator<int> i(*info->value_fields); i.has_next(); ) {                          for(Array_iterator<int> i(*info->value_fields); i.has_next(); ) {
                                 size_t value_field=i.next();                                  size_t value_field=i.next();
                                 if(value_field<row->count())                                  if(value_field<row->count())
                                         hash.put(                                          hash.put(*info->table->columns()->get(value_field), new VString(*row->get(value_field)));
                                                 *info->table->columns()->get(value_field),   
                                                 new VString(*row->get(value_field)));  
                         }                          }
   
                         exist=info->hash->put_dont_replace(*key, vhash);                          exist=info->hash->put_dont_replace(*key, vhash);
Line 811  static void table_row_to_hash(Table::ele Line 809  static void table_row_to_hash(Table::ele
                 }                  }
         }          }
         if(exist && info->distinct==D_ILLEGAL)          if(exist && info->distinct==D_ILLEGAL)
                 throw Exception(PARSER_RUNTIME,                  throw Exception(PARSER_RUNTIME, key, "duplicate key");
                         key,  
                         "duplicate key");  
 }  }
   
 Table2hash_value_type get_value_type(Value& vvalue_type){  Table2hash_value_type get_value_type(Value& vvalue_type){
Line 826  Table2hash_value_type get_value_type(Val Line 822  Table2hash_value_type get_value_type(Val
                 } else if (svalue_type == "hash") {                  } else if (svalue_type == "hash") {
                         return C_HASH;                          return C_HASH;
                 } else {                  } else {
                         throw Exception(PARSER_RUNTIME,                          throw Exception(PARSER_RUNTIME, &svalue_type, "must be 'hash', 'table' or 'string'");
                                 &svalue_type,  
                                 "must be 'hash', 'table' or 'string'");  
                 }                  }
         } else {          } else {
                 throw Exception(PARSER_RUNTIME,                  throw Exception(PARSER_RUNTIME, 0, "'type' must be string");
                         0,  
                         "'type' must be hash");  
         }          }
 }  }
   
Line 858  static void _hash(Request& r, MethodPara Line 850  static void _hash(Request& r, MethodPara
                                                                 value_type=C_TABLE;                                                                  value_type=C_TABLE;
                                                                 distinct=D_FIRST;                                                                  distinct=D_FIRST;
                                                         } else {                                                          } else {
                                                                 throw Exception(PARSER_RUNTIME,                                                                  throw Exception(PARSER_RUNTIME, &sdistinct, "must be 'tables' or true/false");
                                                                         &sdistinct,  
                                                                         "must be 'tables' or true/false");  
                                                         }                                                          }
                                                 } else {                                                  } else {
                                                         distinct=vdistinct_value.as_bool()?D_FIRST:D_ILLEGAL;                                                          distinct=vdistinct_value.as_bool()?D_FIRST:D_ILLEGAL;
Line 868  static void _hash(Request& r, MethodPara Line 858  static void _hash(Request& r, MethodPara
                                         }                                          }
                                         if(Value* vvalue_type_code=options->get(sql_value_type_name)) { // $.type ?                                          if(Value* vvalue_type_code=options->get(sql_value_type_name)) { // $.type ?
                                                 if(value_type==C_TABLE) // $.distinct[tables] already was specified                                                  if(value_type==C_TABLE) // $.distinct[tables] already was specified
                                                         throw Exception(PARSER_RUNTIME,                                                          throw Exception(PARSER_RUNTIME, 0, "you can't specify $.distinct[tables] and $.type[] together");
                                                                 0,  
                                                                 "you can't specify $.distinct[tables] and $.type[] together");  
   
                                                 valid_options++;                                                  valid_options++;
                                                 value_type=get_value_type(r.process_to_value(*vvalue_type_code));                                                  value_type=get_value_type(r.process_to_value(*vvalue_type_code));
                                         }                                          }
Line 887  static void _hash(Request& r, MethodPara Line 874  static void _hash(Request& r, MethodPara
                         Array<int> value_fields;                          Array<int> value_fields;
                         if(param_index==0){ // list of columns wasn't specified                          if(param_index==0){ // list of columns wasn't specified
                                 if(value_type==C_STRING) // $.type[string]                                  if(value_type==C_STRING) // $.type[string]
                                         throw Exception(PARSER_RUNTIME,                                          throw Exception(PARSER_RUNTIME, 0, "you must specify one value field with option $.type[string]");
                                                 0,  
                                                 "you must specify one value field with option $.type[string]");  
                                                                   
                                 for(size_t i=0; i<columns->count(); i++) // by all columns, including key                                  for(size_t i=0; i<columns->count(); i++) // by all columns, including key
                                         value_fields+=i;                                          value_fields+=i;
   
                         } else { // list of columns was specified                          } else { // list of columns was specified
                                 if(value_type==C_TABLE)                                  if(value_type==C_TABLE)
                                         throw Exception(PARSER_RUNTIME,                                          throw Exception(PARSER_RUNTIME, 0, "you can't specify value field(s) with option $.distinct[tables] or $.type[tables]");
                                                 0,  
                                                 "you can't specify value field(s) with option $.distinct[tables] or $.type[tables]");  
   
                                 Value& value_fields_param=params.as_no_junction(param_index, "value field(s) must not be code");                                  Value& value_fields_param=params.as_no_junction(param_index, "value field(s) must not be code");
                                 if(value_fields_param.is_string()) { // one column as string was specified                                  if(value_fields_param.is_string()) { // one column as string was specified
Line 909  static void _hash(Request& r, MethodPara Line 892  static void _hash(Request& r, MethodPara
                                                 value_fields +=self_table.column_name2index(value_field_name, true);                                                  value_fields +=self_table.column_name2index(value_field_name, true);
                                         }                                          }
                                 } else                                  } else
                                         throw Exception(PARSER_RUNTIME,                                          throw Exception(PARSER_RUNTIME, 0, "value field(s) must be string or table");
                                                 0,  
                                                 "value field(s) must be string or table");  
                         }                          }
   
                         if(value_type==C_STRING && value_fields.count()!=1)                          if(value_type==C_STRING && value_fields.count()!=1)
                                 throw Exception(PARSER_RUNTIME,                                  throw Exception(PARSER_RUNTIME, 0, "you can specify only one value field with option $.type[string]");
                                         0,  
                                         "you can specify only one value field with option $.type[string]");  
   
                         {                          {
                                 Value* key_param=&params[0];                                  Value* key_param=&params[0];
Line 932  static void _hash(Request& r, MethodPara Line 911  static void _hash(Request& r, MethodPara
                                         /*row=*/0,                                          /*row=*/0,
                                         value_type                                          value_type
                                 };                                  };
                                 info.key_field=(info.key_code?-1                                  info.key_field=(info.key_code ? -1 : self_table.column_name2index(key_param->as_string(), true));
                                                 :self_table.column_name2index(key_param->as_string(), true));  
   
                                 int saved_current=self_table.current();                                  int saved_current=self_table.current();
                                 self_table.for_each(table_row_to_hash, &info);                                  self_table.for_each(table_row_to_hash, &info);

Removed from v.1.313  
changed lines
  Added in v.1.314


E-mail: