Diff for /parser3/src/classes/table.C between versions 1.255 and 1.263

version 1.255, 2009/05/13 09:01:00 version 1.263, 2009/07/29 05:01:33
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 26  using namespace std; Line 26  using namespace std;
   
 class MTable: public Methoded {  class MTable: public Methoded {
 public: // VStateless_class  public: // VStateless_class
         Value* create_new_value(Pool&, HashStringValue&) { return new VTable(); }          Value* create_new_value(Pool&, HashStringValue*) { return new VTable(); }
   
 public:  public:
         MTable();          MTable();
Line 39  public: // Methoded Line 39  public: // Methoded
   
 DECLARE_CLASS_VAR(table, new MTable, 0);  DECLARE_CLASS_VAR(table, new MTable, 0);
   
 // externs  
   
 extern String cycle_data_name;  
   
 #define TABLE_REVERSE_NAME "reverse"  #define TABLE_REVERSE_NAME "reverse"
   
 // globals  // globals
Line 359  static void _load(Request& r, MethodPara Line 355  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, true/*tainted*/);                          *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 370  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, true/*tainted*/);                  *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 385  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 476  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 526  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 611  static void _offset(Request& r, MethodPa Line 607  static void _offset(Request& r, MethodPa
 }  }
   
 static void _menu(Request& r, MethodParams& params) {  static void _menu(Request& r, MethodParams& params) {
         Temp_hash_value<const String::Body, void*>           InCycle temp(r);
                 cycle_data_setter(r.classes_conf, cycle_data_name, /*any not null flag*/&r);  
   
         Value& body_code=params.as_junction(0, "body must be code");          Value& body_code=params.as_junction(0, "body must be code");
                   
Line 1047  public: Line 1042  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) {          bool add_column(SQL_Error& error, const char *str, size_t length) {
                 try {                  try {
                         columns+=new String(str, true/*tainted*/);                          columns+=new String(str, String::L_TAINTED, length);
                         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 1077  public: Line 1072  public:
         }          }
         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 length) {
                 try {                  try {
                         String& cell=*new String;                          *row+=new String(str, String::L_TAINTED, length);
                         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 1097  static void marshal_bind( Line 1089  static void marshal_bind(
 {  {
         SQL_Driver::Placeholder& ph=**pptr;          SQL_Driver::Placeholder& ph=**pptr;
         ph.name=aname.cstr();          ph.name=aname.cstr();
         ph.value=avalue->as_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.is_null=avalue->get_class()==void_class;
         ph.were_updated=false;          ph.were_updated=false;
   
Line 1122  void unmarshal_bind_updates(HashStringVa Line 1114  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, true/*tainted*/));  
                                 else  
                                         value=new VString(*new String());                                         
                         hash.put(ph->name, value);                          hash.put(ph->name, value);
                 }                  }
 }  }
Line 1170  static void _sql(Request& r, MethodParam Line 1159  static void _sql(Request& r, MethodParam
   
         Temp_lang temp_lang(r, String::L_SQL);          Temp_lang temp_lang(r, String::L_SQL);
         const String&  statement_string=r.process_to_string(statement);          const String&  statement_string=r.process_to_string(statement);
         const char* statement_cstr=          const char* statement_cstr=statement_string.untaint_cstr(r.flang, r.connection());
                 statement_string.cstr(String::L_UNSPECIFIED, r.connection());  
         Table_sql_event_handlers handlers;          Table_sql_event_handlers handlers;
 #ifdef RESOURCES_DEBUG  #ifdef RESOURCES_DEBUG
         struct timeval mt[2];          struct timeval mt[2];

Removed from v.1.255  
changed lines
  Added in v.1.263


E-mail: