|
|
| version 1.21.2.2, 2002/08/20 09:36:21 | version 1.29, 2003/07/24 11:31:20 |
|---|---|
| Line 1 | Line 1 |
| /** @file | /** @file |
| Parser: @b VOID parser class. | Parser: @b VOID parser class. |
| Copyright (c) 2001, 2002 ArtLebedev Group (http://www.artlebedev.com) | Copyright (c) 2001-2003 ArtLebedev Group (http://www.artlebedev.com) |
| Author: Alexandr Petrosian <paf@design.ru> (http://paf.design.ru) | Author: Alexandr Petrosian <paf@design.ru> (http://paf.design.ru) |
| */ | */ |
| static const char* IDENT_VOID_C="$Date$"; | static const char* IDENT_VOID_C="$Date$"; |
| #include "classes.h" | #include "classes.h" |
| #include "pa_vmethod_frame.h" | |
| #include "pa_request.h" | #include "pa_request.h" |
| #include "pa_vint.h" | #include "pa_vint.h" |
| #include "pa_vdouble.h" | #include "pa_vdouble.h" |
| Line 16 static const char* IDENT_VOID_C="$Date$" | Line 18 static const char* IDENT_VOID_C="$Date$" |
| // class | // class |
| class MVoid : public Methoded { | class MVoid: public Methoded { |
| public: | public: |
| MVoid(Pool& pool); | MVoid(); |
| public: // Methoded | public: // Methoded |
| bool used_directly() { return true; } | bool used_directly() { return true; } |
| }; | }; |
| // global variable | |
| DECLARE_CLASS_VAR(void, new MVoid, 0); | |
| // methods | // methods |
| static void _length(Request& r, const String&, MethodParams *params) { | static void _length(Request& r, MethodParams&) { |
| Pool& pool=r.pool(); | |
| // always zero | // always zero |
| r.write_no_lang(*new(pool) VInt(pool, 0)); | r.write_no_lang(*new VInt(0)); |
| } | } |
| static void _pos(Request& r, const String& method_name, MethodParams *params) { | static void _pos(Request& r, MethodParams& params) { |
| Pool& pool=r.pool(); | // just checking for consistency |
| params.as_no_junction(0, "substr must not be code"); | |
| Value& substr=params->as_no_junction(0, "substr must not be code"); | |
| // never found | // never found |
| r.write_assign_lang(*new(pool) VInt(pool, -1)); | r.write_no_lang(*new VInt(-1)); |
| } | } |
| static void _int(Request& r, const String&, MethodParams *params) { | static void _int(Request& r, MethodParams& params) { |
| Pool& pool=r.pool(); | VVoid& vvoid=GET_SELF(r, VVoid); |
| VVoid *vvoid=static_cast<VVoid *>(r.self); | r.write_no_lang(*new VInt( |
| r.write_no_lang(*new(pool) VInt(pool, | params.count()==0?vvoid.as_int():params.as_int(0, "default must be int", r))); |
| params->size()==0?vvoid->as_int():params->as_int(0, "default must be int", r))); | |
| } | } |
| static void _double(Request& r, const String&, MethodParams *params) { | static void _double(Request& r, MethodParams& params) { |
| Pool& pool=r.pool(); | VVoid& vvoid=GET_SELF(r, VVoid); |
| VVoid *vvoid=static_cast<VVoid *>(r.self); | r.write_no_lang(*new VDouble( |
| r.write_no_lang(*new(pool) VDouble(pool, | params.count()==0?vvoid.as_double():params.as_double(0, "default must be double", r))); |
| params->size()==0?vvoid->as_double():params->as_double(0, "default must be double", r))); | |
| } | } |
| #ifndef DOXYGEN | #ifndef DOXYGEN |
| class Void_sql_event_handlers : public SQL_Driver_query_event_handlers { | class Void_sql_event_handlers: public SQL_Driver_query_event_handlers { |
| const String& statement_string; | |
| public: | public: |
| Void_sql_event_handlers(Pool& apool, const String& astatement_string) : | Void_sql_event_handlers(const String& astatement_string): statement_string(astatement_string) {} |
| pool(apool), statement_string(astatement_string) { | bool add_column(SQL_Error& /*error*/, const char* /*str*/, size_t /*length*/) { /* ignore */ return false; } |
| } | bool before_rows(SQL_Error& error) { |
| void add_column(void *ptr, size_t size) { /* ignore */ } | |
| void before_rows() { | |
| // there are some result rows, which is wrong | // there are some result rows, which is wrong |
| throw Exception("parser.runtime", | error=SQL_Error("parser.runtime", |
| &statement_string, | /*statement_string,*/ |
| "must return nothing"); | "must return nothing"); |
| return true; | |
| } | } |
| void add_row() { /* never */ } | bool add_row(SQL_Error& /*error*/) { /* never */ return false; } |
| void add_row_cell(void *ptr, size_t size) { /* never */ } | bool add_row_cell(SQL_Error& /*error*/, const char* /*str*/, size_t /*length*/) { /* never */ return false; } |
| private: | |
| Pool& pool; | |
| const String& statement_string; | |
| }; | }; |
| #endif | #endif |
| static void _sql(Request& r, const String& method_name, MethodParams *params) { | static void _sql(Request& r, MethodParams& params) { |
| Pool& pool=r.pool(); | Value& statement=params.as_junction(0, "statement must be code"); |
| Value& statement=params->as_junction(0, "statement must be code"); | Temp_lang temp_lang(r, String::L_SQL); |
| Temp_lang temp_lang(r, String::UL_SQL); | |
| const String& statement_string=r.process_to_string(statement); | const String& statement_string=r.process_to_string(statement); |
| const char *statement_cstr= | const char* statement_cstr= |
| statement_string.cstr(String::UL_UNSPECIFIED, r.connection(&method_name)); | statement_string.cstr(String::L_UNSPECIFIED, r.connection()); |
| Void_sql_event_handlers handlers(pool, statement_string); | Void_sql_event_handlers handlers(statement_string); |
| try { | r.connection()->query( |
| r.connection(&method_name)->query( | statement_cstr, 0, 0, |
| statement_cstr, 0, 0, | handlers, |
| handlers); | statement_string); |
| } catch(const Exception& e) { | |
| // more specific source [were url] | |
| throw Exception("sql.execute", | |
| &statement_string, | |
| "%s", e.comment()); | |
| } | |
| } | } |
| // constructor | // constructor |
| MVoid::MVoid(Pool& apool) : Methoded(apool, "void") { | MVoid::MVoid(): Methoded("void") { |
| // ^void.length[] | // ^void.length[] |
| add_native_method("length", Method::CT_DYNAMIC, _length, 0, 0); | add_native_method("length", Method::CT_DYNAMIC, _length, 0, 0); |
| Line 116 MVoid::MVoid(Pool& apool) : Methoded(apo | Line 107 MVoid::MVoid(Pool& apool) : Methoded(apo |
| // ^sql[query] | // ^sql[query] |
| add_native_method("sql", Method::CT_STATIC, _sql, 1, 1); | add_native_method("sql", Method::CT_STATIC, _sql, 1, 1); |
| } | } |
| // global variable | |
| Methoded *void_class; | |
| // creator | |
| Methoded *MVoid_create(Pool& pool) { | |
| return void_class=new(pool) MVoid(pool); | |
| } |