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

version 1.263, 2009/07/29 05:01:33 version 1.271, 2010/05/16 22:12:50
Line 9  static const char * const IDENT_TABLE_C= Line 9  static const char * const IDENT_TABLE_C=
   
 #if (!defined(NO_STRINGSTREAM) && !defined(FREEBSD4))  #if (!defined(NO_STRINGSTREAM) && !defined(FREEBSD4))
 #include <sstream>  #include <sstream>
 using namespace std;  
 #endif  #endif
   
 #include "classes.h"  #include "classes.h"
Line 17  using namespace std; Line 16  using namespace std;
   
 #include "pa_common.h"  #include "pa_common.h"
 #include "pa_request.h"  #include "pa_request.h"
   #include "pa_charsets.h"
 #include "pa_vtable.h"  #include "pa_vtable.h"
 #include "pa_vint.h"  #include "pa_vint.h"
 #include "pa_sql_connection.h"  #include "pa_sql_connection.h"
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&) { return new VTable(); }
   
 public:  public:
         MTable();          MTable();
Line 54  String table_reverse_name(TABLE_REVERSE_ Line 54  String table_reverse_name(TABLE_REVERSE_
 // methods  // methods
   
 static Table::Action_options get_action_options(Request& r, MethodParams& params,   static Table::Action_options get_action_options(Request& r, MethodParams& params, 
                                                 const Table& source) {                                                  size_t options_index, const Table& source) {
         Table::Action_options result;          Table::Action_options result;
         if(!params.count())          if(params.count() <= options_index)
                 return result;                  return result;
   
         Value& maybe_options=params.last();          Value& maybe_options=params[options_index];
 /* can not do it:   /* can not do it: 
         want to enable ^table::create[$source;          want to enable ^table::create[$source;
 #               $.option[]  #               $.option[]
Line 156  struct TableSeparators { Line 156  struct TableSeparators {
 static void _create(Request& r, MethodParams& params) {  static void _create(Request& r, MethodParams& params) {
         // clone/copy part?          // clone/copy part?
         if(Table *source=params[0].get_table()) {          if(Table *source=params[0].get_table()) {
                 Table::Action_options o=get_action_options(r, params, *source);                  Table::Action_options o=get_action_options(r, params, 1, *source);
                 check_option_param(o.defined, params, 1,                   check_option_param(o.defined, params, 1, 
                         "too many parameters");                          "too many parameters");
                 GET_SELF(r, VTable).set_table(*new Table(*source, o));                  GET_SELF(r, VTable).set_table(*new Table(*source, o));
Line 387  static void _load(Request& r, MethodPara Line 387  static void _load(Request& r, MethodPara
   
 #if (!defined(NO_STRINGSTREAM) && !defined(FREEBSD4))  #if (!defined(NO_STRINGSTREAM) && !defined(FREEBSD4))
   
 void maybe_enclose( ostringstream& to, const String& from, char encloser ) {  #include "gc_allocator.h"
   
   typedef std::basic_stringstream<char, std::char_traits<char>, gc_allocator<char> > pa_stringstream;
   typedef std::basic_string<char, std::char_traits<char>, gc_allocator<char> > pa_string;
   
   void maybe_enclose( pa_stringstream& to, const String& from, char encloser ) {
         if(encloser) {          if(encloser) {
                 to<<encloser;                  to<<encloser;
                 // while we have 'encloser'...                  // while we have 'encloser'...
Line 461  static void _save(Request& r, MethodPara Line 466  static void _save(Request& r, MethodPara
                                 if(valid_options!=options->count())                                  if(valid_options!=options->count())
                                         throw Exception(PARSER_RUNTIME,                                          throw Exception(PARSER_RUNTIME,
                                                 0,                                                  0,
                                                 "invalid option passed");                                                  INVALID_OPTION_PASSED);
                         } else {                          } else {
                                 throw Exception(PARSER_RUNTIME,                                  throw Exception(PARSER_RUNTIME,
                                         0,                                          0,
Line 478  static void _save(Request& r, MethodPara Line 483  static void _save(Request& r, MethodPara
   
 #if (!defined(NO_STRINGSTREAM) && !defined(FREEBSD4))  #if (!defined(NO_STRINGSTREAM) && !defined(FREEBSD4))
   
         ostringstream ost(stringstream::out);          pa_stringstream ost(std::stringstream::out);
   
         // process header          // process header
         if(output_column_names) {          if(output_column_names) {
Line 520  static void _save(Request& r, MethodPara Line 525  static void _save(Request& r, MethodPara
   
         // write          // write
         {          {
                 string data=ost.str();                  pa_string data=ost.str();
                 const char* data_cstr=data.c_str();                  const char* data_cstr=data.c_str();
   
                 file_write(file_spec, data_cstr, data.length(), true /* as text */, do_append);                  file_write(r.charsets, file_spec, data_cstr, data.length(), true /* as text */, do_append);
         }          }
   
 #else  #else
Line 565  static void _save(Request& r, MethodPara Line 570  static void _save(Request& r, MethodPara
         // write          // write
         {          {
                 const char* data_cstr=sdata.cstr();                  const char* data_cstr=sdata.cstr();
                 file_write(file_spec,                   file_write(r.charsets, 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 681  static void table_row_to_hash(Table::ele Line 685  static void table_row_to_hash(Table::ele
         bool exist=false;          bool exist=false;
         switch(info->value_type) {          switch(info->value_type) {
                 case C_STRING: {                  case C_STRING: {
                         exist=info->hash->put_dont_replace(*key, new VString(*row->get(info->value_fields->get(0))));                          size_t index=info->value_fields->get(0);
                           exist=info->hash->put_dont_replace(*key, (index < row->count()) ? new VString(*row->get(index)) : new VString());
                         break;                          break;
                 }                  }
                 case C_HASH: {                  case C_HASH: {
Line 911  static void _sort(Request& r, MethodPara Line 916  static void _sort(Request& r, MethodPara
                 else                  else
                         seq[i].value.d=value.as_double();                          seq[i].value.d=value.as_double();
         }          }
   
           // @todo: handle this elsewhere
           if(r.charsets.source().NAME()=="KOI8-R" && key_values_are_strings) {
                   for(i=0; i<old_count; i++)
                           if(*seq[i].value.c_str)
                                   seq[i].value.c_str=Charset::transcode(seq[i].value.c_str, r.charsets.source(), UTF8_charset).cstr();
           }
   
         // sort keys          // sort keys
         _qsort(seq, old_count, sizeof(Table_seq_item),           _qsort(seq, old_count, sizeof(Table_seq_item), 
                 key_values_are_strings?sort_cmp_string:sort_cmp_double);                  key_values_are_strings?sort_cmp_string:sort_cmp_double);
Line 954  static bool _locate_name_value(Table& ta Line 967  static bool _locate_name_value(Table& ta
 static void _locate(Request& r, MethodParams& params) {  static void _locate(Request& r, MethodParams& params) {
         Table& table=GET_SELF(r, VTable).table();          Table& table=GET_SELF(r, VTable).table();
   
         Table::Action_options o=get_action_options(r, params, table);          Table::Action_options o=get_action_options(r, params, 1, table);
   
         bool result=params[0].get_junction()?          bool result=params[0].get_junction()?
                 _locate_expression(table, o, r, params) :                  _locate_expression(table, o, r, params) :
Line 967  static void _flip(Request& r, MethodPara Line 980  static void _flip(Request& r, MethodPara
         Table& old_table=GET_SELF(r, VTable).table();          Table& old_table=GET_SELF(r, VTable).table();
         Table& new_table=*new Table(0);          Table& new_table=*new Table(0);
         if(size_t old_count=old_table.count())          if(size_t old_count=old_table.count())
                 if(size_t old_cols=old_table[0]->count())                   if(size_t old_cols=old_table.columns()?old_table.columns()->count():old_table[0]->count()) 
                         for(size_t column=0; column<old_cols; column++) {                          for(size_t column=0; column<old_cols; column++) {
                                 Table::element_type new_row(new ArrayString(old_count));                                  Table::element_type new_row(new ArrayString(old_count));
                                 for(size_t i=0; i<old_count; i++) {                                  for(size_t i=0; i<old_count; i++) {
Line 981  static void _flip(Request& r, MethodPara Line 994  static void _flip(Request& r, MethodPara
 }  }
   
 static void _append(Request& r, MethodParams& params) {  static void _append(Request& r, MethodParams& params) {
         // data  
         Temp_lang temp_lang(r, String::L_PASS_APPENDED);          Temp_lang temp_lang(r, String::L_PASS_APPENDED);
         const String& string=r.process_to_string(params.as_junction(0, "body must be code"));          const String& string=r.process_to_string(params[0]);
   
         // parse cells          // parse cells
         Table::element_type row=new ArrayString;          Table::element_type row=new ArrayString;
Line 1014  static void _join(Request& r, MethodPara Line 1026  static void _join(Request& r, MethodPara
                         "source is not a table");                          "source is not a table");
         Table& src=*maybe_src;          Table& src=*maybe_src;
   
         Table::Action_options o=get_action_options(r, params, src);          Table::Action_options o=get_action_options(r, params, 1, src);
         check_option_param(o.defined, params, 1,          check_option_param(o.defined, params, 1,
                 "invalid extra parameter");                  "invalid extra parameter");
   

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


E-mail: