|
|
| version 1.236, 2007/10/16 09:30:10 | version 1.239, 2008/02/14 09:10:24 |
|---|---|
| Line 429 void maybe_enclose( ostringstream& to, c | Line 429 void maybe_enclose( ostringstream& to, c |
| /* | /* |
| static void _save_old(Request& r, MethodParams& params) { | static void _save_old(Request& r, MethodParams& params) { |
| const String& first_arg=params.as_string(0, "first argument must not be code"); | const String& first_arg=params.as_string(0, FIRST_ARG_MUST_NOT_BE_CODE); |
| size_t param_index=1; | size_t param_index=1; |
| bool do_append=false; | bool do_append=false; |
| Line 515 static void _save_old(Request& r, Method | Line 515 static void _save_old(Request& r, Method |
| */ | */ |
| static void _save(Request& r, MethodParams& params) { | static void _save(Request& r, MethodParams& params) { |
| const String& first_arg=params.as_string(0, "first argument must not be code"); | const String& first_arg=params.as_string(0, FIRST_ARG_MUST_NOT_BE_CODE); |
| size_t param_index=1; | size_t param_index=1; |
| bool do_append=false; | bool do_append=false; |
| Line 572 static void _save(Request& r, MethodPara | Line 572 static void _save(Request& r, MethodPara |
| if(separators.encloser) { | if(separators.encloser) { |
| ost<<separators.encloser<<column<<separators.encloser; | ost<<separators.encloser<<column<<separators.encloser; |
| } else { | } else { |
| ost<<column; | ost<<column; |
| } | } |
| if(column<lsize-1){ | if(column<lsize-1){ |
| ost<<separators.column; | ost<<separators.column; |
| Line 766 Table2hash_value_type get_value_type(Val | Line 766 Table2hash_value_type get_value_type(Val |
| static void _hash(Request& r, MethodParams& params) { | static void _hash(Request& r, MethodParams& params) { |
| Table& self_table=GET_SELF(r, VTable).table(); | Table& self_table=GET_SELF(r, VTable).table(); |
| VHash& result=*new VHash; | VHash& result=*new VHash; |
| if(Table::columns_type columns=self_table.columns()) | if(Table::columns_type columns=self_table.columns()){ |
| if(columns->count()>0) { | if(columns->count()>0) { |
| Table2hash_distint distinct=D_ILLEGAL; | Table2hash_distint distinct=D_ILLEGAL; |
| Table2hash_value_type value_type=C_HASH; | Table2hash_value_type value_type=C_HASH; |
| int param_index=params.count()-1; | int param_index=params.count()-1; |
| if(param_index>0) { | if(param_index>0) { |
| if(HashStringValue* options= | if(HashStringValue* options=params.as_no_junction(param_index, PARAM_MUST_NOT_BE_CODE).get_hash()){ // options where specified |
| params.as_no_junction(param_index, "param must not be code").get_hash() | |
| ){ | |
| --param_index; | --param_index; |
| int valid_options=0; | int valid_options=0; |
| if(Value* vdistinct_code=options->get(sql_distinct_name)) { | if(Value* vdistinct_code=options->get(sql_distinct_name)) { // $.distinct ? |
| valid_options++; | valid_options++; |
| Value& vdistinct_value=r.process_to_value(*vdistinct_code); | Value& vdistinct_value=r.process_to_value(*vdistinct_code); |
| if(vdistinct_value.is_string()) { | if(vdistinct_value.is_string()) { |
| Line 785 static void _hash(Request& r, MethodPara | Line 783 static void _hash(Request& r, MethodPara |
| if(sdistinct=="tables") { | if(sdistinct=="tables") { |
| value_type=C_TABLE; | value_type=C_TABLE; |
| distinct=D_FIRST; | distinct=D_FIRST; |
| } else | } else { |
| throw Exception(PARSER_RUNTIME, | throw Exception(PARSER_RUNTIME, |
| &sdistinct, | &sdistinct, |
| "must be 'tables' or true/false"); | "must be 'tables' or true/false"); |
| } else | } |
| } else { | |
| distinct=vdistinct_value.as_bool()?D_FIRST:D_ILLEGAL; | distinct=vdistinct_value.as_bool()?D_FIRST:D_ILLEGAL; |
| } | |
| } | } |
| if(Value* vvalue_type_code=options->get(sql_value_type_name)) { | if(Value* vvalue_type_code=options->get(sql_value_type_name)) { // $.type ? |
| if(value_type==C_TABLE){ // $.distinct[tables] was specified already | if(value_type==C_TABLE) // $.distinct[tables] already was specified |
| throw Exception(PARSER_RUNTIME, | throw Exception(PARSER_RUNTIME, |
| 0, | 0, |
| "you can't specify $.distinct[tables] and $.type[] together."); | "you can't specify $.distinct[tables] and $.type[] together"); |
| } else { | |
| valid_options++; | valid_options++; |
| value_type=get_value_type(r.process_to_value(*vvalue_type_code)); | value_type=get_value_type(r.process_to_value(*vvalue_type_code)); |
| } | } |
| } | |
| if(valid_options!=options->count()) | if(valid_options!=options->count()) |
| throw Exception(PARSER_RUNTIME, | throw Exception(PARSER_RUNTIME, |
| Line 809 static void _hash(Request& r, MethodPara | Line 808 static void _hash(Request& r, MethodPara |
| "called with invalid option"); | "called with invalid option"); |
| } | } |
| } | } |
| if(param_index==2) // bad options param type | |
| if(param_index==2) // options was specified but not as hash | |
| throw Exception(PARSER_RUNTIME, | throw Exception(PARSER_RUNTIME, |
| 0, | 0, |
| "options must be hash"); | "options must be hash"); |
| Array<int> value_fields; | Array<int> value_fields; |
| if(param_index>0) { | if(param_index==0){ // list of columns wasn't specified |
| if(value_type==C_STRING) // $.type[string] | |
| throw Exception(PARSER_RUNTIME, | |
| 0, | |
| "you must specify one value field with option $.type[string]"); | |
| for(size_t i=0; i<columns->count(); i++) // by all columns, including key | |
| value_fields+=i; | |
| } else { // list of columns was specified | |
| if(value_type==C_TABLE) | if(value_type==C_TABLE) |
| throw Exception(PARSER_RUNTIME, | throw Exception(PARSER_RUNTIME, |
| 0, | 0, |
| "in distinct[tables] mode you may not specify value field(s)"); | "you can't specify value field(s) with option $.distinct[tables] or $.type[tables]"); |
| Value& value_fields_param=params.as_no_junction(param_index, "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()) { // one column as string was specified |
| value_fields+=self_table.column_name2index( | value_fields+=self_table.column_name2index(*value_fields_param.get_string(), true); |
| *value_fields_param.get_string(), true); | } else if(Table* value_fields_table=value_fields_param.get_table()) { // list of columns were specified in table |
| } else if(Table* value_fields_table=value_fields_param.get_table()) { | for(Array_iterator<Table::element_type> i(*value_fields_table); i.has_next(); ) { |
| for(Array_iterator<Table::element_type> i(*value_fields_table); | const String& value_field_name =*i.next()->get(0); |
| i.has_next(); ) { | value_fields +=self_table.column_name2index(value_field_name, true); |
| const String& value_field_name | |
| =*i.next()->get(0); | |
| value_fields | |
| +=self_table.column_name2index(value_field_name, true); | |
| } | } |
| } else | } else |
| throw Exception(PARSER_RUNTIME, | throw Exception(PARSER_RUNTIME, |
| 0, | 0, |
| "value field(s) must be string or table"); | "value field(s) must be string or table"); |
| } else { // by all columns, including key | |
| if(value_type==C_STRING) | |
| throw Exception(PARSER_RUNTIME, | |
| 0, | |
| "with $.type[string] you must specify one value field(s)"); | |
| // if(!(distinct!=D_ILLEGAL && distinct!=D_FIRST)) | |
| for(size_t i=0; i<columns->count(); i++) | |
| value_fields+=i; | |
| } | } |
| if(value_type==C_STRING && value_fields.count()!=1) | if(value_type==C_STRING && value_fields.count()!=1) |
| throw Exception(PARSER_RUNTIME, | throw Exception(PARSER_RUNTIME, |
| 0, | 0, |
| "you can specify one value field with this $.type[]."); | "you can specify only one value field with option $.type[string]"); |
| { | { |
| Value* key_param=¶ms[0]; | Value* key_param=¶ms[0]; |
| Line 875 static void _hash(Request& r, MethodPara | Line 872 static void _hash(Request& r, MethodPara |
| result.extract_default(); | result.extract_default(); |
| } | } |
| } | } |
| } | |
| r.write_no_lang(result); | r.write_no_lang(result); |
| } | } |
| Line 1303 MTable::MTable(): Methoded("table") { | Line 1301 MTable::MTable(): Methoded("table") { |
| // ^table.menu{code}[delim] | // ^table.menu{code}[delim] |
| add_native_method("menu", Method::CT_DYNAMIC, _menu, 1, 2); | add_native_method("menu", Method::CT_DYNAMIC, _menu, 1, 2); |
| // ^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, 3); | 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] |
| Line 1324 MTable::MTable(): Methoded("table") { | Line 1322 MTable::MTable(): Methoded("table") { |
| add_native_method("join", Method::CT_DYNAMIC, _join, 1, 2); | add_native_method("join", Method::CT_DYNAMIC, _join, 1, 2); |
| // ^table:sql[query] | // ^table::sql[query] |
| // ^table:sql[query][$.limit(1) $.offset(2)] | // ^table::sql[query][$.limit(1) $.offset(2)] |
| add_native_method("sql", Method::CT_DYNAMIC, _sql, 1, 2); | add_native_method("sql", Method::CT_DYNAMIC, _sql, 1, 2); |
| // ^table:columns[[column name]] | // ^table.columns[[column name]] |
| add_native_method("columns", Method::CT_DYNAMIC, _columns, 0, 1); | add_native_method("columns", Method::CT_DYNAMIC, _columns, 0, 1); |
| // ^table.select(expression) = table | // ^table.select(expression) = table |