--- parser3/src/classes/hash.C 2002/09/18 08:52:47 1.50 +++ parser3/src/classes/hash.C 2002/12/09 12:19:16 1.53 @@ -5,7 +5,7 @@ Author: Alexandr Petrosian (http://paf.design.ru) */ -static const char* IDENT_HASH_C="$Date: 2002/09/18 08:52:47 $"; +static const char* IDENT_HASH_C="$Date: 2002/12/09 12:19:16 $"; #include "classes.h" #include "pa_request.h" @@ -31,12 +31,12 @@ public: // Methoded // methods #ifndef DOXYGEN -class Hash_sql_event_handlers : public SQL_Driver_query_event_handlers { +class Hash_sql_event_handlers: public SQL_Driver_query_event_handlers { public: Hash_sql_event_handlers(Pool& apool, const String& amethod_name, const String& astatement_string, const char *astatement_cstr, bool adistinct, - Hash& arows_hash) : + Hash& arows_hash): pool(apool), method_name(amethod_name), statement_string(astatement_string), @@ -46,39 +46,60 @@ public: columns(pool), row_index(0) { } - void add_column(void *ptr, size_t size) { - String *column=new(pool) String(pool); - column->APPEND_TAINTED( - (const char *)ptr, size, - statement_cstr, 0); - columns+=column; + 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, 0); + columns+=column; + + return false; + } catch(...) { + error=SQL_Error("exception occured in Hash_sql_event_handlers::add_column"); + return true; + } } - void before_rows() { - if(columns.size()<=1) - throw Exception("parser.runtime", + bool before_rows(SQL_Error& error) { + if(columns.size()<=1) { + error=SQL_Error("parser.runtime", &method_name, "column count must be more than 1 to create a hash"); + return true; + } + + return false; } - void add_row() { + bool add_row(SQL_Error& /*error*/) { column_index=0; + return false; } - void add_row_cell(void *ptr, size_t size) { - String *cell=new(pool) String(pool); - if(size) - cell->APPEND_TAINTED( - (const char *)ptr, size, - statement_cstr, row_index++); - if(column_index==0) { - VHash *row_vhash=new(pool) VHash(pool); - row_hash=row_vhash->get_hash(0); - if(rows_hash.put_dont_replace(*cell, row_vhash)) // put. existed? - if(!distinct) - throw Exception("parser.runtime", - cell, - "duplicate key"); - } else - row_hash->put(*columns.get_string(column_index), new(pool) VString(*cell)); - column_index++; + 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, row_index++); + if(column_index==0) { + VHash *row_vhash=new(pool) VHash(pool); + row_hash=row_vhash->get_hash(0); + if(rows_hash.put_dont_replace(*cell, row_vhash)) // put. existed? + if(!distinct) { + error=SQL_Error("parser.runtime", + cell, + "duplicate key"); + return true; + } + } else + row_hash->put(*columns.get_string(column_index), new(pool) VString(*cell)); + column_index++; + + return false; + } catch(...) { + error=SQL_Error("exception occured in Hash_sql_event_handlers::add_row_cell"); + return true; + } } private: @@ -295,8 +316,9 @@ static void one_foreach_cycle(const Hash Foreach_info& i=*static_cast(info); i.vkey->set_string(akey); - i.r->get_method_frame()->put_element(*i.key_var_name, i.vkey, false); - i.r->get_method_frame()->put_element(*i.value_var_name, static_cast(avalue), false); + Value& ncontext=*i.r->get_method_frame()->caller(); + ncontext.put_element(*i.key_var_name, i.vkey, false); + ncontext.put_element(*i.value_var_name, static_cast(avalue), false); StringOrValue sv_processed=i.r->process(*i.body_code); const String *s_processed=sv_processed.get_string();