|
|
| version 1.239, 2008/02/14 09:10:24 | version 1.243, 2008/05/27 19:01:46 |
|---|---|
| Line 7 | Line 7 |
| static const char * const IDENT_TABLE_C="$Date$"; | static const char * const IDENT_TABLE_C="$Date$"; |
| #ifndef NO_STRINGSTREAM | |
| #include <sstream> | #include <sstream> |
| using namespace std; | using namespace std; |
| #endif | |
| #include "classes.h" | #include "classes.h" |
| #include "pa_vmethod_frame.h" | #include "pa_vmethod_frame.h" |
| Line 387 static void _load(Request& r, MethodPara | Line 389 static void _load(Request& r, MethodPara |
| GET_SELF(r, VTable).set_table(table); | GET_SELF(r, VTable).set_table(table); |
| } | } |
| #ifdef NO_STRINGSTREAM | |
| void maybe_enclose( String& to, const String& from, char encloser, const String* sencloser ) { | void maybe_enclose( String& to, const String& from, char encloser, const String* sencloser ) { |
| if(encloser) { | if(encloser) { |
| to<<*sencloser; | to<<*sencloser; |
| Line 407 void maybe_enclose( String& to, const St | Line 411 void maybe_enclose( String& to, const St |
| to<<from; | to<<from; |
| } | } |
| #else | |
| void maybe_enclose( ostringstream& to, const String& from, char encloser ) { | void maybe_enclose( ostringstream& to, const String& from, char encloser ) { |
| if(encloser) { | if(encloser) { |
| to<<encloser; | to<<encloser; |
| Line 427 void maybe_enclose( ostringstream& to, c | Line 433 void maybe_enclose( ostringstream& to, c |
| to<<from.cstr(); | to<<from.cstr(); |
| } | } |
| /* | #endif |
| static void _save_old(Request& r, MethodParams& params) { | |
| static void _save(Request& r, MethodParams& params) { | |
| const String& first_arg=params.as_string(0, FIRST_ARG_MUST_NOT_BE_CODE); | const String& first_arg=params.as_string(0, FIRST_ARG_MUST_NOT_BE_CODE); |
| size_t param_index=1; | size_t param_index=1; |
| Line 469 static void _save_old(Request& r, Method | Line 476 static void _save_old(Request& r, Method |
| Table& table=GET_SELF(r, VTable).table(); | Table& table=GET_SELF(r, VTable).table(); |
| #ifdef NO_STRINGSTREAM | |
| String sdata; | String sdata; |
| if(output_column_names) { | if(output_column_names) { |
| if(table.columns()) { // named table | if(table.columns()) { // named table |
| Line 511 static void _save_old(Request& r, Method | Line 520 static void _save_old(Request& r, Method |
| 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 |
| } | } |
| } | |
| */ | |
| static void _save(Request& r, MethodParams& params) { | |
| const String& first_arg=params.as_string(0, FIRST_ARG_MUST_NOT_BE_CODE); | |
| size_t param_index=1; | |
| bool do_append=false; | |
| bool output_column_names=true; | |
| // mode? | |
| if(first_arg=="append") | |
| do_append=true; | |
| else if(first_arg=="nameless") | |
| output_column_names=false; | |
| else | |
| --param_index; | |
| const String& file_name=params.as_string(param_index++, FILE_NAME_MUST_NOT_BE_CODE); | |
| TableSeparators separators; | |
| if(param_index<params.count()) { | |
| Value& voptions=params.as_no_junction(param_index++, "additional params must be hash"); | |
| if( voptions.is_defined() && !voptions.is_string() ) { | |
| if(HashStringValue* options=voptions.get_hash()) { | |
| int valid_options=separators.load(*options); | |
| if(valid_options!=options->count()) | |
| throw Exception(PARSER_RUNTIME, | |
| 0, | |
| "invalid option passed"); | |
| } else { | |
| throw Exception(PARSER_RUNTIME, | |
| 0, | |
| "additional params must be hash (did you spell mode parameter correctly?)"); | |
| } | |
| } | |
| } | |
| if(param_index<params.count()) | |
| throw Exception(PARSER_RUNTIME, | |
| 0, | |
| "bad mode (must be nameless or append)"); | |
| Table& table=GET_SELF(r, VTable).table(); | #else |
| ostringstream ost(stringstream::out); | ostringstream ost(stringstream::out); |
| Line 602 static void _save(Request& r, MethodPara | Line 570 static void _save(Request& r, MethodPara |
| file_write(r.absolute(file_name), data_cstr, data.length(), true /* as text */, do_append); | file_write(r.absolute(file_name), data_cstr, data.length(), true /* as text */, do_append); |
| } | } |
| #endif | |
| } | } |
| static void _count(Request& r, MethodParams&) { | static void _count(Request& r, MethodParams&) { |
| Line 653 static void _menu(Request& r, MethodPara | Line 623 static void _menu(Request& r, MethodPara |
| StringOrValue sv_processed=r.process(body_code); | StringOrValue sv_processed=r.process(body_code); |
| Request::Skip lskip=r.get_skip(); r.set_skip(Request::SKIP_NOTHING); | Request::Skip lskip=r.get_skip(); r.set_skip(Request::SKIP_NOTHING); |
| const String* s_processed=sv_processed.get_string(); | const String* s_processed=sv_processed.get_string(); |
| if(delim_maybe_code && s_processed && s_processed->length()) { // delimiter set and we have body | if(delim_maybe_code && s_processed && s_processed->length()) { // delimiter set and we have body |
| if(need_delim) // need delim & iteration produced string? | if(need_delim) // need delim & iteration produced string? |
| r.write_pass_lang(r.process(*delim_maybe_code)); | r.write_pass_lang(r.process(*delim_maybe_code)); |
| need_delim=true; | 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) |
| Line 693 static void table_row_to_hash(Table::ele | Line 666 static void table_row_to_hash(Table::ele |
| if(!key) | if(!key) |
| return; // ignore rows without key [too-short-record_array if-indexed] | return; // ignore rows without key [too-short-record_array if-indexed] |
| bool exist = false; | bool exist=false; |
| switch (info->value_type) { | switch(info->value_type) { |
| case C_STRING: | case C_STRING: { |
| { | |
| exist=info->hash->put_dont_replace(*key, new VString(*row->get(info->value_fields->get(0)))); | exist=info->hash->put_dont_replace(*key, new VString(*row->get(info->value_fields->get(0)))); |
| break; | |
| } | } |
| break; | case C_HASH: { |
| case C_HASH: | |
| { | |
| VHash* vhash=new VHash; | VHash* vhash=new VHash; |
| HashStringValue& hash=vhash->hash(); | HashStringValue& hash=vhash->hash(); |
| for(Array_iterator<int> i(*info->value_fields); i.has_next(); ) { | for(Array_iterator<int> i(*info->value_fields); i.has_next(); ) { |
| Line 713 static void table_row_to_hash(Table::ele | Line 684 static void table_row_to_hash(Table::ele |
| } | } |
| exist=info->hash->put_dont_replace(*key, vhash); | exist=info->hash->put_dont_replace(*key, vhash); |
| break; | |
| } | } |
| break; | case C_TABLE: { |
| case C_TABLE: | VTable* vtable=(VTable*)info->hash->get(*key); // table exist? |
| { | |
| VTable* vtable=(VTable*)info->hash->get(*key); // put. table existed? | |
| if( info->distinct==D_ILLEGAL ){ | |
| exist=true; | |
| break; | |
| } | |
| Table* table; | Table* table; |
| if(vtable) { | if(vtable) { |
| if(info->distinct==D_ILLEGAL) { | |
| exist=true; | |
| break; | |
| } | |
| table=vtable->get_table(); | table=vtable->get_table(); |
| } else { | } else { |
| // no? creating table of same structure as source | // no? creating table of same structure as source |
| Line 733 static void table_row_to_hash(Table::ele | Line 702 static void table_row_to_hash(Table::ele |
| info->hash->put(*key, new VTable(table)); | info->hash->put(*key, new VTable(table)); |
| } | } |
| *table+=row; | *table+=row; |
| break; | |
| } | } |
| break; | |
| } | } |
| if(exist && info->distinct==D_ILLEGAL) | if(exist && info->distinct==D_ILLEGAL) |
| throw Exception(PARSER_RUNTIME, | throw Exception(PARSER_RUNTIME, |