|
|
| version 1.280, 2011/05/15 13:20:07 | version 1.282, 2011/11/19 04:15:31 |
|---|---|
| Line 471 static void _save(Request& r, MethodPara | Line 471 static void _save(Request& r, MethodPara |
| output_column_names=false; | output_column_names=false; |
| TableSeparators separators; | TableSeparators separators; |
| if(param_index<params.count()) { | if(param_index<params.count()) |
| Value& voptions=params.as_no_junction(param_index++, "additional params must be hash"); | if(HashStringValue* options=params.as_hash(param_index++, |
| if( voptions.is_defined() && !voptions.is_string() ) { | "additional params must be hash", |
| if(HashStringValue* options=voptions.get_hash()) { | "additional params must be hash (did you spell mode parameter correctly?)" |
| int valid_options=separators.load(*options); | )) { |
| if(valid_options!=options->count()) | int valid_options=separators.load(*options); |
| throw Exception(PARSER_RUNTIME, 0, CALLED_WITH_INVALID_OPTION); | if(valid_options!=options->count()) |
| } else { | throw Exception(PARSER_RUNTIME, 0, CALLED_WITH_INVALID_OPTION); |
| throw Exception(PARSER_RUNTIME, | |
| 0, | |
| "additional params must be hash (did you spell mode parameter correctly?)"); | |
| } | |
| } | } |
| } | |
| if(param_index<params.count()) | if(param_index<params.count()) |
| throw Exception(PARSER_RUNTIME, | throw Exception(PARSER_RUNTIME, |
| 0, | 0, |
| Line 1161 static void _sql(Request& r, MethodParam | Line 1157 static void _sql(Request& r, MethodParam |
| HashStringValue* bind=0; | HashStringValue* bind=0; |
| ulong limit=SQL_NO_LIMIT; | ulong limit=SQL_NO_LIMIT; |
| ulong offset=0; | ulong offset=0; |
| if(params.count()>1) { | if(params.count()>1) |
| Value& voptions=params.as_no_junction(1, "options must be hash, not code"); | if(HashStringValue* options=params.as_hash(1)) { |
| if(voptions.is_defined() && !voptions.is_string()) | int valid_options=0; |
| if(HashStringValue* options=voptions.get_hash()) { | if(Value* vbind=options->get(sql_bind_name)) { |
| int valid_options=0; | valid_options++; |
| if(Value* vbind=options->get(sql_bind_name)) { | bind=vbind->get_hash(); |
| valid_options++; | } |
| bind=vbind->get_hash(); | if(Value* vlimit=options->get(sql_limit_name)) { |
| } | valid_options++; |
| if(Value* vlimit=options->get(sql_limit_name)) { | limit=(ulong)r.process_to_value(*vlimit).as_double(); |
| valid_options++; | } |
| limit=(ulong)r.process_to_value(*vlimit).as_double(); | if(Value* voffset=options->get(sql_offset_name)) { |
| } | valid_options++; |
| if(Value* voffset=options->get(sql_offset_name)) { | offset=(ulong)r.process_to_value(*voffset).as_double(); |
| valid_options++; | } |
| offset=(ulong)r.process_to_value(*voffset).as_double(); | if(valid_options!=options->count()) |
| } | throw Exception(PARSER_RUNTIME, 0, CALLED_WITH_INVALID_OPTION); |
| if(valid_options!=options->count()) | } |
| throw Exception(PARSER_RUNTIME, 0, CALLED_WITH_INVALID_OPTION); | |
| } else | |
| throw Exception(PARSER_RUNTIME, 0, OPTIONS_MUST_BE_HASH); | |
| } | |
| SQL_Driver::Placeholder* placeholders=0; | SQL_Driver::Placeholder* placeholders=0; |
| uint placeholders_count=0; | uint placeholders_count=0; |
| Line 1255 static void _select(Request& r, MethodPa | Line 1247 static void _select(Request& r, MethodPa |
| Value& vcondition=params.as_expression(0, "condition must be number, bool or expression"); | Value& vcondition=params.as_expression(0, "condition must be number, bool or expression"); |
| Table& source_table=GET_SELF(r, VTable).table(); | Table& source_table=GET_SELF(r, VTable).table(); |
| Table& result_table=*new Table(source_table.columns()); | |
| int limit=source_table.count(); | int limit=source_table.count(); |
| int offset = 0; | int offset=0; |
| bool reverse = false; | bool reverse=false; |
| if(params.count()>1) { | if(params.count()>1) |
| Value& voptions=params.as_no_junction(1, "options must be hash, not code"); | if(HashStringValue* options=params.as_hash(1)) { |
| if(voptions.is_defined() && !voptions.is_string()) | int valid_options=0; |
| if(HashStringValue* options=voptions.get_hash()) { | if(Value* vlimit=options->get(sql_limit_name)) { |
| int valid_options=0; | valid_options++; |
| if(Value* vlimit=options->get(sql_limit_name)) { | limit=r.process_to_value(*vlimit).as_int(); |
| valid_options++; | } |
| limit=r.process_to_value(*vlimit).as_int(); | if(Value* voffset=options->get(sql_offset_name)) { |
| } | valid_options++; |
| if(Value* voffset=options->get(sql_offset_name)) { | offset=r.process_to_value(*voffset).as_int(); |
| valid_options++; | } |
| offset=r.process_to_value(*voffset).as_int(); | if(Value* vreverse=options->get(table_reverse_name)) { |
| } | valid_options++; |
| if(Value* vreverse=options->get(table_reverse_name)) { | reverse=r.process_to_value(*vreverse).as_bool(); |
| valid_options++; | } |
| reverse=r.process_to_value(*vreverse).as_bool(); | if(valid_options!=options->count()) |
| } | |
| if(valid_options!=options->count()) | |
| throw Exception(PARSER_RUNTIME, | |
| 0, | |
| "called with invalid option"); | |
| } else | |
| throw Exception(PARSER_RUNTIME, | throw Exception(PARSER_RUNTIME, |
| 0, | 0, |
| "options must be hash"); | "called with invalid option"); |
| } | } |
| int saved_current=source_table.current(); | |
| int size=source_table.count(); | |
| int appended = 0; | |
| if(reverse){ | |
| for(int row=size-1; row >=0 && result_table.count() < limit; row--) { | |
| source_table.set_current(row); | |
| bool condition=r.process_to_value(vcondition, false/*don't intercept string*/).as_bool(); | Table& result_table=*new Table(source_table.columns()); |
| if(condition && ++appended > offset) // ...condition is true, adding to the result | if(size_t size=source_table.count() && limit>0){ |
| result_table+=source_table[row]; | size_t saved_current=source_table.current(); |
| } | size_t appended=0; |
| } else { | |
| for(int row=0; row < size && result_table.count() < limit; row++) { | if(reverse){ |
| source_table.set_current(row); | for(size_t row=size-1; result_table.count() < (size_t)limit; row--) { |
| source_table.set_current(row); | |
| bool condition=r.process_to_value(vcondition, false/*don't intercept string*/).as_bool(); | |
| if(condition && ++appended > (size_t)offset) // ...condition is true, adding to the result | |
| result_table+=source_table[row]; | |
| if(row==0) break; | |
| } | |
| } else { | |
| for(size_t row=0; row < size && result_table.count() < (size_t)limit; row++) { | |
| source_table.set_current(row); | |
| bool condition=r.process_to_value(vcondition, false/*don't intercept string*/).as_bool(); | bool condition=r.process_to_value(vcondition, false/*don't intercept string*/).as_bool(); |
| if(condition && ++appended > offset) // ...condition is true, adding to the result | if(condition && ++appended > (size_t)offset) // ...condition is true, adding to the result |
| result_table+=source_table[row]; | result_table+=source_table[row]; |
| } | |
| } | } |
| source_table.set_current(saved_current); | |
| } | } |
| source_table.set_current(saved_current); | |
| r.write_no_lang(*new VTable(&result_table)); | r.write_no_lang(*new VTable(&result_table)); |
| } | } |