|
|
| version 1.243, 2008/05/27 19:01:46 | version 1.252, 2009/05/05 10:20:59 |
|---|---|
| Line 1 | Line 1 |
| /** @file | /** @file |
| Parser: @b table parser class. | Parser: @b table parser class. |
| Copyright (c) 2001-2005 ArtLebedev Group (http://www.artlebedev.com) | Copyright (c) 2001-2009 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 230 static void _create(Request& r, MethodPa | Line 230 static void _create(Request& r, MethodPa |
| Array_iterator<const String*> i(rows); | Array_iterator<const String*> i(rows); |
| while(i.has_next()) { | while(i.has_next()) { |
| Table::element_type row(new ArrayString); | Table::element_type row(new ArrayString); |
| const String& string=*i.next(); | const String& string=*i.next(); |
| // remove comment lines | // remove comment lines |
| if(!string.length()) | if(string.is_empty()) |
| continue; | continue; |
| size_t col_pos_after=0; | size_t col_pos_after=0; |
| Line 344 static void _load(Request& r, MethodPara | Line 344 static void _load(Request& r, MethodPara |
| } | } |
| // loading text | // loading text |
| char *data=file_read_text(r.charsets, | char *data=file_load_text(r, |
| r.absolute(params.as_string(filename_param_index, FILE_NAME_MUST_BE_STRING)), | r.absolute(params.as_string(filename_param_index, FILE_NAME_MUST_BE_STRING)), |
| true, | true, |
| options | options |
| Line 451 static void _save(Request& r, MethodPara | Line 451 static void _save(Request& r, MethodPara |
| --param_index; | --param_index; |
| const String& file_name=params.as_string(param_index++, FILE_NAME_MUST_NOT_BE_CODE); | const String& file_name=params.as_string(param_index++, FILE_NAME_MUST_NOT_BE_CODE); |
| String file_spec=r.absolute(file_name); | |
| if(do_append && file_exist(file_spec)) | |
| output_column_names=false; | |
| TableSeparators separators; | TableSeparators separators; |
| if(param_index<params.count()) { | if(param_index<params.count()) { |
| Line 515 static void _save(Request& r, MethodPara | Line 519 static void _save(Request& r, MethodPara |
| // write | // write |
| { | { |
| const char* data_cstr=sdata.cstr(); | const char* data_cstr=sdata.cstr(); |
| file_write(r.absolute(file_name), | file_write(file_spec, |
| data_cstr, sdata.length(), true, do_append); | data_cstr, sdata.length(), true, do_append); |
| if(*data_cstr) // not empty (when empty it's not heap memory) | if(*data_cstr) // not empty (when empty it's not heap memory) |
| pa_free((void*)data_cstr); // not needed anymore | pa_free((void*)data_cstr); // not needed anymore |
| Line 566 static void _save(Request& r, MethodPara | Line 570 static void _save(Request& r, MethodPara |
| // write | // write |
| { | { |
| string data=ost.str(); | string data=ost.str(); |
| const char* data_cstr = data.c_str(); | const char* data_cstr=data.c_str(); |
| file_write(r.absolute(file_name), data_cstr, data.length(), true /* as text */, do_append); | file_write(file_spec, data_cstr, data.length(), true /* as text */, do_append); |
| } | } |
| #endif | #endif |
| Line 615 static void _menu(Request& r, MethodPara | Line 619 static void _menu(Request& r, MethodPara |
| Value* delim_maybe_code=params.count()>1?¶ms[1]:0; | Value* delim_maybe_code=params.count()>1?¶ms[1]:0; |
| Table& table=GET_SELF(r, VTable).table(); | Table& table=GET_SELF(r, VTable).table(); |
| bool need_delim=false; | |
| int saved_current=table.current(); | int saved_current=table.current(); |
| int size=table.count(); | int size=table.count(); |
| for(int row=0; row<size; row++) { | |
| table.set_current(row); | |
| StringOrValue sv_processed=r.process(body_code); | if(delim_maybe_code) { // delimiter set |
| Request::Skip lskip=r.get_skip(); r.set_skip(Request::SKIP_NOTHING); | bool need_delim=false; |
| for(int row=0; row<size; row++) { | |
| const String* s_processed=sv_processed.get_string(); | table.set_current(row); |
| if(delim_maybe_code && s_processed && s_processed->length()) { // delimiter set and we have body | |
| if(need_delim) // need delim & iteration produced string? | StringOrValue sv_processed=r.process(body_code); |
| r.write_pass_lang(r.process(*delim_maybe_code)); | Request::Skip lskip=r.get_skip(); r.set_skip(Request::SKIP_NOTHING); |
| else | |
| need_delim=true; | const String* s_processed=sv_processed.get_string(); |
| } | if(s_processed && !s_processed->is_empty()) { // we have body |
| if(need_delim) // need delim & iteration produced string? | |
| r.write_pass_lang(r.process(*delim_maybe_code)); | |
| else | |
| need_delim=true; | |
| } | |
| r.write_pass_lang(sv_processed); | r.write_pass_lang(sv_processed); |
| if(lskip==Request::SKIP_BREAK) | if(lskip==Request::SKIP_BREAK) |
| break; | break; |
| } | |
| } else { | |
| for(int row=0; row<size; row++) { | |
| table.set_current(row); | |
| r.process_write(body_code); | |
| Request::Skip lskip=r.get_skip(); r.set_skip(Request::SKIP_NOTHING); | |
| if(lskip==Request::SKIP_BREAK) | |
| break; | |
| } | |
| } | } |
| table.set_current(saved_current); | table.set_current(saved_current); |
| } | } |
| Line 947 static void _locate(Request& r, MethodPa | Line 964 static void _locate(Request& r, MethodPa |
| bool result=params[0].get_junction()? | bool result=params[0].get_junction()? |
| _locate_expression(table, o, r, params) : | _locate_expression(table, o, r, params) : |
| _locate_name_value(table, o, r, params); | _locate_name_value(table, o, r, params); |
| r.write_no_lang(*new VBool(result)); | r.write_no_lang(VBool::get(result)); |
| } | } |
| Line 1103 void unmarshal_bind_updates(HashStringVa | Line 1120 void unmarshal_bind_updates(HashStringVa |
| if(ph->were_updated) { | if(ph->were_updated) { |
| Value* value; | Value* value; |
| if(ph->is_null) | if(ph->is_null) |
| value=new VVoid(); | value=VVoid::get(); |
| else | else |
| if(ph->value) | if(ph->value) |
| value=new VString(*new String(ph->value, 0, true/*tainted*/)); | value=new VString(*new String(ph->value, 0, true/*tainted*/)); |
| Line 1117 static void _sql(Request& r, MethodParam | Line 1134 static void _sql(Request& r, MethodParam |
| Value& statement=params.as_junction(0, "statement must be code"); | Value& statement=params.as_junction(0, "statement must be code"); |
| HashStringValue* bind=0; | HashStringValue* bind=0; |
| ulong limit=0; | 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"); | Value& voptions=params.as_no_junction(1, "options must be hash, not code"); |