|
|
| version 1.2, 2001/06/28 07:41:59 | version 1.26, 2002/12/09 11:07:40 |
|---|---|
| Line 1 | Line 1 |
| /** @file | /** @file |
| Parser: @b VOID parser class. | Parser: @b VOID parser class. |
| Copyright (c) 2001 ArtLebedev Group (http://www.artlebedev.com) | Copyright (c) 2001, 2002 ArtLebedev Group (http://www.artlebedev.com) |
| Author: Alexandr Petrosian <paf@design.ru> (http://paf.design.ru) | |
| Author: Alexander Petrosyan <paf@design.ru> (http://design.ru/paf) | |
| $Id$ | |
| */ | */ |
| static char *RCSId="$Id$"; | |
| static const char* IDENT_VOID_C="$Date$"; | |
| #include "classes.h" | #include "classes.h" |
| #include "pa_request.h" | #include "pa_request.h" |
| Line 16 static char *RCSId="$Id$"; | Line 14 static char *RCSId="$Id$"; |
| #include "pa_vvoid.h" | #include "pa_vvoid.h" |
| #include "pa_sql_connection.h" | #include "pa_sql_connection.h" |
| // defines | |
| #define VOID_CLASS_NAME "void" | |
| // class | // class |
| class MVoid : public Methoded { | class MVoid : public Methoded { |
| Line 31 public: // Methoded | Line 25 public: // Methoded |
| // methods | // methods |
| static void _int(Request& r, const String&, MethodParams *) { | static void _length(Request& r, const String&, MethodParams *params) { |
| Pool& pool=r.pool(); | Pool& pool=r.pool(); |
| VInt *vunknown=static_cast<VInt *>(r.self); | // always zero |
| Value& value=*new(pool) VInt(pool, vunknown->as_int()); | r.write_no_lang(*new(pool) VInt(pool, 0)); |
| r.write_no_lang(value); | |
| } | } |
| static void _double(Request& r, const String&, MethodParams *) { | static void _pos(Request& r, const String& method_name, MethodParams *params) { |
| Pool& pool=r.pool(); | Pool& pool=r.pool(); |
| VInt *vunknown=static_cast<VInt *>(r.self); | |
| Value& value=*new(pool) VDouble(pool, vunknown->as_double()); | Value& substr=params->as_no_junction(0, "substr must not be code"); |
| r.write_no_lang(value); | // never found |
| r.write_assign_lang(*new(pool) VInt(pool, -1)); | |
| } | } |
| static void _sql(Request& r, const String& method_name, MethodParams *params) { | static void _int(Request& r, const String&, MethodParams *params) { |
| Pool& pool=r.pool(); | Pool& pool=r.pool(); |
| VVoid *vvoid=static_cast<VVoid *>(r.get_self()); | |
| r.write_no_lang(*new(pool) VInt(pool, | |
| params->size()==0?vvoid->as_int():params->as_int(0, "default must be int", r))); | |
| } | |
| if(!r.connection) | static void _double(Request& r, const String&, MethodParams *params) { |
| PTHROW(0, 0, | Pool& pool=r.pool(); |
| &method_name, | VVoid *vvoid=static_cast<VVoid *>(r.get_self()); |
| "without connect"); | r.write_no_lang(*new(pool) VDouble(pool, |
| params->size()==0?vvoid->as_double():params->as_double(0, "default must be double", r))); | |
| Value& statement=params->get_junction(0, "statement must be code"); | } |
| Temp_lang temp_lang(r, String::UL_SQL); | #ifndef DOXYGEN |
| const String& statement_string=r.process(statement).as_string(); | class Void_sql_event_handlers: public SQL_Driver_query_event_handlers { |
| const char *statement_cstr= | public: |
| statement_string.cstr(String::UL_UNSPECIFIED, r.connection); | Void_sql_event_handlers(Pool& apool, const String& astatement_string) : |
| unsigned int sql_column_count; SQL_Driver::Cell *sql_columns; | pool(apool), statement_string(astatement_string) { |
| 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 | void add_column(void *ptr, size_t size) { /* ignore */ } |
| if(need_rethrow) | void before_rows() { |
| PTHROW(rethrow_me.type(), rethrow_me.code(), | // there are some result rows, which is wrong |
| &statement_string, // setting more specific source [were url] | throw SQL_Exception("parser.runtime", |
| rethrow_me.comment()); | |
| // there are some result rows, which is wrong | |
| if(sql_row_count) | |
| PTHROW(0, 0, | |
| &statement_string, | &statement_string, |
| "must not return result"); | "must return nothing"); |
| } | } |
| void add_row() { /* never */ } | |
| void add_row_cell(void *ptr, size_t size) { /* never */ } | |
| // constructor | private: |
| Pool& pool; | |
| const String& statement_string; | |
| }; | |
| #endif | |
| static void _sql(Request& r, const String& method_name, MethodParams *params) { | |
| Pool& pool=r.pool(); | |
| MVoid::MVoid(Pool& apool) : Methoded(apool) { | Value& statement=params->as_junction(0, "statement must be code"); |
| set_name(*NEW String(pool(), VOID_CLASS_NAME)); | |
| Temp_lang temp_lang(r, String::UL_SQL); | |
| const String& statement_string=r.process_to_string(statement); | |
| const char *statement_cstr= | |
| statement_string.cstr(String::UL_UNSPECIFIED, r.connection(&method_name)); | |
| Void_sql_event_handlers handlers(pool, statement_string); | |
| r.connection(&method_name)->query( | |
| statement_cstr, 0, 0, | |
| handlers, | |
| statement_string); | |
| } | |
| // ^VOID.int[] | // constructor |
| add_native_method("int", Method::CT_DYNAMIC, _int, 0, 0); | |
| // ^VOID.double[] | MVoid::MVoid(Pool& apool) : Methoded(apool, "void") { |
| add_native_method("double", Method::CT_DYNAMIC, _double, 0, 0); | // ^void.length[] |
| add_native_method("length", Method::CT_DYNAMIC, _length, 0, 0); | |
| // ^void.pos[substr] | |
| add_native_method("pos", Method::CT_DYNAMIC, _pos, 1, 1); | |
| // ^void.int[] | |
| // ^void.int(default) | |
| add_native_method("int", Method::CT_DYNAMIC, _int, 0, 1); | |
| // ^void.double[] | |
| // ^void.double(default) | |
| add_native_method("double", Method::CT_DYNAMIC, _double, 0, 1); | |
| // ^sql[query] | // ^sql[query] |
| add_native_method("sql", Method::CT_STATIC, _sql, 1, 1); | add_native_method("sql", Method::CT_STATIC, _sql, 1, 1); |