Diff for /parser3/src/classes/table.C between versions 1.258 and 1.269

version 1.258, 2009/06/14 00:33:36 version 1.269, 2009/11/09 00:31:07
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 39  public: // Methoded Line 39  public: // Methoded
   
 DECLARE_CLASS_VAR(table, new MTable, 0);  DECLARE_CLASS_VAR(table, new MTable, 0);
   
 // externs  
   
 extern String cycle_data_name;  
   
 #define TABLE_REVERSE_NAME "reverse"  #define TABLE_REVERSE_NAME "reverse"
   
 // globals  // globals
Line 58  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 160  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 391  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 465  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 482  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 524  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 569  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 611  static void _offset(Request& r, MethodPa Line 611  static void _offset(Request& r, MethodPa
 }  }
   
 static void _menu(Request& r, MethodParams& params) {  static void _menu(Request& r, MethodParams& params) {
         Temp_hash_value<const String::Body, void*>           InCycle temp(r);
                 cycle_data_setter(r.classes_conf, cycle_data_name, /*any not null flag*/&r);  
   
         Value& body_code=params.as_junction(0, "body must be code");          Value& body_code=params.as_junction(0, "body must be code");
                   
Line 916  static void _sort(Request& r, MethodPara Line 915  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 959  static bool _locate_name_value(Table& ta Line 966  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 986  static void _flip(Request& r, MethodPara Line 993  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 1019  static void _join(Request& r, MethodPara Line 1025  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");
   
Line 1047  public: Line 1053  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) {          bool add_column(SQL_Error& error, const char *str, size_t length) {
                 try {                  try {
                         columns+=new String(str, String::L_TAINTED);                          columns+=new String(str, String::L_TAINTED, length);
                         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 1075  public: Line 1081  public:
                         return true;                          return true;
                 }                  }
         }          }
         bool add_row_cell(SQL_Error& error, const char* str, size_t) {          bool add_row_cell(SQL_Error& error, const char* str, size_t length) {
                 try {                  try {
                         *row+=new String(str, String::L_TAINTED);                          *row+=new String(str, String::L_TAINTED, length);
                         return false;                          return false;
                 } catch(...) {                  } catch(...) {
                         error=SQL_Error("exception occured in Table_sql_event_handlers::add_row_cell");                          error=SQL_Error("exception occured in Table_sql_event_handlers::add_row_cell");
Line 1094  static void marshal_bind( Line 1100  static void marshal_bind(
 {  {
         SQL_Driver::Placeholder& ph=**pptr;          SQL_Driver::Placeholder& ph=**pptr;
         ph.name=aname.cstr();          ph.name=aname.cstr();
         ph.value=avalue->as_string().cstr(String::L_UNSPECIFIED);          ph.value=avalue->as_string().untaint_cstr(String::L_AS_IS);
         ph.is_null=avalue->get_class()==void_class;          ph.is_null=avalue->get_class()==void_class;
         ph.were_updated=false;          ph.were_updated=false;
   
Line 1164  static void _sql(Request& r, MethodParam Line 1170  static void _sql(Request& r, MethodParam
   
         Temp_lang temp_lang(r, String::L_SQL);          Temp_lang temp_lang(r, String::L_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.untaint_cstr(r.flang, r.connection());
                 statement_string.cstr(String::L_UNSPECIFIED, r.connection());  
         Table_sql_event_handlers handlers;          Table_sql_event_handlers handlers;
 #ifdef RESOURCES_DEBUG  #ifdef RESOURCES_DEBUG
         struct timeval mt[2];          struct timeval mt[2];

Removed from v.1.258  
changed lines
  Added in v.1.269


E-mail: