Annotation of parser3/src/classes/void.C, revision 1.50
1.1 parser 1: /** @file
2: Parser: @b VOID parser class.
3:
1.50 ! moko 4: Copyright (c) 2001-2012 Art. Lebedev Studio (http://www.artlebedev.com)
1.16 paf 5: Author: Alexandr Petrosian <paf@design.ru> (http://paf.design.ru)
1.20 paf 6: */
1.1 parser 7:
8: #include "classes.h"
1.29 paf 9: #include "pa_vmethod_frame.h"
10:
1.1 parser 11: #include "pa_request.h"
12: #include "pa_vvoid.h"
13: #include "pa_sql_connection.h"
14:
1.50 ! moko 15: volatile const char * IDENT_VOID_C="$Id: 2011-05-19 06:58:40 $";
! 16:
1.33 paf 17: // externs
18:
19: extern String sql_bind_name;
20:
1.1 parser 21: // class
22:
1.29 paf 23: class MVoid: public Methoded {
1.1 parser 24: public:
1.29 paf 25: MVoid();
1.1 parser 26: };
27:
1.48 moko 28: // void is inherited from string, thus global variable declared in string.C
1.29 paf 29:
1.1 parser 30: // methods
31:
1.5 parser 32: #ifndef DOXYGEN
1.26 paf 33: class Void_sql_event_handlers: public SQL_Driver_query_event_handlers {
1.29 paf 34: const String& statement_string;
1.5 parser 35: public:
1.29 paf 36: Void_sql_event_handlers(const String& astatement_string): statement_string(astatement_string) {}
37: bool add_column(SQL_Error& /*error*/, const char* /*str*/, size_t /*length*/) { /* ignore */ return false; }
1.27 paf 38: bool before_rows(SQL_Error& error) {
1.5 parser 39: // there are some result rows, which is wrong
1.38 misha 40: error=SQL_Error(PARSER_RUNTIME,
1.29 paf 41: /*statement_string,*/
1.5 parser 42: "must return nothing");
1.27 paf 43: return true;
1.5 parser 44: }
1.27 paf 45: bool add_row(SQL_Error& /*error*/) { /* never */ return false; }
1.29 paf 46: bool add_row_cell(SQL_Error& /*error*/, const char* /*str*/, size_t /*length*/) { /* never */ return false; }
1.5 parser 47:
48: };
49: #endif
1.34 paf 50:
51: extern int marshal_binds(HashStringValue& hash, SQL_Driver::Placeholder*& placeholders);
52: extern void unmarshal_bind_updates(HashStringValue& hash, int placeholder_count, SQL_Driver::Placeholder* placeholders);
53:
1.29 paf 54: static void _sql(Request& r, MethodParams& params) {
55: Value& statement=params.as_junction(0, "statement must be code");
1.1 parser 56:
1.33 paf 57: HashStringValue* bind=0;
1.49 misha 58: if(params.count()>1)
59: if(HashStringValue* options=params.as_hash(1)) {
60: int valid_options=0;
61: if(Value* vbind=options->get(sql_bind_name)) {
62: valid_options++;
63: bind=vbind->get_hash();
64: }
65: if(valid_options!=options->count())
66: throw Exception(PARSER_RUNTIME, 0, CALLED_WITH_INVALID_OPTION);
67: }
1.33 paf 68:
69: SQL_Driver::Placeholder* placeholders=0;
70: uint placeholders_count=0;
71: if(bind)
72: placeholders_count=marshal_binds(*bind, placeholders);
73:
1.29 paf 74: Temp_lang temp_lang(r, String::L_SQL);
1.18 paf 75: const String& statement_string=r.process_to_string(statement);
1.45 misha 76: const char* statement_cstr=statement_string.untaint_cstr(r.flang, r.connection());
1.43 misha 77:
1.29 paf 78: Void_sql_event_handlers handlers(statement_string);
79: r.connection()->query(
1.33 paf 80: statement_cstr,
81: placeholders_count, placeholders,
1.39 misha 82: 0, SQL_NO_LIMIT,
1.22 paf 83: handlers,
84: statement_string);
1.34 paf 85:
86: if(bind)
87: unmarshal_bind_updates(*bind, placeholders_count, placeholders);
1.1 parser 88: }
89:
90: // constructor
91:
1.48 moko 92: MVoid::MVoid(): Methoded("void", string_class) {
1.41 misha 93: // ^void:sql{query}
1.33 paf 94: add_native_method("sql", Method::CT_STATIC, _sql, 1, 2);
1.32 paf 95:
1.48 moko 96: // all other methods are inherinted from empty string
1.1 parser 97: }
E-mail: