|
|
| version 1.17, 2002/03/27 15:30:34 | version 1.26, 2002/12/09 11:07:40 |
|---|---|
| Line 3 | Line 3 |
| Copyright (c) 2001, 2002 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: Alexandr Petrosian <paf@design.ru> (http://paf.design.ru) |
| $Id$ | |
| */ | */ |
| static const char* IDENT_VOID_C="$Date$"; | |
| #include "classes.h" | #include "classes.h" |
| #include "pa_request.h" | #include "pa_request.h" |
| #include "pa_vint.h" | #include "pa_vint.h" |
| Line 14 | Line 14 |
| #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 29 public: // Methoded | Line 25 public: // Methoded |
| // methods | // methods |
| static void _length(Request& r, const String&, MethodParams *params) { | |
| Pool& pool=r.pool(); | |
| // always zero | |
| r.write_no_lang(*new(pool) VInt(pool, 0)); | |
| } | |
| static void _pos(Request& r, const String& method_name, MethodParams *params) { | |
| Pool& pool=r.pool(); | |
| Value& substr=params->as_no_junction(0, "substr must not be code"); | |
| // never found | |
| r.write_assign_lang(*new(pool) VInt(pool, -1)); | |
| } | |
| static void _int(Request& r, const String&, 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.self); | VVoid *vvoid=static_cast<VVoid *>(r.get_self()); |
| r.write_no_lang(*new(pool) VInt(pool, | r.write_no_lang(*new(pool) VInt(pool, |
| params->size()==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, const String&, MethodParams *params) { |
| Pool& pool=r.pool(); | Pool& pool=r.pool(); |
| VVoid *vvoid=static_cast<VVoid *>(r.self); | VVoid *vvoid=static_cast<VVoid *>(r.get_self()); |
| r.write_no_lang(*new(pool) VDouble(pool, | r.write_no_lang(*new(pool) VDouble(pool, |
| params->size()==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 { |
| public: | public: |
| Void_sql_event_handlers(Pool& apool, const String& astatement_string) : | Void_sql_event_handlers(Pool& apool, const String& astatement_string) : |
| pool(apool), statement_string(astatement_string) { | pool(apool), statement_string(astatement_string) { |
| Line 52 public: | Line 62 public: |
| void add_column(void *ptr, size_t size) { /* ignore */ } | void add_column(void *ptr, size_t size) { /* ignore */ } |
| void before_rows() { | void before_rows() { |
| // there are some result rows, which is wrong | // there are some result rows, which is wrong |
| throw Exception("parser.runtime", | throw SQL_Exception("parser.runtime", |
| &statement_string, | &statement_string, |
| "must return nothing"); | "must return nothing"); |
| } | } |
| Line 70 static void _sql(Request& r, const Strin | Line 80 static void _sql(Request& r, const Strin |
| 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::UL_SQL); | Temp_lang temp_lang(r, String::UL_SQL); |
| const String& statement_string=r.process(statement).as_string(); | 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::UL_UNSPECIFIED, r.connection(&method_name)); |
| Void_sql_event_handlers handlers(pool, statement_string); | Void_sql_event_handlers handlers(pool, statement_string); |
| try { | r.connection(&method_name)->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) { | MVoid::MVoid(Pool& apool) : Methoded(apool, "void") { |
| set_name(*NEW String(pool(), VOID_CLASS_NAME)); | // ^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[] |
| // ^void.int(default) | // ^void.int(default) |