|
|
| version 1.281, 2011/05/19 06:58:40 | version 1.282, 2011/11/19 04:15:31 |
|---|---|
| Line 1249 static void _select(Request& r, MethodPa | Line 1249 static void _select(Request& r, MethodPa |
| Table& source_table=GET_SELF(r, VTable).table(); | Table& source_table=GET_SELF(r, VTable).table(); |
| 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) |
| if(HashStringValue* options=params.as_hash(1)) { | if(HashStringValue* options=params.as_hash(1)) { |
| Line 1275 static void _select(Request& r, MethodPa | Line 1275 static void _select(Request& r, MethodPa |
| Table& result_table=*new Table(source_table.columns()); | Table& result_table=*new Table(source_table.columns()); |
| int saved_current=source_table.current(); | if(size_t size=source_table.count() && limit>0){ |
| int size=source_table.count(); | size_t saved_current=source_table.current(); |
| int appended = 0; | size_t appended=0; |
| if(reverse){ | if(reverse){ |
| for(int row=size-1; row >=0 && result_table.count() < limit; row--) { | for(size_t row=size-1; result_table.count() < (size_t)limit; row--) { |
| source_table.set_current(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]; |
| } | if(row==0) break; |
| } else { | } |
| for(int row=0; row < size && result_table.count() < limit; row++) { | } else { |
| source_table.set_current(row); | 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)); |
| } | } |