|
|
| version 1.251, 2009/05/05 10:06:57 | version 1.257, 2009/05/15 13:54:29 |
|---|---|
| Line 7 | Line 7 |
| static const char * const IDENT_TABLE_C="$Date$"; | static const char * const IDENT_TABLE_C="$Date$"; |
| #ifndef NO_STRINGSTREAM | #if (!defined(NO_STRINGSTREAM) && !defined(FREEBSD4)) |
| #include <sstream> | #include <sstream> |
| using namespace std; | using namespace std; |
| #endif | #endif |
| Line 130 struct TableSeparators { | Line 130 struct TableSeparators { |
| char encloser; const String* sencloser; | char encloser; const String* sencloser; |
| TableSeparators(): | TableSeparators(): |
| column('\t'), scolumn(new String("\t", false)), | column('\t'), scolumn(new String("\t")), |
| encloser(0), sencloser(0) | encloser(0), sencloser(0) |
| {} | {} |
| int load( HashStringValue& options ) { | int load( HashStringValue& options ) { |
| 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 359 static void _load(Request& r, MethodPara | Line 359 static void _load(Request& r, MethodPara |
| 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) ) { |
| *columns+=new String(sr.piece, 0, true); | *columns+=new String(sr.piece, String::L_TAINTED); |
| if(sr.delim=='\n') | if(sr.delim=='\n') |
| break; | break; |
| } | } |
| Line 374 static void _load(Request& r, MethodPara | Line 374 static void _load(Request& r, MethodPara |
| while( lsplit_result sr=lsplit(&data, separators.column, '\n', separators.encloser) ) { | while( lsplit_result sr=lsplit(&data, separators.column, '\n', separators.encloser) ) { |
| if(!*sr.piece && !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, String::L_TAINTED); |
| if(sr.delim=='\n') { | if(sr.delim=='\n') { |
| table+=row; | table+=row; |
| row=new ArrayString(columns_count); | row=new ArrayString(columns_count); |
| Line 389 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 | #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) { | if(encloser) { |
| to<<*sencloser; | to<<encloser; |
| // while we have 'encloser'... | // while we have 'encloser'... |
| size_t pos_after=0; | size_t pos_after=0; |
| for( size_t pos_before; (pos_before=from.pos( encloser, pos_after ))!=STRING_NOT_FOUND; pos_after=pos_before) { | for( size_t pos_before; (pos_before=from.pos( encloser, pos_after ))!=STRING_NOT_FOUND; pos_after=pos_before) { |
| pos_before++; // including first encloser (and skipping it for next pos) | pos_before++; // including first encloser (and skipping it for next pos) |
| to<<from.mid(pos_after, pos_before); | to<<from.mid(pos_after, pos_before).cstr(); |
| to<<*sencloser; // doubling encloser | to<<encloser; // doubling encloser |
| } | } |
| // last piece | // last piece |
| size_t from_length=from.length(); | size_t from_length=from.length(); |
| if(pos_after<from_length) | if(pos_after<from_length) |
| to<<from.mid(pos_after, from_length); | to<<from.mid(pos_after, from_length).cstr(); |
| to<<*sencloser; | to<<encloser; |
| } else | } else |
| to<<from; | to<<from.cstr(); |
| } | } |
| #else | #else |
| void maybe_enclose( ostringstream& to, const String& from, char encloser ) { | void maybe_enclose( String& to, const String& from, char encloser, const String* sencloser ) { |
| if(encloser) { | if(encloser) { |
| to<<encloser; | to<<*sencloser; |
| // while we have 'encloser'... | // while we have 'encloser'... |
| size_t pos_after=0; | size_t pos_after=0; |
| for( size_t pos_before; (pos_before=from.pos( encloser, pos_after ))!=STRING_NOT_FOUND; pos_after=pos_before) { | for( size_t pos_before; (pos_before=from.pos( encloser, pos_after ))!=STRING_NOT_FOUND; pos_after=pos_before) { |
| pos_before++; // including first encloser (and skipping it for next pos) | pos_before++; // including first encloser (and skipping it for next pos) |
| to<<from.mid(pos_after, pos_before).cstr(); | to<<from.mid(pos_after, pos_before); |
| to<<encloser; // doubling encloser | to<<*sencloser; // doubling encloser |
| } | } |
| // last piece | // last piece |
| size_t from_length=from.length(); | size_t from_length=from.length(); |
| if(pos_after<from_length) | if(pos_after<from_length) |
| to<<from.mid(pos_after, from_length).cstr(); | to<<from.mid(pos_after, from_length); |
| to<<encloser; | to<<*sencloser; |
| } else | } else |
| to<<from.cstr(); | to<<from; |
| } | } |
| #endif | #endif // don't use stringstream |
| static void _save(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); |
| Line 480 static void _save(Request& r, MethodPara | Line 480 static void _save(Request& r, MethodPara |
| Table& table=GET_SELF(r, VTable).table(); | Table& table=GET_SELF(r, VTable).table(); |
| #ifdef NO_STRINGSTREAM | #if (!defined(NO_STRINGSTREAM) && !defined(FREEBSD4)) |
| String sdata; | |
| if(output_column_names) { | |
| if(table.columns()) { // named table | |
| for(Array_iterator<const String*> 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<lsize; column++) { | |
| char *cindex_tab=new(PointerFreeGC) char[MAX_NUMBER]; | |
| sdata.append_know_length(cindex_tab, | |
| snprintf(cindex_tab, MAX_NUMBER, | |
| column<lsize-1?"%d%c":"%d", column, separators.column), | |
| String::L_CLEAN); | |
| } | |
| else | |
| sdata.append_help_length("empty nameless table", 0, String::L_CLEAN); | |
| } | |
| sdata.append_know_length("\n", 1, String::L_CLEAN); | |
| } | |
| // data lines | |
| Array_iterator<ArrayString*> i(table); | |
| while(i.has_next()) { | |
| for(Array_iterator<const String*> 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 | |
| ostringstream ost(stringstream::out); | ostringstream ost(stringstream::out); |
| Line 575 static void _save(Request& r, MethodPara | Line 530 static void _save(Request& r, MethodPara |
| file_write(file_spec, data_cstr, data.length(), true /* as text */, do_append); | 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<const String*> 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<lsize; column++) { | |
| char *cindex_tab=new(PointerFreeGC) char[MAX_NUMBER]; | |
| sdata.append_know_length(cindex_tab, | |
| snprintf(cindex_tab, MAX_NUMBER, | |
| column<lsize-1?"%d%c":"%d", column, separators.column), | |
| String::L_CLEAN); | |
| } | |
| else | |
| sdata.append_help_length("empty nameless table", 0, String::L_CLEAN); | |
| } | |
| sdata.append_know_length("\n", 1, String::L_CLEAN); | |
| } | |
| // data lines | |
| Array_iterator<ArrayString*> i(table); | |
| while(i.has_next()) { | |
| for(Array_iterator<const String*> 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&) { | static void _count(Request& r, MethodParams&) { |
| Line 1047 public: | Line 1047 public: |
| columns(*new ArrayString), row(0), table(0) { | columns(*new ArrayString), row(0), table(0) { |
| } | } |
| bool add_column(SQL_Error& error, const char *str, size_t length) { | bool add_column(SQL_Error& error, const char *str, size_t) { |
| try { | try { |
| columns+=new String(str, length, true); | columns+=new String(str, String::L_TAINTED); |
| return false; | return false; |
| } catch(...) { | } catch(...) { |
| error=SQL_Error("exception occured in Table_sql_event_handlers::add_column"); | error=SQL_Error("exception occured in Table_sql_event_handlers::add_column"); |
| Line 1075 public: | Line 1075 public: |
| return true; | return true; |
| } | } |
| } | } |
| bool add_row_cell(SQL_Error& error, const char* str, size_t length) { | bool add_row_cell(SQL_Error& error, const char* str, size_t) { |
| try { | try { |
| String& cell=*new String; | *row+=new String(str, String::L_TAINTED); |
| if(length) | |
| cell.append_know_length(str, length, String::L_TAINTED); | |
| *row+=&cell; | |
| return false; | return false; |
| } catch(...) { | } catch(...) { |
| error=SQL_Error("exception occured in Table_sql_event_handlers::add_row_cell"); | error=SQL_Error("exception occured in Table_sql_event_handlers::add_row_cell"); |
| Line 1122 void unmarshal_bind_updates(HashStringVa | Line 1119 void unmarshal_bind_updates(HashStringVa |
| if(ph->is_null) | if(ph->is_null) |
| value=VVoid::get(); | value=VVoid::get(); |
| else | else |
| if(ph->value) | value=new VString(*new String(ph->value, String::L_TAINTED)); |
| value=new VString(*new String(ph->value, 0, true/*tainted*/)); | |
| else | |
| value=new VString(*new String()); | |
| hash.put(ph->name, value); | hash.put(ph->name, value); |
| } | } |
| } | } |