Diff for /parser3/src/classes/table.C between versions 1.172.2.4 and 1.174

version 1.172.2.4, 2003/02/04 14:12:42 version 1.174, 2003/04/11 10:39:24
Line 1 Line 1
 /** @file  /** @file
         Parser: @b table parser class.          Parser: @b table parser class.
   
         Copyright (c) 2001-2003 ArtLebedev Group (http://www.artlebedev.com)          Copyright (c) 2001, 2003 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)
 */  */
   
 static const char* IDENT_TABLE_C="$Date$";  static const char* IDENT_TABLE_C="$Date$";
   
 #include "classes.h"  #include "classes.h"
 #include "pa_vmethod_frame.h"  
   
 #include "pa_common.h"  #include "pa_common.h"
 #include "pa_request.h"  #include "pa_request.h"
 #include "pa_vtable.h"  #include "pa_vtable.h"
Line 21  static const char* IDENT_TABLE_C="$Date$ Line 19  static const char* IDENT_TABLE_C="$Date$
   
 class MTable : public Methoded {  class MTable : public Methoded {
 public: // VStateless_class  public: // VStateless_class
         ValuePtr create_new_value() { return ValuePtr(new VTable()); }          Value *create_new_value(Pool& pool) { return new(pool) VTable(pool); }
   
 public:  public:
         MTable(Pool& pool);          MTable(Pool& pool);
Line 32  public: // Methoded Line 30  public: // Methoded
   
 // methods  // methods
   
 static void get_copy_options(Request& r, StringPtr method_name, MethodParams& params, int param_index,  static void get_copy_options(Request& r, const String& method_name, MethodParams *params, int param_index,
                                                          const Table& source,                                                           const Table& source,
                                                          int& offset,                                                           int& offset,
                                                          int& limit) {                                                           int& limit) {
         offset=0;          offset=0;
         limit=0;          limit=0;
         if(params.count()<=param_index)          if(params->size()<=param_index)
                 return;                  return;
   
         Value& voptions=params.as_no_junction(param_index, "options must be hash, not code");          Value& voptions=params->as_no_junction(param_index, "options must be hash, not code");
         if(!voptions.is_string()) {          if(!voptions.is_string()) {
                 if(Hash *options=voptions.get_hash(&method_name)) {                  if(Hash *options=voptions.get_hash(&method_name)) {
                         int valid_options=0;                          int valid_options=0;
Line 75  static void get_copy_options(Request& r, Line 73  static void get_copy_options(Request& r,
                 limit=-1; // thus fixing                  limit=-1; // thus fixing
 }  }
   
 static void _create(Request& r, StringPtr method_name, MethodParams& params) {  static void _create(Request& r, const String& method_name, MethodParams *params) {
         Pool& pool=r.pool();          Pool& pool=r.pool();
         // clone/copy part?          // clone/copy part?
         if(const Table *source=params.get(0).get_table()) {          if(const Table *source=params->get(0).get_table()) {
                 int offset, limit;                  int offset, limit;
                 get_copy_options(r, method_name, params, 1, *source,                   get_copy_options(r, method_name, params, 1, *source, 
                         offset, limit);                          offset, limit);
Line 89  static void _create(Request& r, StringPt Line 87  static void _create(Request& r, StringPt
         // data is last parameter          // data is last parameter
         Temp_lang temp_lang(r, String::UL_PASS_APPENDED);          Temp_lang temp_lang(r, String::UL_PASS_APPENDED);
         const String& data=          const String& data=
                 r.process_to_string(params.as_junction(params.count()-1, "body must be code"));                  r.process_to_string(params->as_junction(params->size()-1, "body must be code"));
   
         size_t pos_after=0;          size_t pos_after=0;
         // parse columns          // parse columns
         Array *columns;          Array *columns;
         if(params.count()==2) {          if(params->size()==2) {
                 columns=0;                  columns=0;
         } else {          } else {
                 columns=new(pool) Array(pool);                  columns=new(pool) Array(pool);
Line 125  static void _create(Request& r, StringPt Line 123  static void _create(Request& r, StringPt
         static_cast<VTable *>(r.get_self())->set_table(table);          static_cast<VTable *>(r.get_self())->set_table(table);
 }  }
   
 static void _load(Request& r, StringPtr method_name, MethodParams& params) {  static void _load(Request& r, const String& method_name, MethodParams *params) {
         Pool& pool=r.pool();          Pool& pool=r.pool();
         const String& first_param=params.as_string(0, "file name must be string");          const String& first_param=params->as_string(0, "file name must be string");
         int filename_param_index=0;          int filename_param_index=0;
         bool nameless=first_param=="nameless";          bool nameless=first_param=="nameless";
         if(nameless)          if(nameless)
Line 136  static void _load(Request& r, StringPtr Line 134  static void _load(Request& r, StringPtr
                   
         // loading text          // loading text
         char *data=file_read_text(pool,           char *data=file_read_text(pool, 
                 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_param_index<params.count()?params.as_no_junction(options_param_index, "additional params must be hash").get_hash(&method_name):0                  options_param_index<params->size()?params->as_no_junction(options_param_index, "additional params must be hash").get_hash(&method_name):0
         );          );
   
         // parse columns          // parse columns
         Array *columns;          Array *columns;
 #ifndef NO_STRING_ORIGIN  #ifndef NO_STRING_ORIGIN
         const Origin& origin=method_name.origin();          const Origin& origin=method_name.origin();
         const char* file=origin.file;          const char *file=origin.file;
         uint line=origin.line;          uint line=origin.line;
 #endif  #endif
         if(nameless) {          if(nameless) {
Line 191  static void _load(Request& r, StringPtr Line 189  static void _load(Request& r, StringPtr
 }  }
   
 /// @todo "x\nx" "xxx""xx"  /// @todo "x\nx" "xxx""xx"
 static void _save(Request& r, StringPtr method_name, MethodParams& params) {  static void _save(Request& r, const String& method_name, MethodParams *params) {
         Pool& pool=r.pool();          Pool& pool=r.pool();
         Value& vfile_name=params.as_no_junction(params.count()-1,           Value& vfile_name=params->as_no_junction(params->size()-1, 
                 "file name must not be code");                  "file name must not be code");
   
         Table& table=static_cast<VTable *>(r.get_self())->table(&method_name);          Table& table=static_cast<VTable *>(r.get_self())->table(&method_name);
   
         bool do_append=false;          bool do_append=false;
         String sdata(pool);          String sdata(pool);
         if(params.count()==1) { // named output          if(params->size()==1) { // named output
                 // write out names line                  // write out names line
                 if(table.columns()) { // named table                  if(table.columns()) { // named table
                         Array_iter i(*table.columns());                          Array_iter i(*table.columns());
Line 222  static void _save(Request& r, StringPtr Line 220  static void _save(Request& r, StringPtr
                 }                  }
                 sdata.APPEND_CONST("\n");                  sdata.APPEND_CONST("\n");
         } else { // mode specified          } else { // mode specified
                 const String& mode=params.as_string(0, "mode must be string");                  const String& mode=params->as_string(0, "mode must be string");
                 if(mode=="append")                  if(mode=="append")
                         do_append=true;                          do_append=true;
                 else if(mode=="nameless")                  else if(mode=="nameless")
Line 252  static void _save(Request& r, StringPtr Line 250  static void _save(Request& r, StringPtr
                 sdata.cstr(), sdata.size(), true, do_append);                  sdata.cstr(), sdata.size(), true, do_append);
 }  }
   
 static void _count(Request& r, StringPtr method_name, MethodParams& ) {  static void _count(Request& r, const String& method_name, MethodParams *) {
         Pool& pool=r.pool();          Pool& pool=r.pool();
         int result=static_cast<VTable *>(r.get_self())->table(&method_name).size();          int result=static_cast<VTable *>(r.get_self())->table(&method_name).size();
         r.write_no_lang(*new(pool) VInt(pool, result));          r.write_no_lang(*new(pool) VInt(pool, result));
 }  }
   
 static void _line(Request& r, StringPtr method_name, MethodParams& ) {  static void _line(Request& r, const String& method_name, MethodParams *) {
         Pool& pool=r.pool();          Pool& pool=r.pool();
         int result=1+static_cast<VTable *>(r.get_self())->table(&method_name).current();          int result=1+static_cast<VTable *>(r.get_self())->table(&method_name).current();
         r.write_no_lang(*new(pool) VInt(pool, result));          r.write_no_lang(*new(pool) VInt(pool, result));
 }  }
   
 static void _offset(Request& r, StringPtr method_name, MethodParams& params) {  static void _offset(Request& r, const String& method_name, MethodParams *params) {
         Pool& pool=r.pool();          Pool& pool=r.pool();
         Table& table=static_cast<VTable *>(r.get_self())->table(&method_name);          Table& table=static_cast<VTable *>(r.get_self())->table(&method_name);
         if(params.count()) {          if(params->size()) {
                 bool absolute=false;                  bool absolute=false;
                 if(params.count()>1) {                  if(params->size()>1) {
                     const String& whence=params.as_string(0, "whence must be string");                      const String& whence=params->as_string(0, "whence must be string");
                     if(whence=="cur")                      if(whence=="cur")
                                 absolute=false;                                  absolute=false;
                     else if(whence=="set")                      else if(whence=="set")
Line 281  static void _offset(Request& r, StringPt Line 279  static void _offset(Request& r, StringPt
                                         "is invalid whence, valid are 'cur' or 'set'");                                          "is invalid whence, valid are 'cur' or 'set'");
                 }                  }
                                   
                 Value& offset_expr=params.as_junction(params.count()-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
                 r.write_no_lang(*new(pool) VInt(pool, table.current()));                  r.write_no_lang(*new(pool) VInt(pool, table.current()));
 }  }
   
 static void _menu(Request& r, StringPtr method_name, MethodParams& params) {  static void _menu(Request& r, const String& method_name, MethodParams *params) {
         Value& body_code=params.as_junction(0, "body must be code");          Value& body_code=params->as_junction(0, "body must be code");
                   
         Value *delim_maybe_code=params.count()>1?&params.get(1):0;          Value *delim_maybe_code=params->size()>1?&params->get(1):0;
   
         Table& table=static_cast<VTable *>(r.get_self())->table(&method_name);          Table& table=static_cast<VTable *>(r.get_self())->table(&method_name);
         bool need_delim=false;          bool need_delim=false;
Line 312  static void _menu(Request& r, StringPtr Line 310  static void _menu(Request& r, StringPtr
 }  }
   
 #ifndef DOXYGEN  #ifndef DOXYGEN
   enum Table2hash_distint { D_ILLEGAL, D_FIRST, D_TABLES };
 struct Row_info {  struct Row_info {
         Request *r;          Request *r;
         Table *table;          Table *table;
Line 319  struct Row_info { Line 318  struct Row_info {
         int key_field;          int key_field;
         Array *value_fields;          Array *value_fields;
         Hash *hash;          Hash *hash;
         bool distinct;          Table2hash_distint distinct;
         int row;          int row;
 };  };
 #endif  #endif
Line 339  static void table_row_to_hash(Array::Ite Line 338  static void table_row_to_hash(Array::Ite
         if(!key)          if(!key)
                 return; // ignore rows without key [too-short-record_array if-indexed]                  return; // ignore rows without key [too-short-record_array if-indexed]
                                   
         VHash& result=*new(pool) VHash(pool);          switch(ri.distinct) {
         Hash& hash=*result.get_hash(0);          case D_ILLEGAL: case D_FIRST:
         for(int i=0; i<ri.value_fields->size(); i++) {                  {
                 int value_field=ri.value_fields->get_int(i);                          VHash& result=*new(pool) VHash(pool);
                 if(value_field<row.size())                          Hash& hash=*result.get_hash(0);
                         hash.put(                          for(int i=0; i<ri.value_fields->size(); i++) {
                                 *ri.table->columns()->get_string(value_field),                                   int value_field=ri.value_fields->get_int(i);
                                 new(pool) VString(*row.get_string(value_field)));                                  if(value_field<row.size())
                                           hash.put(
                                                   *ri.table->columns()->get_string(value_field), 
                                                   new(pool) VString(*row.get_string(value_field)));
                           }
   
                           if(ri.hash->put_dont_replace(*key, &result)) // put. existed?
                                   if(ri.distinct==D_ILLEGAL)
                                           throw Exception("parser.runtime",
                                                   key,
                                                   "duplicate key");
                   }
                   break;
           case D_TABLES:
                   {
                           VTable* vtable=(VTable*)ri.hash->get(*key); // put. table existed?
                           Table* table;
                           if(vtable) 
                                   table=vtable->get_table();
                           else {
                                   // no? creating table of same structure as source
                                   table=new(pool) Table(pool, *ri.table, 0, -1 /*no rows, just structure*/);
                                   ri.hash->put(*key, new(pool) VTable(pool, table));
                           }
                           *table+=&row;
                   }
                   break;
           default:
                   throw Exception(0,
                           0,
                           "invalid distinct code (#%d), ri.distinct");
         }          }
   
         if(ri.hash->put_dont_replace(*key, &result)) // put. existed?  
                 if(!ri.distinct)  
                         throw Exception("parser.runtime",  
                                 key,  
                                 "duplicate key");  
 }  }
 static void _hash(Request& r, StringPtr method_name, MethodParams& params) {  static void _hash(Request& r, const String& method_name, MethodParams *params) {
         Pool& pool=r.pool();          Pool& pool=r.pool();
         Table& self_table=static_cast<VTable *>(r.get_self())->table(&method_name);          Table& self_table=static_cast<VTable *>(r.get_self())->table(&method_name);
         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()>0) {                  if(columns->size()>0) {
                         bool distinct=false;                          Table2hash_distint distinct=D_ILLEGAL;
                         int param_index=params.count()-1;                          int param_index=params->size()-1;
                         if(param_index>0) {                          if(param_index>0) {
                                 if(Hash *options=                                  if(Hash *options=
                                         params.as_no_junction(param_index, "param must not be code").get_hash(0)) {                                          params->as_no_junction(param_index, "param must not be code").get_hash(0)) {
                                         --param_index;                                          --param_index;
                                         int valid_options=0;                                          int valid_options=0;
                                         if(Value *vdistinct=(Value *)options->get(*sql_distinct_name)) {                                          if(Value *vdistinct_code=(Value *)options->get(*sql_distinct_name)) {
                                                 valid_options++;                                                  valid_options++;
                                                 distinct=r.process_to_value(*vdistinct).as_bool();                                                  Value& vdistinct_value=r.process_to_value(*vdistinct_code);
                                                   if(vdistinct_value.is_string()) {
                                                           const String& sdistinct=*vdistinct_value.get_string();
                                                           if(sdistinct=="tables")
                                                                   distinct=D_TABLES;
                                                           else
                                                                   throw Exception("parser.runtime",
                                                                           &sdistinct,
                                                                           "must be 'tables' or true/false");
                                                   } else
                                                           distinct=vdistinct_value.as_bool()?D_FIRST:D_ILLEGAL;
                                         }                                          }
                                         if(valid_options!=options->size())                                          if(valid_options!=options->size())
                                                 throw Exception("parser.runtime",                                                  throw Exception("parser.runtime",
Line 385  static void _hash(Request& r, StringPtr Line 419  static void _hash(Request& r, StringPtr
   
                         Array value_fields(pool);                          Array value_fields(pool);
                         if(param_index>0) {                          if(param_index>0) {
                                 Value& value_fields_param=params.as_no_junction(param_index, "value field(s) must not be code");                                  if(distinct!=D_ILLEGAL && distinct!=D_FIRST)
                                           throw Exception("parser.runtime",
                                                   0,
                                                   "in distinct[tables] mode you may not specify value field(s)");
                                   Value& value_fields_param=params->as_no_junction(param_index, "value field(s) must not be code");
                                 if(value_fields_param.is_string()) {                                  if(value_fields_param.is_string()) {
                                         value_fields+=self_table.column_name2index(value_fields_param.as_string(), true);                                          value_fields+=self_table.column_name2index(value_fields_param.as_string(), true);
                                 } else if(Table *value_fields_table=value_fields_param.get_table()) {                                  } else if(Table *value_fields_table=value_fields_param.get_table()) {
Line 400  static void _hash(Request& r, StringPtr Line 438  static void _hash(Request& r, StringPtr
                                                 "value field(s) must be string or self_table"                                                  "value field(s) must be string or self_table"
                                         );                                          );
                         } else { // by all columns, including key                          } else { // by all columns, including key
                                 for(int i=0; i<columns->size(); i++)                                  if(!(distinct!=D_ILLEGAL && distinct!=D_FIRST))
                                         value_fields+=i;                                          for(int i=0; i<columns->size(); i++)
                                                   value_fields+=i;
                         }                          }
   
                         Value& key_param=params.get(0);                          Value& key_param=params->get(0);
                         Value *key_code=key_param.get_junction()?&key_param:0;                          Value *key_code=key_param.get_junction()?&key_param:0;
                         int key_field=key_code?-1                          int key_field=key_code?-1
                                 :self_table.column_name2index(key_param.as_string(), true);                                  :self_table.column_name2index(key_param.as_string(), true);
   
                         Row_info row_info={&r, &self_table, key_code, key_field, &value_fields, result.get_hash(0), distinct};                          Row_info row_info={&r, &self_table, 
                                   key_code, key_field, &value_fields, 
                                   result.get_hash(0), distinct};
   
                         int saved_current=self_table.current();                          int saved_current=self_table.current();
                         self_table.for_each(table_row_to_hash, &row_info);                          self_table.for_each(table_row_to_hash, &row_info);
Line 443  static int sort_cmp_double(const void *a Line 484  static int sort_cmp_double(const void *a
         else           else 
                 return 0;                  return 0;
 }  }
 static void _sort(Request& r, StringPtr method_name, MethodParams& params) {  static void _sort(Request& r, const String& method_name, MethodParams *params) {
         Pool& pool=r.pool();          Pool& pool=r.pool();
         Value& key_maker=params.as_junction(0, "key-maker must be code");          Value& key_maker=params->as_junction(0, "key-maker must be code");
   
         bool reverse=params.count()>1/*..[desc|asc|]*/?          bool reverse=params->size()>1/*..[desc|asc|]*/?
                 reverse=params.as_no_junction(1, "order must not be code").as_string()=="desc":                  reverse=params->as_no_junction(1, "order must not be code").as_string()=="desc":
                 false; // default=asc                  false; // default=asc
   
         Table& old_table=static_cast<VTable *>(r.get_self())->table(&method_name);          Table& old_table=static_cast<VTable *>(r.get_self())->table(&method_name);
           if(old_table.size()==0)
                   return;
   
         Table& new_table=*new(pool) Table(pool, &method_name, old_table.columns());          Table& new_table=*new(pool) Table(pool, &method_name, old_table.columns());
   
         Table_seq_item *seq=(Table_seq_item *)pool.malloc(sizeof(Table_seq_item)*old_table.size());          Table_seq_item *seq=(Table_seq_item *)pool.malloc(sizeof(Table_seq_item)*old_table.size());
Line 484  static void _sort(Request& r, StringPtr Line 528  static void _sort(Request& r, StringPtr
         static_cast<VTable *>(r.get_self())->set_table(new_table);          static_cast<VTable *>(r.get_self())->set_table(new_table);
 }  }
   
 static bool _locate_expression(Request& r, StringPtr method_name, MethodParams& params) {  static bool _locate_expression(Request& r, const String& method_name, MethodParams *params) {
         if(params.count()>1)          if(params->size()>1)
                 throw Exception("parser.runtime",                   throw Exception("parser.runtime", 
                         &method_name,                          &method_name,
                         "locate by expression has only one parameter - expression");                          "locate by expression has only one parameter - expression");
   
         Value& expression_code=params.as_junction(0, "must be expression");          Value& expression_code=params->as_junction(0, "must be expression");
   
         Table& table=static_cast<VTable *>(r.get_self())->table(&method_name);          Table& table=static_cast<VTable *>(r.get_self())->table(&method_name);
         int saved_current=table.current();          int saved_current=table.current();
Line 504  static bool _locate_expression(Request& Line 548  static bool _locate_expression(Request&
         table.set_current(saved_current);          table.set_current(saved_current);
         return false;          return false;
 }  }
 static bool _locate_name_value(Request& r, StringPtr method_name, MethodParams& params) {  static bool _locate_name_value(Request& r, const String& method_name, MethodParams *params) {
         if(params.count()>2)          if(params->size()>2)
                 throw Exception("parser.runtime",                   throw Exception("parser.runtime", 
                         &method_name,                          &method_name,
                         "locate by name and value has only two parameters - name and value");                          "locate by name and value has only two parameters - name and value");
   
         Table& table=static_cast<VTable *>(r.get_self())->table(&method_name);          Table& table=static_cast<VTable *>(r.get_self())->table(&method_name);
         return table.locate(          return table.locate(
                 params.as_string(0, "column name must be string"),                  params->as_string(0, "column name must be string"),
                 params.as_string(1, "value must be string")                  params->as_string(1, "value must be string")
         );          );
 }  }
 static void _locate(Request& r, StringPtr method_name, MethodParams& params) {  static void _locate(Request& r, const String& method_name, MethodParams *params) {
         Pool& pool=r.pool();          Pool& pool=r.pool();
         bool result=params.get(0).get_junction()?          bool result=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);
         r.write_no_lang(*new(pool) VBool(pool, result));          r.write_no_lang(*new(pool) VBool(pool, result));
 }  }
   
 static void _flip(Request& r, StringPtr method_name, MethodParams& params) {  static void _flip(Request& r, const String& method_name, MethodParams *params) {
         Pool& pool=r.pool();          Pool& pool=r.pool();
         Table& old_table=static_cast<VTable *>(r.get_self())->table(&method_name);          Table& old_table=static_cast<VTable *>(r.get_self())->table(&method_name);
         Table& new_table=*new(pool) Table(pool, &method_name, 0/*nameless*/);          Table& new_table=*new(pool) Table(pool, &method_name, 0/*nameless*/);
Line 542  static void _flip(Request& r, StringPtr Line 586  static void _flip(Request& r, StringPtr
         r.write_no_lang(*new(pool) VTable(pool, &new_table));          r.write_no_lang(*new(pool) VTable(pool, &new_table));
 }  }
   
 static void _append(Request& r, StringPtr method_name, MethodParams& params) {  static void _append(Request& r, const String& method_name, MethodParams *params) {
         Pool& pool=r.pool();          Pool& pool=r.pool();
         // data          // data
         Temp_lang temp_lang(r, String::UL_PASS_APPENDED);          Temp_lang temp_lang(r, String::UL_PASS_APPENDED);
         const String& string=          const String& string=
                 r.process_to_string(params.as_junction(0, "body must be code"));                  r.process_to_string(params->as_junction(0, "body must be code"));
   
         // parse cells          // parse cells
         Array& row=*new(pool) Array(pool);          Array& row=*new(pool) Array(pool);
Line 556  static void _append(Request& r, StringPt Line 600  static void _append(Request& r, StringPt
         static_cast<VTable *>(r.get_self())->table(&method_name)+=&row;          static_cast<VTable *>(r.get_self())->table(&method_name)+=&row;
 }  }
   
 static void _join(Request& r, StringPtr method_name, MethodParams& params) {  static void _join(Request& r, const String& method_name, MethodParams *params) {
         Pool& pool=r.pool();          Pool& pool=r.pool();
   
         Table *maybe_src=params.as_no_junction(0, "table ref must not be code").get_table();          Table *maybe_src=params->as_no_junction(0, "table ref must not be code").get_table();
         if(!maybe_src)          if(!maybe_src)
                 throw Exception("parser.runtime",                   throw Exception("parser.runtime", 
                         &method_name,                           &method_name, 
Line 602  static void _join(Request& r, StringPtr Line 646  static void _join(Request& r, StringPtr
 class Table_sql_event_handlers: public SQL_Driver_query_event_handlers {  class Table_sql_event_handlers: public SQL_Driver_query_event_handlers {
 public:  public:
         Table_sql_event_handlers(Pool& apool, const String& amethod_name,          Table_sql_event_handlers(Pool& apool, const String& amethod_name,
                 const String& astatement_string, const char* astatement_cstr) :                  const String& astatement_string, const char *astatement_cstr) :
                 pool(apool),                   pool(apool), 
                 method_name(amethod_name),                  method_name(amethod_name),
                 statement_string(astatement_string),                  statement_string(astatement_string),
Line 617  public: Line 661  public:
                 try {                  try {
                         String *column=new(pool) String(pool);                          String *column=new(pool) String(pool);
                         column->APPEND_TAINTED(                          column->APPEND_TAINTED(
                                 (const char* )ptr, size,                                   (const char *)ptr, size, 
                                 statement_cstr, 0);                                  statement_cstr, 0);
                         columns+=column;                          columns+=column;
                         return false;                          return false;
Line 649  public: Line 693  public:
                         String *cell=new(pool) String(pool);                          String *cell=new(pool) String(pool);
                         if(size)                          if(size)
                                 cell->APPEND_TAINTED(                                  cell->APPEND_TAINTED(
                                         (const char* )ptr, size,                                           (const char *)ptr, size, 
                                         statement_cstr, table->size()-1);                                          statement_cstr, table->size()-1);
                         (*row)+=cell;                          (*row)+=cell;
                         return false;                          return false;
Line 662  public: Line 706  public:
 private:  private:
         Pool& pool;          Pool& pool;
         const String& method_name;          const String& method_name;
         const String& statement_string; const char* statement_cstr;          const String& statement_string; const char *statement_cstr;
         Array& columns;          Array& columns;
         Array *row;          Array *row;
 public:  public:
         Table *table;          Table *table;
 };  };
 #endif  #endif
 static void _sql(Request& r, StringPtr method_name, MethodParams& params) {  static void _sql(Request& r, const String& method_name, MethodParams *params) {
         Pool& pool=r.pool();          Pool& pool=r.pool();
   
         Value& statement=params.as_junction(0, "statement must be code");          Value& statement=params->as_junction(0, "statement must be code");
   
         ulong limit=0;          ulong limit=0;
         ulong offset=0;          ulong offset=0;
         if(params.count()>1) {          if(params->size()>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");
                 if(!voptions.is_string())                  if(!voptions.is_string())
                         if(Hash *options=voptions.get_hash(&method_name)) {                          if(Hash *options=voptions.get_hash(&method_name)) {
                                 int valid_options=0;                                  int valid_options=0;
Line 701  static void _sql(Request& r, StringPtr m Line 745  static void _sql(Request& r, StringPtr m
   
         Temp_lang temp_lang(r, String::UL_SQL);          Temp_lang temp_lang(r, String::UL_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.cstr(String::UL_UNSPECIFIED, r.connection(&method_name));                  statement_string.cstr(String::UL_UNSPECIFIED, r.connection(&method_name));
         Table_sql_event_handlers handlers(pool, method_name,          Table_sql_event_handlers handlers(pool, method_name,
                 statement_string, statement_cstr);                  statement_string, statement_cstr);
Line 734  static void _sql(Request& r, StringPtr m Line 778  static void _sql(Request& r, StringPtr m
         static_cast<VTable *>(r.get_self())->set_table(*result);          static_cast<VTable *>(r.get_self())->set_table(*result);
 }  }
   
 static void _columns(Request& r, StringPtr method_name, MethodParams& ) {  static void _columns(Request& r, const String& method_name, MethodParams *) {
         Pool& pool=r.pool();          Pool& pool=r.pool();
   
         Array& result_columns=*new(pool) Array(pool);          Array& result_columns=*new(pool) Array(pool);
Line 754  static void _columns(Request& r, StringP Line 798  static void _columns(Request& r, StringP
         r.write_no_lang(*new(pool) VTable(pool, &result_table));          r.write_no_lang(*new(pool) VTable(pool, &result_table));
 }  }
   
 static void _select(Request& r, StringPtr method_name, MethodParams& params) {  static void _select(Request& r, const String& method_name, MethodParams *params) {
         Pool& pool=r.pool();          Pool& pool=r.pool();
   
         Value& vcondition=params.as_junction(0, "condition must be expression");          Value& vcondition=params->as_junction(0, "condition must be expression");
   
         Table& source_table=static_cast<VTable *>(r.get_self())->table(&method_name);          Table& source_table=static_cast<VTable *>(r.get_self())->table(&method_name);
         Table& result_table=*new(pool) Table(pool,           Table& result_table=*new(pool) Table(pool, 

Removed from v.1.172.2.4  
changed lines
  Added in v.1.174


E-mail: