|
|
| version 1.48, 2010/10/21 15:25:07 | version 1.60, 2024/11/04 03:53:25 |
|---|---|
| Line 1 | Line 1 |
| /** @file | /** @file |
| Parser: @b VOID parser class. | Parser: @b VOID parser class. |
| Copyright (c) 2001-2009 ArtLebedev Group (http://www.artlebedev.com) | Copyright (c) 2001-2024 Art. Lebedev Studio (http://www.artlebedev.com) |
| Author: Alexandr Petrosian <paf@design.ru> (http://paf.design.ru) | Authors: Konstantin Morshnev <moko@design.ru>, Alexandr Petrosian <paf@design.ru> |
| */ | */ |
| static const char * const IDENT_VOID_C="$Date$"; | |
| #include "classes.h" | #include "classes.h" |
| #include "pa_vmethod_frame.h" | #include "pa_vmethod_frame.h" |
| Line 14 static const char * const IDENT_VOID_C=" | Line 12 static const char * const IDENT_VOID_C=" |
| #include "pa_vvoid.h" | #include "pa_vvoid.h" |
| #include "pa_sql_connection.h" | #include "pa_sql_connection.h" |
| // externs | volatile const char * IDENT_VOID_C="$Id$"; |
| extern String sql_bind_name; | |
| // class | // class |
| Line 31 public: | Line 27 public: |
| #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 { |
| const String& statement_string; | |
| public: | public: |
| Void_sql_event_handlers(const String& astatement_string): statement_string(astatement_string) {} | |
| bool add_column(SQL_Error& /*error*/, const char* /*str*/, size_t /*length*/) { /* ignore */ return false; } | bool add_column(SQL_Error& /*error*/, const char* /*str*/, size_t /*length*/) { /* ignore */ return false; } |
| bool before_rows(SQL_Error& error) { | bool before_rows(SQL_Error& error) { |
| // there are some result rows, which is wrong | // there are some result rows, which is wrong |
| error=SQL_Error(PARSER_RUNTIME, | error=SQL_Error("must return nothing"); |
| /*statement_string,*/ | |
| "must return nothing"); | |
| return true; | return true; |
| } | } |
| bool add_row(SQL_Error& /*error*/) { /* never */ return false; } | bool add_row(SQL_Error& /*error*/) { /* never */ return false; } |
| Line 55 static void _sql(Request& r, MethodParam | Line 47 static void _sql(Request& r, MethodParam |
| Value& statement=params.as_junction(0, "statement must be code"); | Value& statement=params.as_junction(0, "statement must be code"); |
| HashStringValue* bind=0; | HashStringValue* bind=0; |
| if(params.count()>1) { | if(params.count()>1) |
| Value& voptions=params.as_no_junction(1, "options must be hash, not code"); | if(HashStringValue* options=params.as_hash(1, "sql options")) { |
| if(voptions.is_defined() && !voptions.is_string()) | int valid_options=0; |
| if(HashStringValue* options=voptions.get_hash()) { | if(Value* vbind=options->get(sql_bind_name)) { |
| int valid_options=0; | valid_options++; |
| if(Value* vbind=options->get(sql_bind_name)) { | bind=vbind->get_hash(); |
| valid_options++; | } |
| bind=vbind->get_hash(); | if(valid_options!=options->count()) |
| } | throw Exception(PARSER_RUNTIME, 0, CALLED_WITH_INVALID_OPTION); |
| 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; | SQL_Driver::Placeholder* placeholders=0; |
| uint placeholders_count=0; | uint placeholders_count=0; |
| if(bind) | if(bind) |
| placeholders_count=marshal_binds(*bind, placeholders); | placeholders_count=marshal_binds(*bind, placeholders); |
| 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=statement_string.untaint_cstr(r.flang, r.connection()); | const char* statement_cstr=statement_string.untaint_cstr(String::L_SQL, r.connection()); |
| Void_sql_event_handlers handlers(statement_string); | Void_sql_event_handlers handlers; |
| r.connection()->query( | r.connection()->query(statement_cstr, placeholders_count, placeholders, 0, SQL_NO_LIMIT, handlers, statement_string); |
| statement_cstr, | |
| placeholders_count, placeholders, | |
| 0, SQL_NO_LIMIT, | |
| handlers, | |
| statement_string); | |
| if(bind) | if(bind) |
| unmarshal_bind_updates(*bind, placeholders_count, placeholders); | unmarshal_bind_updates(*bind, placeholders_count, placeholders); |
| Line 93 static void _sql(Request& r, MethodParam | Line 75 static void _sql(Request& r, MethodParam |
| // constructor | // constructor |
| MVoid::MVoid(): Methoded("void", string_class) { | MVoid::MVoid(): Methoded("void") { |
| set_base(string_class); | |
| // ^void: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); |