|
|
| version 1.192, 2003/11/20 16:34:23 | version 1.201, 2004/04/01 15:08:48 |
|---|---|
| Line 1 | Line 1 |
| /** @file | /** @file |
| Parser: @b table parser class. | Parser: @b table parser class. |
| Copyright (c) 2001-2003 ArtLebedev Group (http://www.artlebedev.com) | Copyright (c) 2001-2004 ArtLebedev Group (http://www.artlebedev.com) |
| Author: Alexandr Petrosian <paf@design.ru> (http://paf.design.ru) | Author: Alexandr Petrosian <paf@design.ru> (http://paf.design.ru) |
| */ | */ |
| Line 178 static void _create(Request& r, MethodPa | Line 178 static void _create(Request& r, MethodPa |
| GET_SELF(r, VTable).set_table(table); | GET_SELF(r, VTable).set_table(table); |
| } | } |
| static char* remove_encloser(char* cstr, char encloser) { | |
| if(cstr[0]!=encloser) | |
| return cstr; | |
| size_t length=strlen(cstr); | |
| if(length<2 || cstr[length-1]!=encloser) | |
| return cstr; | |
| // 'string' | |
| cstr[length-1]=0; | |
| cstr++; | |
| // double-encloser stands for encloser | |
| char *read; | |
| char *write; | |
| write=read=cstr; | |
| while(char c=*read++) { | |
| if(c==encloser && *read==encloser) | |
| read++; | |
| *write++=c; | |
| } | |
| *write=0; // terminate | |
| return cstr; | |
| } | |
| struct lsplit_result { | struct lsplit_result { |
| char* piece; | char* piece; |
| char delim; | char delim; |
| Line 249 static lsplit_result lsplit(char** strin | Line 221 static lsplit_result lsplit(char** strin |
| char *write; | char *write; |
| write=read=string; | write=read=string; |
| char c; | char c; |
| while(c=*read++) { | while((c=*read++)) { |
| if(c==encloser) { | if(c==encloser) { |
| char n=*read; | char n=*read; |
| if(n==encloser) // double-encloser stands for encloser | if(n==encloser) // double-encloser stands for encloser |
| Line 279 static void skip_empty_and_comment_lines | Line 251 static void skip_empty_and_comment_lines |
| while( char c=*data ) { | while( char c=*data ) { |
| if( c== '\n' || c == '#' ) { | if( c== '\n' || c == '#' ) { |
| /*nowhere=*/getrow(&data); // remove empty&comment lines | /*nowhere=*/getrow(&data); // remove empty&comment lines |
| *data_ref=data; | if(!(*data_ref=data)) |
| break; | |
| continue; | continue; |
| } | } |
| break; | break; |
| Line 363 static void _load(Request& r, MethodPara | Line 336 static void _load(Request& r, MethodPara |
| Table::element_type row(new ArrayString); | Table::element_type row(new ArrayString); |
| skip_empty_and_comment_lines(&data); | skip_empty_and_comment_lines(&data); |
| while( lsplit_result sr=lsplit(&data, separators.column, '\n', separators.encloser) ) { | while( lsplit_result sr=lsplit(&data, separators.column, '\n', separators.encloser) ) { |
| if(!sr.delim && !row->count()) // append last empty column [if without \n] | if(!*sr.piece && !sr.delim && !row->count()) // append last empty column [if without \n] |
| break; | break; |
| *row+=new String(sr.piece, 0, true); | *row+=new String(sr.piece, 0, true); |
| if(sr.delim=='\n') { | if(sr.delim=='\n') { |
| Line 657 static void _hash(Request& r, MethodPara | Line 630 static void _hash(Request& r, MethodPara |
| } else | } else |
| throw Exception("parser.runtime", | throw Exception("parser.runtime", |
| 0, | 0, |
| "value field(s) must be string or self_table" | "value field(s) must be string or table" |
| ); | ); |
| } else { // by all columns, including key | } else { // by all columns, including key |
| if(!(distinct!=D_ILLEGAL && distinct!=D_FIRST)) | if(!(distinct!=D_ILLEGAL && distinct!=D_FIRST)) |
| Line 667 static void _hash(Request& r, MethodPara | Line 640 static void _hash(Request& r, MethodPara |
| { | { |
| Row_info info={0}; | |
| info.r=&r; | |
| info.table=&self_table; | |
| Value* key_param=¶ms[0]; | Value* key_param=¶ms[0]; |
| info.key_code=key_param->get_junction()?key_param:0; | Row_info info={ |
| info.key_field=info.key_code?-1 | &r, |
| :self_table.column_name2index(key_param->as_string(), true); | &self_table, |
| info.value_fields=&value_fields; | /*key_code=*/key_param->get_junction()?key_param:0, |
| info.hash=&result.hash(); | /*key_field=*/0/*filled below*/, |
| info.distinct=distinct; | &value_fields, |
| info.row=0; | &result.hash(), |
| distinct, | |
| /*row=*/0 | |
| }; | |
| info.key_field=(info.key_code?-1 | |
| :self_table.column_name2index(key_param->as_string(), true)); | |
| int saved_current=self_table.current(); | int saved_current=self_table.current(); |
| self_table.for_each(table_row_to_hash, &info); | self_table.for_each(table_row_to_hash, &info); |
| Line 854 static void _join(Request& r, MethodPara | Line 829 static void _join(Request& r, MethodPara |
| 0, | 0, |
| "source and destination are same table"); | "source and destination are same table"); |
| if(Table::columns_type dest_columns=dest.columns()) // dest is named | if(dest.columns()) // dest is named |
| src.table_for_each(join_named_row, &dest, o); | src.table_for_each(join_named_row, &dest, o); |
| else // dest is nameless | else // dest is nameless |
| src.table_for_each(join_nameless_row, &dest, o); | src.table_for_each(join_nameless_row, &dest, o); |
| Line 1004 static void _select(Request& r, MethodPa | Line 979 static void _select(Request& r, MethodPa |
| source_table.set_current(row); | source_table.set_current(row); |
| bool condition=r.process_to_value(vcondition, | bool condition=r.process_to_value(vcondition, |
| /*0/*no name* /,*/ | |
| false/*don't intercept string*/).as_bool(); | false/*don't intercept string*/).as_bool(); |
| if(condition) // ...condition is true= | if(condition) // ...condition is true= |