Diff for /parser3/src/classes/table.C between versions 1.149 and 1.154

version 1.149, 2002/04/15 10:35:21 version 1.154, 2002/08/01 11:26:44
Line 3 Line 3
   
         Copyright (c) 2001, 2002 ArtLebedev Group (http://www.artlebedev.com)          Copyright (c) 2001, 2002 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)
   
         $Id$  
 */  */
   
   static const char* IDENT_TABLE_C="$Id$";
   
 #include "classes.h"  #include "classes.h"
 #include "pa_common.h"  #include "pa_common.h"
 #include "pa_request.h"  #include "pa_request.h"
Line 15 Line 15
 #include "pa_sql_connection.h"  #include "pa_sql_connection.h"
 #include "pa_vbool.h"  #include "pa_vbool.h"
   
 // defines  
   
 #define TABLE_CLASS_NAME "table"  
   
 // class  // class
   
 class MTable : public Methoded {  class MTable : public Methoded {
Line 188  static void _save(Request& r, const Stri Line 184  static void _save(Request& r, const Stri
         while(i.has_next()) {          while(i.has_next()) {
                 Array_iter c(*static_cast<Array *>(i.next()));                  Array_iter c(*static_cast<Array *>(i.next()));
                 while(c.has_next()) {                  while(c.has_next()) {
                         sdata.append(*c.next_string(), //*static_cast<String *>(row->quick_get(column)),                           if(const String *s=c.next_string())
                                 String::UL_TABLE);                                  sdata.append(*s,
                                           String::UL_TABLE);
                         if(c.has_next())                          if(c.has_next())
                                 sdata.APPEND_CONST("\t");                                  sdata.APPEND_CONST("\t");
                 }                  }
Line 203  static void _save(Request& r, const Stri Line 200  static void _save(Request& r, const Stri
   
 static void _count(Request& r, const String& method_name, MethodParams *) {  static void _count(Request& r, const String& method_name, MethodParams *) {
         Pool& pool=r.pool();          Pool& pool=r.pool();
         Value& value=*new(pool) VInt(pool, static_cast<VTable *>(r.self)->table().size());          int result=static_cast<VTable *>(r.self)->table().size();
         value.set_name(method_name);          r.write_no_lang(*new(pool) VInt(pool, result));
         r.write_no_lang(value);  
 }  }
   
 static void _line(Request& r, const String& method_name, MethodParams *) {  static void _line(Request& r, const String& method_name, MethodParams *) {
         Pool& pool=r.pool();          Pool& pool=r.pool();
         Value& value=*new(pool) VInt(pool, 1+static_cast<VTable *>(r.self)->table().current());          int result=1+static_cast<VTable *>(r.self)->table().current();
         value.set_name(method_name);          r.write_no_lang(*new(pool) VInt(pool, result));
         r.write_no_lang(value);  
 }  }
   
 static void _offset(Request& r, const String& method_name, MethodParams *params) {  static void _offset(Request& r, const String& method_name, MethodParams *params) {
Line 234  static void _offset(Request& r, const St Line 229  static void _offset(Request& r, const St
                                   
                 Value& offset_expr=params->as_junction(params->size()-1, "offset must be expression");                  Value& offset_expr=params->as_junction(params->size()-1, "offset must be expression");
                 table.offset(absolute, r.process_to_value(offset_expr).as_int());                  table.offset(absolute, r.process_to_value(offset_expr).as_int());
         } else {          } else
                 Value& value=*new(pool) VInt(pool, table.current());                  r.write_no_lang(*new(pool) VInt(pool, table.current()));
                 value.set_name(method_name);  
                 r.write_no_lang(value);  
         }  
 }  }
   
 static void _menu(Request& r, const String& method_name, MethodParams *params) {  static void _menu(Request& r, const String& method_name, MethodParams *params) {
Line 253  static void _menu(Request& r, const Stri Line 245  static void _menu(Request& r, const Stri
         for(int row=0; row<size; row++) {          for(int row=0; row<size; row++) {
                 table.set_current(row);                  table.set_current(row);
   
                 Value& processed_body=r.process_to_value(body_code);                  StringOrValue processed_body=r.process(body_code);
                 if(delim_maybe_code) { // delimiter set?                  if(delim_maybe_code) { // delimiter set?
                         const String *string=processed_body.get_string();                          const String *string=processed_body.get_string();
                         if(need_delim && string && string->size()) // need delim & iteration produced string?                          if(need_delim && string && string->size()) // need delim & iteration produced string?
                                 r.write_pass_lang(r.process_to_string(*delim_maybe_code));                                  r.write_pass_lang(r.process(*delim_maybe_code));
                         need_delim=true;                          need_delim=true;
                 }                  }
                 r.write_pass_lang(processed_body);                  r.write_pass_lang(processed_body);
Line 296  static void _hash(Request& r, const Stri Line 288  static void _hash(Request& r, const Stri
         Pool& pool=r.pool();          Pool& pool=r.pool();
         Table& self_table=static_cast<VTable *>(r.self)->table();          Table& self_table=static_cast<VTable *>(r.self)->table();
         Value& result=*new(pool) VHash(pool);          Value& result=*new(pool) VHash(pool);
         if(const Array *columns=self_table.columns())           if(const Array *columns=self_table.columns())
                 if(columns->size()>1) {                  if(columns->size()>0) {
                         const String& key_field_name=params->as_no_junction(0,                           const String& key_field_name=params->as_no_junction(0, 
                                 "key field name must not be code").as_string();                                  "key field name must not be code").as_string();
                         int key_field=self_table.column_name2index(key_field_name, true);                          int key_field=self_table.column_name2index(key_field_name, true);
Line 327  static void _hash(Request& r, const Stri Line 319  static void _hash(Request& r, const Stri
                         Row_info row_info={&self_table, key_field, &value_fields, result.get_hash(0)};                          Row_info row_info={&self_table, key_field, &value_fields, result.get_hash(0)};
                         self_table.for_each(table_row_to_hash, &row_info);                          self_table.for_each(table_row_to_hash, &row_info);
                 }                  }
         result.set_name(method_name);  
         r.write_no_lang(result);          r.write_no_lang(result);
 }  }
   
Line 435  static bool _locate_name_value(Request& Line 426  static bool _locate_name_value(Request&
 }  }
 static void _locate(Request& r, const String& method_name, MethodParams *params) {  static void _locate(Request& r, const String& method_name, MethodParams *params) {
         Pool& pool=r.pool();          Pool& pool=r.pool();
         Value& result=*new(pool) VBool(pool,           bool result=params->get(0).get_junction()?
                 params->get(0).get_junction()?  
                 _locate_expression(r, method_name, params) :                  _locate_expression(r, method_name, params) :
                 _locate_name_value(r, method_name, params));                  _locate_name_value(r, method_name, params);
         result.set_name(method_name);          r.write_no_lang(*new(pool) VBool(pool, result));
         r.write_no_lang(result);  
 }  }
   
 static void _flip(Request& r, const String& method_name, MethodParams *params) {  static void _flip(Request& r, const String& method_name, MethodParams *params) {
Line 635  static void _columns(Request& r, const S Line 624  static void _columns(Request& r, const S
                 }                  }
         }          }
   
         VTable& result=*new(pool) VTable(pool, &result_table);          r.write_no_lang(*new(pool) VTable(pool, &result_table));
         result.set_name(method_name);  
         r.write_no_lang(result);  
 }  }
   
 static void _select(Request& r, const String& method_name, MethodParams *params) {  static void _select(Request& r, const String& method_name, MethodParams *params) {
Line 656  static void _select(Request& r, const St Line 643  static void _select(Request& r, const St
         for(int row=0; row<size; row++) {          for(int row=0; row<size; row++) {
                 source_table.set_current(row);                  source_table.set_current(row);
   
                 bool condition=                  bool condition=r.process_to_value(vcondition, 
                         r.process_to_value(  
                                 vcondition,   
                                 /*0/*no name* /,*/                                  /*0/*no name* /,*/
                                 false/*don't intercept string*/).as_bool();                                  false/*don't intercept string*/).as_bool();
   
Line 667  static void _select(Request& r, const St Line 652  static void _select(Request& r, const St
         }          }
         source_table.set_current(saved_current);          source_table.set_current(saved_current);
   
         VTable& result=*new(pool) VTable(pool, &result_table);          r.write_no_lang(*new(pool) VTable(pool, &result_table));
         result.set_name(method_name);  
         r.write_no_lang(result);  
 }  }
   
 // constructor  // constructor
   
 MTable::MTable(Pool& apool) : Methoded(apool) {  MTable::MTable(Pool& apool) : Methoded(apool, "table") {
         set_name(*NEW String(pool(), TABLE_CLASS_NAME));  
   
         // ^table::create{data}          // ^table::create{data}
         // ^table::create[nameless]{data}          // ^table::create[nameless]{data}
         // ^table::create[table]          // ^table::create[table]

Removed from v.1.149  
changed lines
  Added in v.1.154


E-mail: