--- parser3/src/classes/void.C 2004/03/02 16:55:28 1.32 +++ parser3/src/classes/void.C 2004/06/22 14:12:57 1.34 @@ -5,7 +5,7 @@ Author: Alexandr Petrosian (http://paf.design.ru) */ -static const char * const IDENT_VOID_C="$Date: 2004/03/02 16:55:28 $"; +static const char * const IDENT_VOID_C="$Date: 2004/06/22 14:12:57 $"; #include "classes.h" #include "pa_vmethod_frame.h" @@ -16,6 +16,10 @@ static const char * const IDENT_VOID_C=" #include "pa_vvoid.h" #include "pa_sql_connection.h" +// externs + +extern String sql_bind_name; + // class class MVoid: public Methoded { @@ -73,18 +77,52 @@ public: }; #endif + +extern int marshal_binds(HashStringValue& hash, SQL_Driver::Placeholder*& placeholders); +extern void unmarshal_bind_updates(HashStringValue& hash, int placeholder_count, SQL_Driver::Placeholder* placeholders); + static void _sql(Request& r, MethodParams& params) { Value& statement=params.as_junction(0, "statement must be code"); + HashStringValue* bind=0; + if(params.count()>1) { + Value& voptions=params.as_no_junction(1, "options must be hash, not code"); + if(!voptions.is_string()) + if(HashStringValue* options=voptions.get_hash()) { + int valid_options=0; + if(Value* vbind=options->get(sql_bind_name)) { + valid_options++; + bind=vbind->get_hash(); + } + if(valid_options!=options->count()) + throw Exception("parser.runtime", + 0, + "called with invalid option"); + } else + throw Exception("parser.runtime", + 0, + "options must be hash"); + } + + SQL_Driver::Placeholder* placeholders=0; + uint placeholders_count=0; + if(bind) + placeholders_count=marshal_binds(*bind, placeholders); + Temp_lang temp_lang(r, String::L_SQL); const String& statement_string=r.process_to_string(statement); const char* statement_cstr= statement_string.cstr(String::L_UNSPECIFIED, r.connection()); Void_sql_event_handlers handlers(statement_string); r.connection()->query( - statement_cstr, 0, 0, + statement_cstr, + placeholders_count, placeholders, + 0, 0, handlers, statement_string); + + if(bind) + unmarshal_bind_updates(*bind, placeholders_count, placeholders); } static void _left_right(Request& r, MethodParams& params) { @@ -133,7 +171,7 @@ MVoid::MVoid(): Methoded("void") { add_native_method("double", Method::CT_DYNAMIC, _double, 0, 1); // ^sql[query] - add_native_method("sql", Method::CT_STATIC, _sql, 1, 1); + add_native_method("sql", Method::CT_STATIC, _sql, 1, 2); // ^void.left() ^void.right() add_native_method("left", Method::CT_DYNAMIC, _left_right, 1, 1);