|
|
| version 1.355, 2020/12/17 19:51:21 | version 1.356, 2020/12/25 22:05:31 |
|---|---|
| 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=¶ms.as_string(0, COLUMN_NAME_MUST_BE_STRING); | |
| name_to=¶ms.as_string(1, COLUMN_NAME_MUST_BE_STRING); | |
| } else | |
| if (!(names=params.as_hash(0))) | |
| throw Exception(PARSER_RUNTIME, 0, CALLED_WITH_INVALID_OPTION); | |
| 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)){ | |
| const String *sto=vto->get_string(); | |
| if(!sto) | |
| throw Exception(PARSER_RUNTIME, column, COLUMN_NAME_MUST_BE_STRING); | |
| columns->put(i, sto); | |
| } | |
| } | |
| } else { | |
| 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(); | |
| } | |
| } | |
| // 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); | |
| } | } |