--- parser3/src/classes/void.C 2001/10/19 12:43:30 1.12 +++ parser3/src/classes/void.C 2002/08/20 09:37:31 1.24 @@ -1,12 +1,12 @@ /** @file Parser: @b VOID parser class. - Copyright (c) 2001 ArtLebedev Group (http://www.artlebedev.com) - Author: Alexander Petrosyan (http://design.ru/paf) - - $Id: void.C,v 1.12 2001/10/19 12:43:30 parser Exp $ + Copyright (c) 2001, 2002 ArtLebedev Group (http://www.artlebedev.com) + Author: Alexandr Petrosian (http://paf.design.ru) */ +static const char* IDENT_VOID_C="$Date: 2002/08/20 09:37:31 $"; + #include "classes.h" #include "pa_request.h" #include "pa_vint.h" @@ -14,10 +14,6 @@ #include "pa_vvoid.h" #include "pa_sql_connection.h" -// defines - -#define VOID_CLASS_NAME "void" - // class class MVoid : public Methoded { @@ -29,6 +25,20 @@ public: // Methoded // methods +static void _length(Request& r, const String&, MethodParams *params) { + Pool& pool=r.pool(); + // always zero + r.write_no_lang(*new(pool) VInt(pool, 0)); +} + +static void _pos(Request& r, const String& method_name, MethodParams *params) { + Pool& pool=r.pool(); + + Value& substr=params->as_no_junction(0, "substr must not be code"); + // never found + r.write_assign_lang(*new(pool) VInt(pool, -1)); +} + static void _int(Request& r, const String&, MethodParams *params) { Pool& pool=r.pool(); VVoid *vvoid=static_cast(r.self); @@ -52,7 +62,7 @@ public: void add_column(void *ptr, size_t size) { /* ignore */ } void before_rows() { // there are some result rows, which is wrong - throw Exception(0, 0, + throw Exception("parser.runtime", &statement_string, "must return nothing"); } @@ -67,35 +77,27 @@ private: static void _sql(Request& r, const String& method_name, MethodParams *params) { Pool& pool=r.pool(); - if(!r.connection) - throw Exception(0, 0, - &method_name, - "without connect"); - Value& statement=params->as_junction(0, "statement must be code"); Temp_lang temp_lang(r, String::UL_SQL); - const String& statement_string=r.process(statement).as_string(); + const String& statement_string=r.process_to_string(statement); const char *statement_cstr= - statement_string.cstr(String::UL_UNSPECIFIED, r.connection); + statement_string.cstr(String::UL_UNSPECIFIED, r.connection(&method_name)); Void_sql_event_handlers handlers(pool, statement_string); - try { - r.connection->query( - statement_cstr, 0, 0, - handlers); - } catch(const Exception& e) { - // more specific source [were url] - throw Exception(e.type(), e.code(), - &statement_string, - "%s", e.comment()); - } + r.connection(&method_name)->query( + statement_cstr, 0, 0, + handlers, + statement_string); } // constructor -MVoid::MVoid(Pool& apool) : Methoded(apool) { - set_name(*NEW String(pool(), VOID_CLASS_NAME)); +MVoid::MVoid(Pool& apool) : Methoded(apool, "void") { + // ^void.length[] + add_native_method("length", Method::CT_DYNAMIC, _length, 0, 0); + // ^void.pos[substr] + add_native_method("pos", Method::CT_DYNAMIC, _pos, 1, 1); // ^void.int[] // ^void.int(default)