|
|
| version 1.372, 2024/11/16 02:57:05 | version 1.375, 2024/12/06 22:03:58 |
|---|---|
| Line 638 static void _save(Request& r, MethodPara | Line 638 static void _save(Request& r, MethodPara |
| else | else |
| --param_index; | --param_index; |
| const String& file_name=params.as_string(param_index++, FILE_NAME_MUST_NOT_BE_CODE); | const String& file_name=params.as_string(param_index++, FILE_NAME_MUST_BE_STRING); |
| String file_spec=r.full_disk_path(file_name); | String file_spec=r.full_disk_path(file_name); |
| if(do_append && file_exist(file_spec)) | if(do_append && file_exist(file_spec)) |
| Line 1001 static void _hash(Request& r, MethodPara | Line 1001 static void _hash(Request& r, MethodPara |
| }; | }; |
| info.key_field=(info.key_code ? -1 : self_table.column_name2index(key_param->as_string(), true)); | info.key_field=(info.key_code ? -1 : self_table.column_name2index(key_param->as_string(), true)); |
| self_table.for_each(table_row_to_hash, &info); | Temp_current tc(self_table); |
| for(Table::RobustIterator i(self_table); i; i.next()) { | |
| table_row_to_hash(i.value(), &info); | |
| } | |
| result.extract_default(); | result.extract_default(); |
| r.write(result); | r.write(result); |
| } | } |
| static void _array(Request& r, MethodParams& params) { | |
| Table& table=GET_SELF(r, VTable).table(); | |
| VArray& result=*new VArray; | |
| ArrayValue& array=result.array(); | |
| Table2hash_value_type value_type=C_HASH; | |
| Array<int> value_fields; | |
| Value* value_code=0; | |
| if(params.count()>0) { | |
| if(params[0].get_junction()){ | |
| value_type=C_CODE; | |
| value_code=¶ms[0]; | |
| } else if(params[0].is_string()) { | |
| const String &field_name=*params[0].get_string(); | |
| if(!field_name.is_empty()){ | |
| value_type=C_STRING; | |
| value_fields+=table.column_name2index(field_name, true); | |
| } | |
| } else { | |
| throw Exception(PARSER_RUNTIME, 0, "value field must be string or code or empty"); | |
| } | |
| } | |
| Temp_current tc(table); | |
| for(Table::RobustIterator i(table); i; i.next()) { | |
| switch(value_type) { | |
| case C_STRING: { | |
| size_t index=value_fields.get(0); | |
| Table::element_type row=i.value(); | |
| array+=(index < row->count() ? new VString(*row->get(index)) : VString::empty()); | |
| break; | |
| } | |
| case C_HASH: { | |
| VHash* vhash=new VHash; | |
| HashStringValue& hash=vhash->hash(); | |
| Table::element_type row=i.value(); | |
| Table::columns_type columns=table.columns(); | |
| for(size_t index=0; index<row->count(); index++) { | |
| hash.put(columns && index < columns->count() ? *columns->get(index) : String(pa_uitoa(index)), new VString(*row->get(index))); | |
| } | |
| array+=vhash; | |
| break; | |
| } | |
| case C_CODE: { | |
| table.set_current(i.index()); | |
| array+=&r.process(*value_code); | |
| break; | |
| } | |
| } | |
| } | |
| r.write(result); | |
| } | |
| static void _cells(Request& r, MethodParams& params) { | static void _cells(Request& r, MethodParams& params) { |
| Table& self_table=GET_SELF(r, VTable).table(); | Table& self_table=GET_SELF(r, VTable).table(); |
| size_t row_size=self_table[self_table.current()]->count(); // number of columns in current row | size_t row_size=self_table[self_table.current()]->count(); // number of columns in current row |
| Line 1614 MTable::MTable(): Methoded("table") { | Line 1672 MTable::MTable(): Methoded("table") { |
| // ^table.hash[key field name][value field name(s) string/table] | // ^table.hash[key field name][value field name(s) string/table] |
| add_native_method("hash", Method::CT_DYNAMIC, _hash, 1, 3); | add_native_method("hash", Method::CT_DYNAMIC, _hash, 1, 3); |
| // ^table.array[] | |
| // ^table.array[string] | |
| // ^table.array{code} | |
| add_native_method("array", Method::CT_DYNAMIC, _array, 0, 1); | |
| // ^table.cells[] | // ^table.cells[] |
| // ^table.cells(limit) | // ^table.cells(limit) |
| add_native_method("cells", Method::CT_DYNAMIC, _cells, 0, 1); | add_native_method("cells", Method::CT_DYNAMIC, _cells, 0, 1); |