--- parser3/src/classes/string.C 2002/09/18 08:52:49 1.120 +++ parser3/src/classes/string.C 2002/12/09 12:19:16 1.124 @@ -5,7 +5,7 @@ Author: Alexandr Petrosian (http://paf.design.ru) */ -static const char* IDENT_STRING_C="$Date: 2002/09/18 08:52:49 $"; +static const char* IDENT_STRING_C="$Date: 2002/12/09 12:19:16 $"; #include "classes.h" #include "pa_request.h" @@ -37,11 +37,15 @@ static void _length(Request& r, const St static void _int(Request& r, const String& method_name, MethodParams *params) { Pool& pool=r.pool(); + const String *self_string=r.get_self()->get_string(); int converted; - Value *default_code=params->size()>0? - default_code=¶ms->as_junction(0, "default must be int"):0; // (default) + Value *default_code=params->size()>0?¶ms->as_junction(0, "default must be int"):0; // (default) try { - converted=r.get_self()->as_int(); + if(!self_string || self_string->is_empty()) + throw Exception("parser.runtime", + &method_name, + "parameter is empty string, error converting"); + converted=self_string->as_int(); } catch(...) { // convert problem if(!default_code) // we have a problem when no default /*re*/throw; @@ -53,11 +57,15 @@ static void _int(Request& r, const Strin static void _double(Request& r, const String& method_name, MethodParams *params) { Pool& pool=r.pool(); + const String *self_string=r.get_self()->get_string(); double converted; - Value *default_code=params->size()>0? - default_code=¶ms->as_junction(0, "default must be double"):0; // (default) + Value *default_code=params->size()>0?¶ms->as_junction(0, "default must be double"):0; // (default) try { - converted=r.get_self()->as_double(); + if(!self_string || self_string->is_empty()) + throw Exception("parser.runtime", + &method_name, + "parameter is empty string, error converting"); + converted=self_string->as_double(); } catch(...) { // convert problem if(!default_code) // we have a problem when no default /*re*/throw; @@ -358,7 +366,7 @@ static void _lower(Request& r, const Str class String_sql_event_handlers : public SQL_Driver_query_event_handlers { public: String_sql_event_handlers(Pool& apool, - const String& astatement_string, const char *astatement_cstr) : + const String& astatement_string, const char *astatement_cstr): pool(apool), statement_string(astatement_string), statement_cstr(astatement_cstr), @@ -366,23 +374,34 @@ public: result=new(pool) String(pool); } - void add_column(void *ptr, size_t size) { - if(got_column) - throw Exception("parser.runtime", + bool add_column(SQL_Error& error, void *ptr, size_t size) { + if(got_column) { + error=SQL_Error("parser.runtime", &statement_string, "result must contain exactly one column"); + return true; + } got_column=true; + return false; } - void before_rows() { /* ignore */ } - void add_row() { /* ignore */ } - void add_row_cell(void *ptr, size_t size) { - if(got_cell) - throw Exception("parser.runtime", + bool before_rows(SQL_Error& /*error*/ ) { /* ignore */ return false; } + bool add_row(SQL_Error& /*error*/) { /* ignore */ return false; } + bool add_row_cell(SQL_Error& error, void *ptr, size_t size) { + if(got_cell) { + error=SQL_Error("parser.runtime", &statement_string, "result must not contain more then one row"); - got_cell=true; + return true; + } - result->APPEND_TAINTED((const char *)ptr, size, statement_cstr, 0); + try { + got_cell=true; + result->APPEND_TAINTED((const char *)ptr, size, statement_cstr, 0); + return false; + } catch(...) { + error=SQL_Error("exception occured in String_sql_event_handlers::add_row_cell"); + return true; + } } private: @@ -494,7 +513,7 @@ static void _save(Request& r, const Stri } // write - const char *buf=src.cstr(String::UL_UNSPECIFIED); + const char *buf=src.cstr(String::UL_UNSPECIFIED, r.connection(0/*no error if none*/)); file_write(r.absolute(file_name), buf, strlen(buf), true, do_append); }