|
|
| version 1.281, 2011/05/19 06:58:40 | version 1.286, 2012/03/16 09:24:08 |
|---|---|
| Line 1 | Line 1 |
| /** @file | /** @file |
| Parser: @b table parser class. | Parser: @b table parser class. |
| Copyright (c) 2001-2009 ArtLebedev Group (http://www.artlebedev.com) | Copyright (c) 2001-2012 Art. Lebedev Studio (http://www.artlebedev.com) |
| Author: Alexandr Petrosian <paf@design.ru> (http://paf.design.ru) | Author: Alexandr Petrosian <paf@design.ru> (http://paf.design.ru) |
| */ | */ |
| static const char * const IDENT_TABLE_C="$Date$"; | |
| #if (!defined(NO_STRINGSTREAM) && !defined(FREEBSD4)) | #if (!defined(NO_STRINGSTREAM) && !defined(FREEBSD4)) |
| #include <sstream> | #include <sstream> |
| #endif | #endif |
| Line 23 static const char * const IDENT_TABLE_C= | Line 21 static const char * const IDENT_TABLE_C= |
| #include "pa_vbool.h" | #include "pa_vbool.h" |
| #include "pa_array.h" | #include "pa_array.h" |
| volatile const char * IDENT_TABLE_C="$Id$"; | |
| // class | // class |
| class MTable: public Methoded { | class MTable: public Methoded { |
| Line 209 static void _create(Request& r, MethodPa | Line 209 static void _create(Request& r, MethodPa |
| data.split(head, raw_pos_after, "\n", String::L_AS_IS, 1); | data.split(head, raw_pos_after, "\n", String::L_AS_IS, 1); |
| if(head.count()) { | if(head.count()) { |
| size_t col_pos_after=0; | size_t col_pos_after=0; |
| head[0]->split(*columns, col_pos_after, *separators.scolumn, String::L_AS_IS); | if(head[0]->is_empty()) |
| *columns += new String(); | |
| else | |
| head[0]->split(*columns, col_pos_after, *separators.scolumn, String::L_AS_IS); | |
| } | } |
| } | } |
| Line 1249 static void _select(Request& r, MethodPa | Line 1252 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 1278 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(); | size_t size=source_table.count(); |
| int size=source_table.count(); | if(offset<0) |
| int appended = 0; | offset+=size; |
| if(size && limit>0 && offset>=0 && (size_t)offset<size){ | |
| if(reverse){ | size_t saved_current=source_table.current(); |
| for(int row=size-1; row >=0 && result_table.count() < limit; row--) { | size_t appended=0; |
| source_table.set_current(row); | |
| if(reverse){ | |
| bool condition=r.process_to_value(vcondition, false/*don't intercept string*/).as_bool(); | for(size_t row=size-1; result_table.count() < (size_t)limit; row--) { |
| source_table.set_current(row); | |
| if(condition && ++appended > offset) // ...condition is true, adding to the result | |
| result_table+=source_table[row]; | bool condition=r.process_to_value(vcondition, false/*don't intercept string*/).as_bool(); |
| } | |
| } else { | if(condition && ++appended > (size_t)offset) // ...condition is true, adding to the result |
| for(int row=0; row < size && result_table.count() < limit; row++) { | result_table+=source_table[row]; |
| source_table.set_current(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)); |
| } | } |