--- parser3/src/classes/op.C 2001/05/11 17:45:10 1.18 +++ parser3/src/classes/op.C 2001/05/21 16:01:10 1.22 @@ -5,7 +5,7 @@ Author: Alexander Petrosyan (http://design.ru/paf) - $Id: op.C,v 1.18 2001/05/11 17:45:10 parser Exp $ + $Id: op.C,v 1.22 2001/05/21 16:01:10 parser Exp $ */ #include "classes.h" @@ -266,11 +266,12 @@ static void _connect(Request& r, const S Value& url=params->get_no_junction(0, "url must not be code"); Value& body_code=params->get_junction(1, "body must be code"); - Table *protocol2library=static_cast(r.classes_conf.get(OP->name())); + Table *protocol2driver_and_client= + static_cast
(r.classes_conf.get(OP->name())); // connect SQL_Connection& connection=SQL_driver_manager->get_connection( - url.as_string(), protocol2library); + url.as_string(), protocol2driver_and_client); Exception rethrow_me; // remember/set current connection @@ -308,6 +309,45 @@ static void _connect(Request& r, const S rethrow_me.comment()); } +static void _sql(Request& r, const String& method_name, MethodParams *params) { + Pool& pool=r.pool(); + + if(!r.connection) + PTHROW(0, 0, + &method_name, + "without connect"); + + Value& statement=params->get_junction(0, "statement must be code"); + + Temp_lang temp_lang(r, String::UL_SQL); + const String& statement_string=r.process(statement).as_string(); + const char *statement_cstr= + statement_string.cstr(String::UL_UNSPECIFIED, r.connection); + unsigned int sql_column_count; SQL_Driver::Cell *sql_columns; + unsigned long sql_row_count; SQL_Driver::Cell **sql_rows; + bool need_rethrow=false; Exception rethrow_me; + PTRY { + r.connection->query( + statement_cstr, 0, 0, + &sql_column_count, &sql_columns, + &sql_row_count, &sql_rows); + } + PCATCH(e) { // connect/process problem + rethrow_me=e; need_rethrow=true; + } + PEND_CATCH + if(need_rethrow) + PTHROW(rethrow_me.type(), rethrow_me.code(), + &statement_string, // setting more specific source [were url] + rethrow_me.comment()); + + // there are some result rows, which is wrong + if(sql_row_count) + PTHROW(0, 0, + &statement_string, + "must not return result"); +} + // constructor MOP::MOP(Pool& apool) : Methoded(apool), @@ -369,6 +409,8 @@ MOP::MOP(Pool& apool) : Methoded(apool), // ^connect[protocol://user:pass@host[:port]/database]{code with ^sql-s} add_native_method("connect", Method::CT_ANY, _connect, 2, 2); + // ^sql[query] + add_native_method("sql", Method::CT_ANY, _sql, 1, 1); } // constructor & configurator