Diff for /parser3/src/classes/table.C between versions 1.243 and 1.253

version 1.243, 2008/05/27 19:01:46 version 1.253, 2009/05/13 07:36:05
Line 1 Line 1
 /** @file  /** @file
         Parser: @b table parser class.          Parser: @b table parser class.
   
         Copyright (c) 2001-2005 ArtLebedev Group (http://www.artlebedev.com)          Copyright (c) 2001-2009 ArtLebedev Group (http://www.artlebedev.com)
         Author: Alexandr Petrosian <paf@design.ru> (http://paf.design.ru)          Author: Alexandr Petrosian <paf@design.ru> (http://paf.design.ru)
 */  */
   
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 344  static void _load(Request& r, MethodPara Line 344  static void _load(Request& r, MethodPara
         }          }
   
         // loading text          // loading text
         char *data=file_read_text(r.charsets,          char *data=file_load_text(r,
                 r.absolute(params.as_string(filename_param_index, FILE_NAME_MUST_BE_STRING)),                  r.absolute(params.as_string(filename_param_index, FILE_NAME_MUST_BE_STRING)),
                 true,                  true,
                 options                  options
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, true);
                         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, true);
                 if(sr.delim=='\n') {                  if(sr.delim=='\n') {
                         table+=row;                          table+=row;
                         row=new ArrayString(columns_count);                          row=new ArrayString(columns_count);
Line 451  static void _save(Request& r, MethodPara Line 451  static void _save(Request& r, MethodPara
                 --param_index;                  --param_index;
   
         const String& file_name=params.as_string(param_index++, FILE_NAME_MUST_NOT_BE_CODE);          const String& file_name=params.as_string(param_index++, FILE_NAME_MUST_NOT_BE_CODE);
           String file_spec=r.absolute(file_name);
   
           if(do_append && file_exist(file_spec))
                   output_column_names=false;
   
         TableSeparators separators;          TableSeparators separators;
         if(param_index<params.count()) {          if(param_index<params.count()) {
Line 515  static void _save(Request& r, MethodPara Line 519  static void _save(Request& r, MethodPara
         // write          // write
         {          {
                 const char* data_cstr=sdata.cstr();                  const char* data_cstr=sdata.cstr();
                 file_write(r.absolute(file_name),                   file_write(file_spec, 
                         data_cstr, sdata.length(), true, do_append);                          data_cstr, sdata.length(), true, do_append);
                 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
Line 566  static void _save(Request& r, MethodPara Line 570  static void _save(Request& r, MethodPara
         // write          // write
         {          {
                 string data=ost.str();                  string data=ost.str();
                 const char* data_cstr = data.c_str();                  const char* data_cstr=data.c_str();
   
                 file_write(r.absolute(file_name), data_cstr, data.length(), true /* as text */, do_append);                  file_write(file_spec, data_cstr, data.length(), true /* as text */, do_append);
         }          }
   
 #endif  #endif
Line 615  static void _menu(Request& r, MethodPara Line 619  static void _menu(Request& r, MethodPara
         Value* delim_maybe_code=params.count()>1?&params[1]:0;          Value* delim_maybe_code=params.count()>1?&params[1]:0;
   
         Table& table=GET_SELF(r, VTable).table();          Table& table=GET_SELF(r, VTable).table();
         bool need_delim=false;  
         int saved_current=table.current();          int saved_current=table.current();
         int size=table.count();          int size=table.count();
         for(int row=0; row<size; row++) {  
                 table.set_current(row);  
   
                 StringOrValue sv_processed=r.process(body_code);          if(delim_maybe_code) { // delimiter set
                 Request::Skip lskip=r.get_skip(); r.set_skip(Request::SKIP_NOTHING);                  bool need_delim=false;
                   for(int row=0; row<size; row++) {
                 const String* s_processed=sv_processed.get_string();                          table.set_current(row);
                 if(delim_maybe_code && s_processed && s_processed->length()) { // delimiter set and we have body  
                         if(need_delim) // need delim & iteration produced string?                          StringOrValue sv_processed=r.process(body_code);
                                 r.write_pass_lang(r.process(*delim_maybe_code));                          Request::Skip lskip=r.get_skip(); r.set_skip(Request::SKIP_NOTHING);
                         else  
                                 need_delim=true;                          const String* s_processed=sv_processed.get_string();
                 }                          if(s_processed && !s_processed->is_empty()) { // we have body
                                   if(need_delim) // need delim & iteration produced string?
                                           r.write_pass_lang(r.process(*delim_maybe_code));
                                   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)
                         break;                                  break;
                   }
           } else {
                   for(int row=0; row<size; row++) {
                           table.set_current(row);
    
                           r.process_write(body_code);
                           Request::Skip lskip=r.get_skip(); r.set_skip(Request::SKIP_NOTHING);
    
                           if(lskip==Request::SKIP_BREAK)
                                   break;
                   }
         }          }
         table.set_current(saved_current);          table.set_current(saved_current);
 }  }
Line 947  static void _locate(Request& r, MethodPa Line 964  static void _locate(Request& r, MethodPa
         bool result=params[0].get_junction()?          bool result=params[0].get_junction()?
                 _locate_expression(table, o, r, params) :                  _locate_expression(table, o, r, params) :
                 _locate_name_value(table, o, r, params);                  _locate_name_value(table, o, r, params);
         r.write_no_lang(*new VBool(result));          r.write_no_lang(VBool::get(result));
 }  }
   
   
Line 1030  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, true);
                         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 1103  void unmarshal_bind_updates(HashStringVa Line 1120  void unmarshal_bind_updates(HashStringVa
                 if(ph->were_updated) {                  if(ph->were_updated) {
                         Value* value;                          Value* value;
                         if(ph->is_null)                          if(ph->is_null)
                                 value=new VVoid();                                  value=VVoid::get();
                         else                          else
                                 if(ph->value)                                  if(ph->value)
                                         value=new VString(*new String(ph->value, 0, true/*tainted*/));                                          value=new VString(*new String(ph->value, true/*tainted*/));
                                 else                                  else
                                         value=new VString(*new String());                                                                                 value=new VString(*new String());                                       
                         hash.put(ph->name, value);                          hash.put(ph->name, value);
Line 1117  static void _sql(Request& r, MethodParam Line 1134  static void _sql(Request& r, MethodParam
         Value& statement=params.as_junction(0, "statement must be code");          Value& statement=params.as_junction(0, "statement must be code");
   
         HashStringValue* bind=0;          HashStringValue* bind=0;
         ulong limit=0;          ulong limit=SQL_NO_LIMIT;
         ulong offset=0;          ulong offset=0;
         if(params.count()>1) {          if(params.count()>1) {
                 Value& voptions=params.as_no_junction(1, "options must be hash, not code");                  Value& voptions=params.as_no_junction(1, "options must be hash, not code");

Removed from v.1.243  
changed lines
  Added in v.1.253


E-mail: