--- parser3/src/classes/void.C 2002/04/18 10:51:00 1.19 +++ parser3/src/classes/void.C 2003/01/21 15:51:08 1.28 @@ -1,12 +1,12 @@ /** @file Parser: @b VOID parser class. - Copyright (c) 2001, 2002 ArtLebedev Group (http://www.artlebedev.com) + Copyright (c) 2001, 2003 ArtLebedev Group (http://www.artlebedev.com) Author: Alexandr Petrosian (http://paf.design.ru) - - $Id: void.C,v 1.19 2002/04/18 10:51:00 paf Exp $ */ +static const char* IDENT_VOID_C="$Date: 2003/01/21 15:51:08 $"; + #include "classes.h" #include "pa_request.h" #include "pa_vint.h" @@ -25,35 +25,50 @@ 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); + VVoid *vvoid=static_cast(r.get_self()); r.write_no_lang(*new(pool) VInt(pool, params->size()==0?vvoid->as_int():params->as_int(0, "default must be int", r))); } static void _double(Request& r, const String&, MethodParams *params) { Pool& pool=r.pool(); - VVoid *vvoid=static_cast(r.self); + VVoid *vvoid=static_cast(r.get_self()); r.write_no_lang(*new(pool) VDouble(pool, params->size()==0?vvoid->as_double():params->as_double(0, "default must be double", r))); } #ifndef DOXYGEN -class Void_sql_event_handlers : public SQL_Driver_query_event_handlers { +class Void_sql_event_handlers: public SQL_Driver_query_event_handlers { public: Void_sql_event_handlers(Pool& apool, const String& astatement_string) : pool(apool), statement_string(astatement_string) { } - void add_column(void *ptr, size_t size) { /* ignore */ } - void before_rows() { + bool add_column(SQL_Error& /*error*/, void *ptr, size_t size) { /* ignore */ return false; } + bool before_rows(SQL_Error& error) { // there are some result rows, which is wrong - throw Exception("parser.runtime", + error=SQL_Error("parser.runtime", &statement_string, "must return nothing"); + return true; } - void add_row() { /* never */ } - void add_row_cell(void *ptr, size_t size) { /* never */ } + bool add_row(SQL_Error& /*error*/) { /* never */ return false; } + bool add_row_cell(SQL_Error& /*error*/, void *ptr, size_t size) { /* never */ return false; } private: Pool& pool; @@ -70,21 +85,21 @@ static void _sql(Request& r, const Strin const char *statement_cstr= statement_string.cstr(String::UL_UNSPECIFIED, r.connection(&method_name)); Void_sql_event_handlers handlers(pool, statement_string); - try { - r.connection(&method_name)->query( - statement_cstr, 0, 0, - handlers); - } catch(const Exception& e) { - // more specific source [were url] - throw Exception("sql.execute", - &statement_string, - "%s", e.comment()); - } + r.connection(&method_name)->query( + statement_cstr, 0, 0, + handlers, + statement_string); } // constructor 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) add_native_method("int", Method::CT_DYNAMIC, _int, 0, 1);