Annotation of parser3/src/classes/void.C, revision 1.58
1.1 parser 1: /** @file
2: Parser: @b VOID parser class.
3:
1.58 ! moko 4: Copyright (c) 2001-2020 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.58 ! moko 15: volatile const char * IDENT_VOID_C="$Id: void.C,v 1.57 2019/09/11 15:26:09 moko Exp $";
1.33 paf 16:
1.1 parser 17: // class
18:
1.29 paf 19: class MVoid: public Methoded {
1.1 parser 20: public:
1.29 paf 21: MVoid();
1.1 parser 22: };
23:
1.48 moko 24: // void is inherited from string, thus global variable declared in string.C
1.29 paf 25:
1.1 parser 26: // methods
27:
1.5 parser 28: #ifndef DOXYGEN
1.26 paf 29: class Void_sql_event_handlers: public SQL_Driver_query_event_handlers {
1.5 parser 30: public:
1.29 paf 31: bool add_column(SQL_Error& /*error*/, const char* /*str*/, size_t /*length*/) { /* ignore */ return false; }
1.27 paf 32: bool before_rows(SQL_Error& error) {
1.5 parser 33: // there are some result rows, which is wrong
1.57 moko 34: error=SQL_Error("must return nothing");
1.27 paf 35: return true;
1.5 parser 36: }
1.27 paf 37: bool add_row(SQL_Error& /*error*/) { /* never */ return false; }
1.29 paf 38: bool add_row_cell(SQL_Error& /*error*/, const char* /*str*/, size_t /*length*/) { /* never */ return false; }
1.5 parser 39:
40: };
41: #endif
1.34 paf 42:
43: extern int marshal_binds(HashStringValue& hash, SQL_Driver::Placeholder*& placeholders);
44: extern void unmarshal_bind_updates(HashStringValue& hash, int placeholder_count, SQL_Driver::Placeholder* placeholders);
45:
1.29 paf 46: static void _sql(Request& r, MethodParams& params) {
47: Value& statement=params.as_junction(0, "statement must be code");
1.1 parser 48:
1.33 paf 49: HashStringValue* bind=0;
1.49 misha 50: if(params.count()>1)
1.51 misha 51: if(HashStringValue* options=params.as_hash(1, "sql options")) {
1.49 misha 52: int valid_options=0;
53: if(Value* vbind=options->get(sql_bind_name)) {
54: valid_options++;
55: bind=vbind->get_hash();
56: }
57: if(valid_options!=options->count())
58: throw Exception(PARSER_RUNTIME, 0, CALLED_WITH_INVALID_OPTION);
59: }
1.33 paf 60:
61: SQL_Driver::Placeholder* placeholders=0;
62: uint placeholders_count=0;
63: if(bind)
64: placeholders_count=marshal_binds(*bind, placeholders);
65:
1.18 paf 66: const String& statement_string=r.process_to_string(statement);
1.54 moko 67: const char* statement_cstr=statement_string.untaint_cstr(String::L_SQL, r.connection());
1.43 misha 68:
1.57 moko 69: Void_sql_event_handlers handlers;
70: r.connection()->query(statement_cstr, placeholders_count, placeholders, 0, SQL_NO_LIMIT, handlers, statement_string);
1.34 paf 71:
72: if(bind)
73: unmarshal_bind_updates(*bind, placeholders_count, placeholders);
1.1 parser 74: }
75:
76: // constructor
77:
1.53 moko 78: MVoid::MVoid(): Methoded("void") {
79: set_base(string_class);
80:
1.41 misha 81: // ^void:sql{query}
1.33 paf 82: add_native_method("sql", Method::CT_STATIC, _sql, 1, 2);
1.32 paf 83:
1.48 moko 84: // all other methods are inherinted from empty string
1.1 parser 85: }
E-mail: