--- parser3/src/classes/table.C 2009/05/14 08:10:09 1.256 +++ parser3/src/classes/table.C 2009/08/31 08:28:53 1.265 @@ -5,9 +5,9 @@ Author: Alexandr Petrosian (http://paf.design.ru) */ -static const char * const IDENT_TABLE_C="$Date: 2009/05/14 08:10:09 $"; +static const char * const IDENT_TABLE_C="$Date: 2009/08/31 08:28:53 $"; -#ifndef NO_STRINGSTREAM +#if (!defined(NO_STRINGSTREAM) && !defined(FREEBSD4)) #include using namespace std; #endif @@ -17,6 +17,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" @@ -26,7 +27,7 @@ using namespace std; class MTable: public Methoded { public: // VStateless_class - Value* create_new_value(Pool&, HashStringValue&) { return new VTable(); } + Value* create_new_value(Pool&) { return new VTable(); } public: MTable(); @@ -39,10 +40,6 @@ public: // Methoded DECLARE_CLASS_VAR(table, new MTable, 0); -// externs - -extern String cycle_data_name; - #define TABLE_REVERSE_NAME "reverse" // globals @@ -389,51 +386,51 @@ static void _load(Request& r, MethodPara GET_SELF(r, VTable).set_table(table); } -#ifdef NO_STRINGSTREAM +#if (!defined(NO_STRINGSTREAM) && !defined(FREEBSD4)) -void maybe_enclose( String& to, const String& from, char encloser, const String* sencloser ) { +void maybe_enclose( ostringstream& to, const String& from, char encloser ) { if(encloser) { - to<<*sencloser; + to< i(*table.columns()); i.has_next(); ) { - maybe_enclose( sdata, *i.next(), separators.encloser, separators.sencloser ); - if(i.has_next()) - sdata<<*separators.scolumn; - } - } else { // nameless table [we were asked to output column names] - if(int lsize=table.count()?table[0]->count():0) - for(int column=0; column i(table); - while(i.has_next()) { - for(Array_iterator c(*i.next()); c.has_next(); ) { - maybe_enclose( sdata, *c.next(), separators.encloser, separators.sencloser ); - if(c.has_next()) - sdata<<*separators.scolumn; - } - sdata.append_know_length("\n", 1, String::L_CLEAN); - } - - // write - { - const char* data_cstr=sdata.cstr(); - file_write(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 - } - -#else +#if (!defined(NO_STRINGSTREAM) && !defined(FREEBSD4)) ostringstream ost(stringstream::out); @@ -575,7 +527,52 @@ static void _save(Request& r, MethodPara file_write(file_spec, data_cstr, data.length(), true /* as text */, do_append); } -#endif +#else + + String sdata; + if(output_column_names) { + if(table.columns()) { // named table + for(Array_iterator i(*table.columns()); i.has_next(); ) { + maybe_enclose( sdata, *i.next(), separators.encloser, separators.sencloser ); + if(i.has_next()) + sdata<<*separators.scolumn; + } + } else { // nameless table [we were asked to output column names] + if(int lsize=table.count()?table[0]->count():0) + for(int column=0; column i(table); + while(i.has_next()) { + for(Array_iterator c(*i.next()); c.has_next(); ) { + maybe_enclose( sdata, *c.next(), separators.encloser, separators.sencloser ); + if(c.has_next()) + sdata<<*separators.scolumn; + } + sdata.append_know_length("\n", 1, String::L_CLEAN); + } + + // write + { + const char* data_cstr=sdata.cstr(); + file_write(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 + } + +#endif // don't use stringstream } static void _count(Request& r, MethodParams&) { @@ -611,8 +608,7 @@ static void _offset(Request& r, MethodPa } static void _menu(Request& r, MethodParams& params) { - Temp_hash_value - cycle_data_setter(r.classes_conf, cycle_data_name, /*any not null flag*/&r); + InCycle temp(r); Value& body_code=params.as_junction(0, "body must be code"); @@ -916,7 +912,15 @@ static void _sort(Request& r, MethodPara else seq[i].value.d=value.as_double(); } - // sort keys + + // @todo: handle this elsewhere + if(r.charsets.source().NAME()=="KOI8-R" && key_values_are_strings) { + for(i=0; ias_string().cstr(String::L_UNSPECIFIED); + ph.value=avalue->as_string().untaint_cstr(String::L_AS_IS); ph.is_null=avalue->get_class()==void_class; ph.were_updated=false; @@ -1164,8 +1168,8 @@ static void _sql(Request& r, MethodParam Temp_lang temp_lang(r, String::L_SQL); const String& statement_string=r.process_to_string(statement); - const char* statement_cstr= - statement_string.cstr(String::L_UNSPECIFIED, r.connection()); + const char* statement_cstr=statement_string.untaint_cstr(r.flang, r.connection()); + Table_sql_event_handlers handlers; #ifdef RESOURCES_DEBUG struct timeval mt[2];