|
|
| version 1.162, 2002/09/17 09:30:06 | version 1.164, 2002/09/17 14:34:53 |
|---|---|
| Line 42 static void get_copy_options(Request& r, | Line 42 static void get_copy_options(Request& r, |
| Value& voptions=params->as_no_junction(param_index, "options must be hash, not code"); | Value& voptions=params->as_no_junction(param_index, "options must be hash, not code"); |
| if(!voptions.is_string()) { | if(!voptions.is_string()) { |
| if(Hash *options=voptions.get_hash(&method_name)) { | if(Hash *options=voptions.get_hash(&method_name)) { |
| if(Value *voffset=(Value *)options->get(*sql_offset_name)) | int valid_options=0; |
| if(Value *voffset=(Value *)options->get(*sql_offset_name)) { | |
| valid_options++; | |
| if(voffset->is_string()) { | if(voffset->is_string()) { |
| const String& soffset=*voffset->get_string(); | const String& soffset=*voffset->get_string(); |
| if(soffset == "cur") | if(soffset == "cur") |
| Line 53 static void get_copy_options(Request& r, | Line 55 static void get_copy_options(Request& r, |
| "must be 'cur' string or expression"); | "must be 'cur' string or expression"); |
| } else | } else |
| offset=r.process_to_value(*voffset).as_int(); | offset=r.process_to_value(*voffset).as_int(); |
| if(Value *vlimit=(Value *)options->get(*sql_limit_name)) | } |
| if(Value *vlimit=(Value *)options->get(*sql_limit_name)) { | |
| valid_options++; | |
| limit=r.process_to_value(*vlimit).as_int(); | limit=r.process_to_value(*vlimit).as_int(); |
| } | |
| if(valid_options!=options->size()) | |
| throw Exception("parser.runtime", | |
| &method_name, | |
| "called with invalid option"); | |
| } else | } else |
| throw Exception("parser.runtime", | throw Exception("parser.runtime", |
| &method_name, | &method_name, |
| Line 299 struct Row_info { | Line 308 struct Row_info { |
| int key_field; | int key_field; |
| Array *value_fields; | Array *value_fields; |
| Hash *hash; | Hash *hash; |
| bool distinct; | |
| }; | }; |
| #endif | #endif |
| static void table_row_to_hash(Array::Item *value, void *info) { | static void table_row_to_hash(Array::Item *value, void *info) { |
| Line 319 static void table_row_to_hash(Array::Ite | Line 329 static void table_row_to_hash(Array::Ite |
| const String& key=*row.get_string(ri.key_field); | const String& key=*row.get_string(ri.key_field); |
| if(ri.hash->put_dont_replace(key, &result)) // put. existed? | if(ri.hash->put_dont_replace(key, &result)) // put. existed? |
| throw Exception("parser.runtime", | if(!ri.distinct) |
| &key, | throw Exception("parser.runtime", |
| "duplicate key"); | &key, |
| "duplicate key"); | |
| } | } |
| } | } |
| static void _hash(Request& r, const String& method_name, MethodParams *params) { | static void _hash(Request& r, const String& method_name, MethodParams *params) { |
| Line 334 static void _hash(Request& r, const Stri | Line 345 static void _hash(Request& r, const Stri |
| "key field name must not be code").as_string(); | "key field name must not be code").as_string(); |
| int key_field=self_table.column_name2index(key_field_name, true); | int key_field=self_table.column_name2index(key_field_name, true); |
| bool distinct=false; | |
| int param_index=params->size()-1; | |
| if(Hash *options= | |
| params->as_no_junction(param_index, "param must not be code").get_hash(0)) { | |
| --param_index; | |
| int valid_options=0; | |
| if(Value *vdistinct=(Value *)options->get(*sql_distinct_name)) { | |
| valid_options++; | |
| distinct=r.process_to_value(*vdistinct).as_bool(); | |
| } | |
| if(valid_options!=options->size()) | |
| throw Exception("parser.runtime", | |
| &method_name, | |
| "called with invalid option"); | |
| } | |
| if(param_index==2) // bad options param type | |
| throw Exception("parser.runtime", | |
| &method_name, | |
| "options must be hash"); | |
| Array value_fields(pool); | Array value_fields(pool); |
| if(params->size()>1) { | if(param_index>0) { |
| Value& value_fields_param=params->as_no_junction(1, "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()) { | if(value_fields_param.is_string()) { |
| value_fields+=self_table.column_name2index(value_fields_param.as_string(), true); | value_fields+=self_table.column_name2index(value_fields_param.as_string(), true); |
| } else if(Table *value_fields_table=value_fields_param.get_table()) { | } else if(Table *value_fields_table=value_fields_param.get_table()) { |
| Line 356 static void _hash(Request& r, const Stri | Line 387 static void _hash(Request& r, const Stri |
| } | } |
| // integers: key_field & value_fields | // integers: key_field & value_fields |
| Row_info row_info={&self_table, key_field, &value_fields, result.get_hash(0)}; | Row_info row_info={&self_table, key_field, &value_fields, result.get_hash(0), distinct}; |
| self_table.for_each(table_row_to_hash, &row_info); | self_table.for_each(table_row_to_hash, &row_info); |
| } | } |
| r.write_no_lang(result); | r.write_no_lang(result); |
| Line 604 static void _sql(Request& r, const Strin | Line 635 static void _sql(Request& r, const Strin |
| 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_string()) | 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)) | int valid_options=0; |
| if(Value *vlimit=(Value *)options->get(*sql_limit_name)) { | |
| valid_options++; | |
| limit=(ulong)r.process_to_value(*vlimit).as_double(); | limit=(ulong)r.process_to_value(*vlimit).as_double(); |
| if(Value *voffset=(Value *)options->get(*sql_offset_name)) | } |
| if(Value *voffset=(Value *)options->get(*sql_offset_name)) { | |
| valid_options++; | |
| offset=(ulong)r.process_to_value(*voffset).as_double(); | offset=(ulong)r.process_to_value(*voffset).as_double(); |
| } | |
| if(valid_options!=options->size()) | |
| throw Exception("parser.runtime", | |
| &method_name, | |
| "called with invalid option"); | |
| } else | } else |
| throw Exception("parser.runtime", | throw Exception("parser.runtime", |
| &method_name, | &method_name, |
| Line 732 MTable::MTable(Pool& apool) : Methoded(a | Line 772 MTable::MTable(Pool& apool) : Methoded(a |
| // ^table:hash[key field name] | // ^table:hash[key field name] |
| // ^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, 2); | add_native_method("hash", Method::CT_DYNAMIC, _hash, 1, 3); |
| // ^table.sort{string-key-maker} ^table.sort{string-key-maker}[desc|asc] | // ^table.sort{string-key-maker} ^table.sort{string-key-maker}[desc|asc] |
| // ^table.sort(numeric-key-maker) ^table.sort(numeric-key-maker)[desc|asc] | // ^table.sort(numeric-key-maker) ^table.sort(numeric-key-maker)[desc|asc] |