--- parser3/src/classes/table.C 2009/08/08 13:30:20 1.264 +++ parser3/src/classes/table.C 2010/05/16 22:12:50 1.271 @@ -5,11 +5,10 @@ Author: Alexandr Petrosian (http://paf.design.ru) */ -static const char * const IDENT_TABLE_C="$Date: 2009/08/08 13:30:20 $"; +static const char * const IDENT_TABLE_C="$Date: 2010/05/16 22:12:50 $"; #if (!defined(NO_STRINGSTREAM) && !defined(FREEBSD4)) #include -using namespace std; #endif #include "classes.h" @@ -17,6 +16,7 @@ using namespace std; #include "pa_common.h" #include "pa_request.h" +#include "pa_charsets.h" #include "pa_vtable.h" #include "pa_vint.h" #include "pa_sql_connection.h" @@ -54,12 +54,12 @@ String table_reverse_name(TABLE_REVERSE_ // methods static Table::Action_options get_action_options(Request& r, MethodParams& params, - const Table& source) { + size_t options_index, const Table& source) { Table::Action_options result; - if(!params.count()) + if(params.count() <= options_index) return result; - Value& maybe_options=params.last(); + Value& maybe_options=params[options_index]; /* can not do it: want to enable ^table::create[$source; # $.option[] @@ -156,7 +156,7 @@ struct TableSeparators { static void _create(Request& r, MethodParams& params) { // clone/copy part? if(Table *source=params[0].get_table()) { - Table::Action_options o=get_action_options(r, params, *source); + Table::Action_options o=get_action_options(r, params, 1, *source); check_option_param(o.defined, params, 1, "too many parameters"); GET_SELF(r, VTable).set_table(*new Table(*source, o)); @@ -387,7 +387,12 @@ static void _load(Request& r, MethodPara #if (!defined(NO_STRINGSTREAM) && !defined(FREEBSD4)) -void maybe_enclose( ostringstream& to, const String& from, char encloser ) { +#include "gc_allocator.h" + +typedef std::basic_stringstream, gc_allocator > pa_stringstream; +typedef std::basic_string, gc_allocator > pa_string; + +void maybe_enclose( pa_stringstream& to, const String& from, char encloser ) { if(encloser) { to<count()) throw Exception(PARSER_RUNTIME, 0, - "invalid option passed"); + INVALID_OPTION_PASSED); } else { throw Exception(PARSER_RUNTIME, 0, @@ -478,7 +483,7 @@ static void _save(Request& r, MethodPara #if (!defined(NO_STRINGSTREAM) && !defined(FREEBSD4)) - ostringstream ost(stringstream::out); + pa_stringstream ost(std::stringstream::out); // process header if(output_column_names) { @@ -520,10 +525,10 @@ static void _save(Request& r, MethodPara // write { - string data=ost.str(); + pa_string data=ost.str(); const char* data_cstr=data.c_str(); - file_write(file_spec, data_cstr, data.length(), true /* as text */, do_append); + file_write(r.charsets, file_spec, data_cstr, data.length(), true /* as text */, do_append); } #else @@ -565,8 +570,7 @@ static void _save(Request& r, MethodPara // write { const char* data_cstr=sdata.cstr(); - file_write(file_spec, - data_cstr, sdata.length(), true, do_append); + file_write(r.charsets, file_spec, data_cstr, sdata.length(), true, do_append); if(*data_cstr) // not empty (when empty it's not heap memory) pa_free((void*)data_cstr); // not needed anymore } @@ -681,7 +685,8 @@ static void table_row_to_hash(Table::ele bool exist=false; switch(info->value_type) { case C_STRING: { - exist=info->hash->put_dont_replace(*key, new VString(*row->get(info->value_fields->get(0)))); + size_t index=info->value_fields->get(0); + exist=info->hash->put_dont_replace(*key, (index < row->count()) ? new VString(*row->get(index)) : new VString()); break; } case C_HASH: { @@ -911,6 +916,14 @@ static void _sort(Request& r, MethodPara else seq[i].value.d=value.as_double(); } + + // @todo: handle this elsewhere + if(r.charsets.source().NAME()=="KOI8-R" && key_values_are_strings) { + for(i=0; icount()) + if(size_t old_cols=old_table.columns()?old_table.columns()->count():old_table[0]->count()) for(size_t column=0; column