--- parser3/src/classes/table.C 2002/10/23 09:32:17 1.166 +++ parser3/src/classes/table.C 2002/12/14 12:47:29 1.171 @@ -5,7 +5,7 @@ Author: Alexandr Petrosian (http://paf.design.ru) */ -static const char* IDENT_TABLE_C="$Date: 2002/10/23 09:32:17 $"; +static const char* IDENT_TABLE_C="$Date: 2002/12/14 12:47:29 $"; #include "classes.h" #include "pa_common.h" @@ -125,12 +125,19 @@ static void _create(Request& r, const St static void _load(Request& r, const String& method_name, MethodParams *params) { Pool& pool=r.pool(); - // filename is last parameter - Value& vfile_name=params->as_no_junction(params->size()-1, - "file name must not be code"); - + const String& first_param=params->as_string(0, "file name must be string"); + int filename_param_index=0; + bool nameless=first_param=="nameless"; + if(nameless) + filename_param_index++; + int options_param_index=filename_param_index+1; + // loading text - char *data=file_read_text(pool, r.absolute(vfile_name.as_string())); + char *data=file_read_text(pool, + r.absolute(params->as_string(filename_param_index, "file name must be string")), + true, + options_param_indexsize()?params->as_no_junction(options_param_index, "additional params must be hash").get_hash(&method_name):0 + ); // parse columns Array *columns; @@ -139,7 +146,7 @@ static void _load(Request& r, const Stri const char *file=origin.file; uint line=origin.line; #endif - if(params->size()==2) { + if(nameless) { columns=0; // nameless } else { columns=new(pool) Array(pool); @@ -311,7 +318,7 @@ struct Row_info { Array *value_fields; Hash *hash; bool distinct; - int index; + int row; }; #endif static void table_row_to_hash(Array::Item *value, void *info) { @@ -321,7 +328,7 @@ static void table_row_to_hash(Array::Ite const String *key; if(ri.key_code) { - ri.table->set_current(ri.index++); // change context row + ri.table->set_current(ri.row++); // change context row StringOrValue sv_processed=ri.r->process(*ri.key_code); key=&sv_processed.as_string(); } else @@ -450,8 +457,6 @@ static void _sort(Request& r, const Stri // calculate key values bool key_values_are_strings=true; - // save 'current' - int saved_current=old_table.current(); for(i=0; iAPPEND_TAINTED( - (const char *)ptr, size, - statement_cstr, 0); - columns+=column; - } - void before_rows() { - table=new(pool) Table(pool, &method_name, &columns); - } - void add_row() { - (*table)+=(row=new(pool) Array(pool)); - } - void add_row_cell(void *ptr, size_t size) { - String *cell=new(pool) String(pool); - if(size) - cell->APPEND_TAINTED( + bool add_column(SQL_Error& error, void *ptr, size_t size) { + try { + String *column=new(pool) String(pool); + column->APPEND_TAINTED( (const char *)ptr, size, - statement_cstr, table->size()-1); - (*row)+=cell; + statement_cstr, 0); + columns+=column; + return false; + } catch(...) { + error=SQL_Error("exception occured in Table_sql_event_handlers::add_column"); + return true; + } + } + bool before_rows(SQL_Error& error) { + try { + table=new(pool) Table(pool, &method_name, &columns); + return false; + } catch(...) { + error=SQL_Error("exception occured in Table_sql_event_handlers::before_rows"); + return true; + } + } + bool add_row(SQL_Error& error) { + try { + (*table)+=(row=new(pool) Array(pool)); + return false; + } catch(...) { + error=SQL_Error("exception occured in Table_sql_event_handlers::add_row"); + return true; + } + } + bool add_row_cell(SQL_Error& error, void *ptr, size_t size) { + try { + String *cell=new(pool) String(pool); + if(size) + cell->APPEND_TAINTED( + (const char *)ptr, size, + statement_cstr, table->size()-1); + (*row)+=cell; + return false; + } catch(...) { + error=SQL_Error("exception occured in Table_sql_event_handlers::add_row_cell"); + return true; + } } private: @@ -765,7 +792,7 @@ MTable::MTable(Pool& apool) : Methoded(a // ^table::load[file] // ^table::load[nameless;file] - add_native_method("load", Method::CT_DYNAMIC, _load, 1, 2); + add_native_method("load", Method::CT_DYNAMIC, _load, 1, 3); // ^table.save[file] // ^table.save[nameless;file]