|
|
| version 1.155, 2002/08/01 11:41:13 | version 1.157, 2002/08/06 14:23:22 |
|---|---|
| Line 30 public: // Methoded | Line 30 public: // Methoded |
| // methods | // methods |
| static void get_copy_options(Request& r, const String& method_name, MethodParams *params, int param_index, | |
| const Table& source, | |
| int& offset, | |
| int& limit) { | |
| offset=0; | |
| limit=0; | |
| if(params->size()<=param_index) | |
| return; | |
| Value& voptions=params->as_no_junction(param_index, "options must be hash, not code"); | |
| if(!voptions.is_string()) | |
| if(Hash *options=voptions.get_hash(&method_name)) { | |
| if(Value *voffset=(Value *)options->get(*sql_offset_name)) | |
| if(voffset->is_string()) { | |
| const String& soffset=*voffset->get_string(); | |
| if(soffset == "cur") | |
| offset=source.current(); | |
| else | |
| throw Exception("parser.runtime", | |
| &soffset, | |
| "must be 'cur' string or expression"); | |
| } else | |
| offset=r.process_to_value(*voffset).as_int(); | |
| if(Value *vlimit=(Value *)options->get(*sql_limit_name)) | |
| limit=r.process_to_value(*vlimit).as_int(); | |
| } else | |
| throw Exception("parser.runtime", | |
| &method_name, | |
| "options must be hash"); | |
| } | |
| static void _create(Request& r, const String& method_name, MethodParams *params) { | static void _create(Request& r, const String& method_name, MethodParams *params) { |
| Pool& pool=r.pool(); | Pool& pool=r.pool(); |
| // clone? | // clone/copy part? |
| if(params->size()==1) | if(const Table *source=params->get(0).get_table()) { |
| if(const Table *source=params->get(0).get_table()) { | int offset, limit; |
| static_cast<VTable *>(r.self)->set_table(*new(pool) Table(*source)); | get_copy_options(r, method_name, params, 1, *source, |
| return; | offset, limit); |
| } | static_cast<VTable *>(r.self)->set_table(*new(pool) Table(pool, *source, offset, limit)); |
| return; | |
| } | |
| // data is last parameter | // data is last parameter |
| Temp_lang temp_lang(r, String::UL_PASS_APPENDED); | Temp_lang temp_lang(r, String::UL_PASS_APPENDED); |
| Line 225 static void _offset(Request& r, const St | Line 258 static void _offset(Request& r, const St |
| throw Exception("parser.runtime", | throw Exception("parser.runtime", |
| &whence, | &whence, |
| "is invalid whence, valid are 'cur' or 'set'"); | "is invalid whence, valid are 'cur' or 'set'"); |
| } | } |
| Value& offset_expr=params->as_junction(params->size()-1, "offset must be expression"); | Value& offset_expr=params->as_junction(params->size()-1, "offset must be expression"); |
| table.offset(absolute, r.process_to_value(offset_expr).as_int()); | table.offset(absolute, r.process_to_value(offset_expr).as_int()); |
| Line 480 static void _join(Request& r, const Stri | Line 513 static void _join(Request& r, const Stri |
| &method_name, | &method_name, |
| "source and destination are same table"); | "source and destination are same table"); |
| int offset, limit; | |
| get_copy_options(r, method_name, params, 1, src, | |
| offset, limit); | |
| if(const Array *dest_columns=dest.columns()) { // dest is named | if(const Array *dest_columns=dest.columns()) { // dest is named |
| int saved_src_current=src.current(); | int saved_src_current=src.current(); |
| for(int src_row=0; src_row<src.size(); src_row++) { | int m=src.size()-offset; |
| if(!limit || limit>m) | |
| limit=m; | |
| int end=offset+limit; | |
| for(int src_row=offset; src_row<end; src_row++) { | |
| src.set_current(src_row); | src.set_current(src_row); |
| Array& dest_row=*new(pool) Array(pool); | Array& dest_row=*new(pool) Array(pool); |
| for(int dest_column=0; dest_column<dest_columns->size(); dest_column++) { | for(int dest_column=0; dest_column<dest_columns->size(); dest_column++) { |
| Line 554 static void _sql(Request& r, const Strin | Line 595 static void _sql(Request& r, const Strin |
| ulong offset=0; | ulong offset=0; |
| if(params->size()>1) { | if(params->size()>1) { |
| Value& voptions=params->as_no_junction(1, "options must be hash, not code"); | Value& voptions=params->as_no_junction(1, "options must be hash, not code"); |
| if(voptions.is_defined()) | if(!voptions.is_string()) |
| if(Hash *options=voptions.get_hash(&method_name)) { | if(Hash *options=voptions.get_hash(&method_name)) { |
| if(Value *vlimit=(Value *)options->get(*sql_limit_name)) | if(Value *vlimit=(Value *)options->get(*sql_limit_name)) |
| limit=(ulong)r.process_to_value(*vlimit).as_double(); | limit=(ulong)r.process_to_value(*vlimit).as_double(); |
| Line 705 MTable::MTable(Pool& apool) : Methoded(a | Line 746 MTable::MTable(Pool& apool) : Methoded(a |
| // ^table.append{r{tab}e{tab}c{tab}o{tab}r{tab}d} | // ^table.append{r{tab}e{tab}c{tab}o{tab}r{tab}d} |
| add_native_method("append", Method::CT_DYNAMIC, _append, 1, 1); | add_native_method("append", Method::CT_DYNAMIC, _append, 1, 1); |
| // ^table.join[table] | // ^table.join[table][$.limit(10) $.offset(1) $.offset[cur] ] |
| add_native_method("join", Method::CT_DYNAMIC, _join, 1, 1); | add_native_method("join", Method::CT_DYNAMIC, _join, 1, 2); |
| // ^table:sql[query] | // ^table:sql[query] |