--- parser3/src/classes/void.C 2007/02/03 18:08:38 1.37 +++ parser3/src/classes/void.C 2008/09/04 13:15:36 1.41 @@ -5,7 +5,7 @@ Author: Alexandr Petrosian (http://paf.design.ru) */ -static const char * const IDENT_VOID_C="$Date: 2007/02/03 18:08:38 $"; +static const char * const IDENT_VOID_C="$Date: 2008/09/04 13:15:36 $"; #include "classes.h" #include "pa_vmethod_frame.h" @@ -44,6 +44,13 @@ static void _length(Request& r, MethodPa static void _pos(Request& r, MethodParams& params) { // just checking for consistency params.as_no_junction(0, "substr must not be code"); + if(params.count()>1){ + ssize_t offset=params.as_int(1, "n must be int", r); + if(offset<0) + throw Exception(PARSER_RUNTIME, + 0, + "n(%d) must be >=0", offset); + } // never found r.write_no_lang(*new VInt(-1)); } @@ -74,7 +81,7 @@ public: bool add_column(SQL_Error& /*error*/, const char* /*str*/, size_t /*length*/) { /* ignore */ return false; } bool before_rows(SQL_Error& error) { // there are some result rows, which is wrong - error=SQL_Error("parser.runtime", + error=SQL_Error(PARSER_RUNTIME, /*statement_string,*/ "must return nothing"); return true; @@ -102,11 +109,11 @@ static void _sql(Request& r, MethodParam bind=vbind->get_hash(); } if(valid_options!=options->count()) - throw Exception("parser.runtime", + throw Exception(PARSER_RUNTIME, 0, "called with invalid option"); } else - throw Exception("parser.runtime", + throw Exception(PARSER_RUNTIME, 0, "options must be hash"); } @@ -124,7 +131,7 @@ static void _sql(Request& r, MethodParam r.connection()->query( statement_cstr, placeholders_count, placeholders, - 0, 0, + 0, SQL_NO_LIMIT, handlers, statement_string); @@ -135,7 +142,7 @@ static void _sql(Request& r, MethodParam static void _left_right(Request& r, MethodParams& params) { ssize_t sn=params.as_int(0, "n must be int", r); if(sn<0) - throw Exception("parser.runtime", + throw Exception(PARSER_RUNTIME, 0, "n(%d) must be >=0", sn); @@ -145,14 +152,14 @@ static void _left_right(Request& r, Meth static void _mid(Request& r, MethodParams& params) { ssize_t sbegin=params.as_int(0, "p must be int", r); if(sbegin<0) - throw Exception("parser.runtime", + throw Exception(PARSER_RUNTIME, 0, "p(%d) must be >=0", sbegin); if(params.count()>1) { ssize_t sn=params.as_int(1, "n must be int", r); if(sn<0) - throw Exception("parser.runtime", + throw Exception(PARSER_RUNTIME, 0, "n(%d) must be >=0", sn); } @@ -167,7 +174,8 @@ MVoid::MVoid(): Methoded("void") { add_native_method("length", Method::CT_DYNAMIC, _length, 0, 0); // ^void.pos[substr] - add_native_method("pos", Method::CT_DYNAMIC, _pos, 1, 1); + // ^void.pos[substr](n) + add_native_method("pos", Method::CT_DYNAMIC, _pos, 1, 2); // ^void.int[] // ^void.int(default) @@ -181,7 +189,7 @@ MVoid::MVoid(): Methoded("void") { // ^void.bool(default) add_native_method("bool", Method::CT_DYNAMIC, _bool, 0, 1); - // ^sql[query] + // ^void:sql{query} add_native_method("sql", Method::CT_STATIC, _sql, 1, 2); // ^void.left() ^void.right()