|
|
| version 1.38, 2007/04/23 10:30:10 | version 1.47, 2010/10/21 15:06:29 |
|---|---|
| Line 1 | Line 1 |
| /** @file | /** @file |
| Parser: @b VOID parser class. | Parser: @b VOID parser class. |
| Copyright (c) 2001-2005 ArtLebedev Group (http://www.artlebedev.com) | Copyright (c) 2001-2009 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) |
| */ | */ |
| Line 26 extern String sql_bind_name; | Line 26 extern String sql_bind_name; |
| class MVoid: public Methoded { | class MVoid: public Methoded { |
| public: | public: |
| MVoid(); | MVoid(); |
| public: // Methoded | |
| bool used_directly() { return true; } | |
| }; | }; |
| // global variable | // global variable |
| Line 44 static void _length(Request& r, MethodPa | Line 42 static void _length(Request& r, MethodPa |
| static void _pos(Request& r, MethodParams& params) { | static void _pos(Request& r, MethodParams& params) { |
| // just checking for consistency | // just checking for consistency |
| params.as_no_junction(0, "substr must not be code"); | params.as_no_junction(0, "substr must not be code"); |
| if(params.count()>1){ | |
| ssize_t offset=params.as_int(1, "n must be int", r); | |
| if(offset<0) | |
| throw Exception(PARSER_RUNTIME, | |
| 0, | |
| "n(%d) must be >=0", offset); | |
| } | |
| // never found | // never found |
| r.write_no_lang(*new VInt(-1)); | r.write_no_lang(*new VInt(-1)); |
| } | } |
| Line 62 static void _double(Request& r, MethodPa | Line 67 static void _double(Request& r, MethodPa |
| static void _bool(Request& r, MethodParams& params) { | static void _bool(Request& r, MethodParams& params) { |
| VVoid& vvoid=GET_SELF(r, VVoid); | VVoid& vvoid=GET_SELF(r, VVoid); |
| r.write_no_lang(*new VBool( | r.write_no_lang(VBool::get(params.count()==0?vvoid.as_bool():params.as_bool(0, "default must be bool", r))); |
| params.count()==0?vvoid.as_bool():params.as_bool(0, "default must be bool", r))); | |
| } | } |
| #ifndef DOXYGEN | #ifndef DOXYGEN |
| Line 102 static void _sql(Request& r, MethodParam | Line 106 static void _sql(Request& r, MethodParam |
| bind=vbind->get_hash(); | bind=vbind->get_hash(); |
| } | } |
| if(valid_options!=options->count()) | if(valid_options!=options->count()) |
| throw Exception(PARSER_RUNTIME, | throw Exception(PARSER_RUNTIME, 0, CALLED_WITH_INVALID_OPTION); |
| 0, | |
| "called with invalid option"); | |
| } else | } else |
| throw Exception(PARSER_RUNTIME, | throw Exception(PARSER_RUNTIME, 0, OPTIONS_MUST_BE_HASH); |
| 0, | |
| "options must be hash"); | |
| } | } |
| SQL_Driver::Placeholder* placeholders=0; | SQL_Driver::Placeholder* placeholders=0; |
| Line 118 static void _sql(Request& r, MethodParam | Line 118 static void _sql(Request& r, MethodParam |
| Temp_lang temp_lang(r, String::L_SQL); | Temp_lang temp_lang(r, String::L_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.untaint_cstr(r.flang, r.connection()); |
| statement_string.cstr(String::L_UNSPECIFIED, r.connection()); | |
| Void_sql_event_handlers handlers(statement_string); | Void_sql_event_handlers handlers(statement_string); |
| r.connection()->query( | r.connection()->query( |
| statement_cstr, | statement_cstr, |
| placeholders_count, placeholders, | placeholders_count, placeholders, |
| 0, 0, | 0, SQL_NO_LIMIT, |
| handlers, | handlers, |
| statement_string); | statement_string); |
| Line 167 MVoid::MVoid(): Methoded("void") { | Line 167 MVoid::MVoid(): Methoded("void") { |
| add_native_method("length", Method::CT_DYNAMIC, _length, 0, 0); | add_native_method("length", Method::CT_DYNAMIC, _length, 0, 0); |
| // ^void.pos[substr] | // ^void.pos[substr] |
| add_native_method("pos", Method::CT_DYNAMIC, _pos, 1, 1); | // ^void.pos[substr](n) |
| add_native_method("pos", Method::CT_DYNAMIC, _pos, 1, 2); | |
| // ^void.int[] | // ^void.int[] |
| // ^void.int(default) | // ^void.int(default) |
| Line 181 MVoid::MVoid(): Methoded("void") { | Line 182 MVoid::MVoid(): Methoded("void") { |
| // ^void.bool(default) | // ^void.bool(default) |
| add_native_method("bool", Method::CT_DYNAMIC, _bool, 0, 1); | add_native_method("bool", Method::CT_DYNAMIC, _bool, 0, 1); |
| // ^sql[query] | // ^void:sql{query} |
| add_native_method("sql", Method::CT_STATIC, _sql, 1, 2); | add_native_method("sql", Method::CT_STATIC, _sql, 1, 2); |
| // ^void.left() ^void.right() | // ^void.left() ^void.right() |