Diff for /parser3/src/classes/table.C between versions 1.94 and 1.97

version 1.94, 2001/07/23 11:19:25 version 1.97, 2001/07/28 12:07:26
Line 349  static void _empty(Request& r, const Str Line 349  static void _empty(Request& r, const Str
         r.write_no_lang(*new(pool) VBool(pool, table.size()==0));          r.write_no_lang(*new(pool) VBool(pool, table.size()==0));
 }  }
   
 /// used by table: _record / store_column_item_to_hash  
 struct Record_info {  
         Pool *pool;  
         Table *table;  
         Hash *hash;  
 };  
 static void store_column_item_to_hash(Array::Item *item, void *info) {  
         Record_info& ri=*static_cast<Record_info *>(info);  
         String& column_name=*static_cast<String *>(item);  
         Value *value;  
         if(const String *column_item=ri.table->item(column_name))  
                 value=new(*ri.pool) VString(*column_item);  
         else  
                 value=new(*ri.pool) VVoid(*ri.pool);  
         ri.hash->put(column_name, value);  
 }  
 static void _record(Request& r, const String& method_name, MethodParams *) {  
         Table& table=static_cast<VTable *>(r.self)->table();  
         if(const Array *columns=table.columns()) {  
                 Pool& pool=r.pool();  
                 Value& result=*new(pool) VHash(pool);  
                 Record_info record_info={&pool, &table, result.get_hash()};  
                 columns->for_each(store_column_item_to_hash, &record_info);  
                 result.set_name(method_name);  
                 r.write_no_lang(result);  
         }  
 }  
   
 /// used by table: _hash / table_row_to_hash  /// used by table: _hash / table_row_to_hash
 struct Row_info {  struct Row_info {
         Table *table;          Table *table;
Line 404  static void table_row_to_hash(Array::Ite Line 376  static void table_row_to_hash(Array::Ite
         }          }
 }  }
 static void _hash(Request& r, const String& method_name, MethodParams *params) {  static void _hash(Request& r, const String& method_name, MethodParams *params) {
           Pool& pool=r.pool();
         Table& table=static_cast<VTable *>(r.self)->table();          Table& table=static_cast<VTable *>(r.self)->table();
           Value& result=*new(pool) VHash(pool);
         if(const Array *columns=table.columns())           if(const Array *columns=table.columns()) 
                 if(columns->size()>1) {                  if(columns->size()>1) {
                         Pool& pool=r.pool();  
   
                         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();
Line 430  static void _hash(Request& r, const Stri Line 403  static void _hash(Request& r, const Stri
                         }                          }
   
                         // integers: key_field & value_fields                          // integers: key_field & value_fields
                         Value& result=*new(pool) VHash(pool);  
                         Row_info row_info={&table, key_field, &value_fields, result.get_hash()};                          Row_info row_info={&table, key_field, &value_fields, result.get_hash()};
                         table.for_each(table_row_to_hash, &row_info);                          table.for_each(table_row_to_hash, &row_info);
                         result.set_name(method_name);  
                         r.write_no_lang(result);  
                 }                  }
           result.set_name(method_name);
           r.write_no_lang(result);
 }  }
   
 /// used by table: _sort / sort_cmp_string|sort_cmp_double  /// used by table: _sort / sort_cmp_string|sort_cmp_double
Line 676  static void _sql(Request& r, const Strin Line 648  static void _sql(Request& r, const Strin
                 PTHROW(rethrow_me.type(), rethrow_me.code(),                   PTHROW(rethrow_me.type(), rethrow_me.code(), 
                         &statement_string, // setting more specific source [were url]                          &statement_string, // setting more specific source [were url]
                         rethrow_me.comment());                          rethrow_me.comment());
           
         if(!handlers.table)          Table *result=
                 PTHROW(0, 0,                   handlers.table?handlers.table: // query resulted in table? return it
                         &statement_string,                   new(pool) Table(pool, &method_name, 0); // query returned no table, fake it
                         "no table result");  
   
         // replace any previous table value          // replace any previous table value
         static_cast<VTable *>(r.self)->set_table(*handlers.table);          static_cast<VTable *>(r.self)->set_table(*result);
 }  }
   
 static void _dir(Request& r, const String& method_name, MethodParams *params) {  static void _dir(Request& r, const String& method_name, MethodParams *params) {
Line 821  MTable::MTable(Pool& apool) : Methoded(a Line 792  MTable::MTable(Pool& apool) : Methoded(a
         // ^table.empty[]          // ^table.empty[]
         add_native_method("empty", Method::CT_DYNAMIC, _empty, 0, 0);          add_native_method("empty", Method::CT_DYNAMIC, _empty, 0, 0);
   
         // ^table.record[]  
         add_native_method("record", Method::CT_DYNAMIC, _record, 0, 0);  
   
         // ^table:hash[key field name]          // ^table:hash[key field name]
         // ^table:hash[key field name][value field name;...]          // ^table:hash[key field name][value field name;...]
         add_native_method("hash", Method::CT_DYNAMIC, _hash, 1, 1000);          add_native_method("hash", Method::CT_DYNAMIC, _hash, 1, 1000);

Removed from v.1.94  
changed lines
  Added in v.1.97


E-mail: