Diff for /parser3/src/classes/table.C between versions 1.354 and 1.357

version 1.354, 2020/12/15 17:10:29 version 1.357, 2020/12/26 23:09:08
Line 1259  static void join_nameless_row(Table& src Line 1259  static void join_nameless_row(Table& src
         *dest+=src[src.current()];          *dest+=src[src.current()];
 }  }
 static void _join(Request& r, MethodParams& params) {  static void _join(Request& r, MethodParams& params) {
         Table& src=*params.as_table(0, "source");          if(Table* src=params.as_table(0, "source")){
                   Table::Action_options o=get_action_options(r, params, 1, *src);
   
         Table::Action_options o=get_action_options(r, params, 1, src);                  Table& dest=GET_SELF(r, VTable).table();
                   if(src == &dest)
         Table& dest=GET_SELF(r, VTable).table();                          throw Exception(PARSER_RUNTIME, 0, "source and destination are same table");
         if(&src == &dest)  
                 throw Exception(PARSER_RUNTIME, 0, "source and destination are same table");                  if(dest.columns()) // dest is named
                           src->table_for_each(join_named_row, &dest, o);
         if(dest.columns()) // dest is named                  else // dest is nameless
                 src.table_for_each(join_named_row, &dest, o);                          src->table_for_each(join_nameless_row, &dest, o);
         else // dest is nameless          }
                 src.table_for_each(join_nameless_row, &dest, o);  
 }  }
   
 #ifndef DOXYGEN  #ifndef DOXYGEN
Line 1501  static void _select(Request& r, MethodPa Line 1501  static void _select(Request& r, MethodPa
         r.write(*new VTable(&result_table));          r.write(*new VTable(&result_table));
 }  }
   
   
   static void _rename(Request& r, MethodParams& params) {
           const String* name_from=NULL;
           const String* name_to=NULL;
           HashStringValue* names=NULL;
   
           if(params.count()>1){
                   name_from=&params.as_string(0, COLUMN_NAME_MUST_BE_STRING);
                   name_to=&params.as_string(1, COLUMN_NAME_MUST_BE_STRING);
           } else
                   names=params.as_hash(0);
   
           Table& table=GET_SELF(r, VTable).table();
           if(Table::columns_type columns=table.columns()) {
                   if(names){
                           for(int i=0; i<columns->count(); i++) {
                                   const String *column = columns->get(i);
                                   if(Value* vto=names->get(*column)){
                                           if(const String *sto=vto->get_string())
                                                   columns->put(i, sto);
                                           else
                                                   throw Exception(PARSER_RUNTIME, column, COLUMN_NAME_MUST_BE_STRING);
                                   }
                           }
                   } else if(name_from){
                           for(int i=0; i<columns->count(); i++) {
                                   const String *column = columns->get(i);
                                   if(*column == *name_from)
                                           columns->put(i, name_to);
                           }
                   }
                   table.column_names_init();
           } else
                   throw Exception(PARSER_RUNTIME, 0, "columns renaming is not supported for nameless tables");
   }
   
 // constructor  // constructor
   
 MTable::MTable(): Methoded("table") {  MTable::MTable(): Methoded("table") {
Line 1584  MTable::MTable(): Methoded("table") { Line 1620  MTable::MTable(): Methoded("table") {
   
         // ^table.select(expression) = table          // ^table.select(expression) = table
         add_native_method("select", Method::CT_DYNAMIC, _select, 1, 2);          add_native_method("select", Method::CT_DYNAMIC, _select, 1, 2);
   
           // ^table.rename[column name from;column name to] 
           // ^table.rename[ $.[column name from][column name to] ... ]
           add_native_method("rename", Method::CT_DYNAMIC, _rename, 1, 2);
 }  }

Removed from v.1.354  
changed lines
  Added in v.1.357


E-mail: