|
|
| version 1.111, 2002/04/24 13:17:13 | version 1.117, 2002/08/15 10:38:18 |
|---|---|
| Line 3 | Line 3 |
| Copyright (c) 2001, 2002 ArtLebedev Group (http://www.artlebedev.com) | Copyright (c) 2001, 2002 ArtLebedev Group (http://www.artlebedev.com) |
| Author: Alexandr Petrosian <paf@design.ru> (http://paf.design.ru) | Author: Alexandr Petrosian <paf@design.ru> (http://paf.design.ru) |
| $Id$ | |
| */ | */ |
| static const char* IDENT_STRING_C="$Date$"; | |
| #include "classes.h" | #include "classes.h" |
| #include "pa_request.h" | #include "pa_request.h" |
| #include "pa_vdouble.h" | #include "pa_vdouble.h" |
| Line 105 static void _mid(Request& r, const Strin | Line 105 static void _mid(Request& r, const Strin |
| Pool& pool=r.pool(); | Pool& pool=r.pool(); |
| const String& string=*r.self->get_string(); | const String& string=*r.self->get_string(); |
| size_t p=(size_t)params->as_int(0, "p must be int", r); | size_t p=(size_t)max(0, params->as_int(0, "p must be int", r)); |
| size_t n=params->size()>1? | size_t n=params->size()>1? |
| (size_t)params->as_int(1, "n must be int", r):string.size(); | (size_t)max(0, params->as_int(1, "n must be int", r)):string.size(); |
| r.write_assign_lang(string.mid(p, p+n)); | r.write_assign_lang(string.mid(p, p+n)); |
| } | } |
| Line 327 const String* sql_result_string(Request& | Line 327 const String* sql_result_string(Request& |
| default_code=0; | default_code=0; |
| if(params->size()>1) { | if(params->size()>1) { |
| Value& voptions=params->as_no_junction(1, "options must be hash, not code"); | Value& voptions=params->as_no_junction(1, "options must be hash, not code"); |
| if(voptions.is_defined()) | if(!voptions.is_string()) |
| if(options=voptions.get_hash(&method_name)) { | if(options=voptions.get_hash(&method_name)) { |
| if(Value *vlimit=(Value *)options->get(*sql_limit_name)) | if(Value *vlimit=(Value *)options->get(*sql_limit_name)) |
| limit=(ulong)r.process_to_value(*vlimit).as_double(); | limit=(ulong)r.process_to_value(*vlimit).as_double(); |
| Line 353 const String* sql_result_string(Request& | Line 353 const String* sql_result_string(Request& |
| const char *statement_cstr= | const char *statement_cstr= |
| statement_string.cstr(String::UL_UNSPECIFIED, r.connection(&method_name)); | statement_string.cstr(String::UL_UNSPECIFIED, r.connection(&method_name)); |
| String_sql_event_handlers handlers(pool, statement_string, statement_cstr); | String_sql_event_handlers handlers(pool, statement_string, statement_cstr); |
| try { | r.connection(&method_name)->query( |
| r.connection(&method_name)->query( | statement_cstr, offset, limit, |
| statement_cstr, offset, limit, | handlers, |
| handlers); | statement_string); |
| } catch(const Exception& e) { // query problem | |
| // give more specific source [were url] | |
| throw Exception("sql.execute", | |
| &statement_string, | |
| "%s", e.comment()); | |
| } | |
| if(!handlers.got_cell) | if(!handlers.got_cell) |
| return 0; // no lines, caller should return second param[default value] | return 0; // no lines, caller should return second param[default value] |
| Line 427 static void _save(Request& r, const Stri | Line 421 static void _save(Request& r, const Stri |
| buf, strlen(buf), true, do_append); | buf, strlen(buf), true, do_append); |
| } | } |
| static void _optimize(Request& r, const String& method_name, MethodParams * /*params*/) { | static void _normalize(Request& r, const String& method_name, MethodParams * /*params*/) { |
| r.write_assign_lang(r.self->get_string()->join_chains(r.pool(), 0/*cstr*/)); | r.write_assign_lang(r.self->get_string()->join_chains(r.pool(), 0/*cstr*/)); |
| } | } |
| Line 481 MString::MString(Pool& apool) : Methoded | Line 475 MString::MString(Pool& apool) : Methoded |
| // ^string.save[file] | // ^string.save[file] |
| add_native_method("save", Method::CT_DYNAMIC, _save, 1, 2); | add_native_method("save", Method::CT_DYNAMIC, _save, 1, 2); |
| // ^string.optimize[] | // ^string.normalize[] |
| add_native_method("optimize", Method::CT_DYNAMIC, _optimize, 0, 0); | add_native_method("normalize", Method::CT_DYNAMIC, _normalize, 0, 0); |
| } | } |
| // global variable | // global variable |