--- parser3/src/classes/hash.C 2008/05/29 09:26:34 1.86 +++ parser3/src/classes/hash.C 2009/05/14 08:10:09 1.93 @@ -1,11 +1,11 @@ /** @file Parser: @b hash parser class. - Copyright (c) 2001-2005 ArtLebedev Group (http://www.artlebedev.com) + Copyright (c) 2001-2009 ArtLebedev Group (http://www.artlebedev.com) Author: Alexandr Petrosian (http://paf.design.ru) */ -static const char * const IDENT_HASH_C="$Date: 2008/05/29 09:26:34 $"; +static const char * const IDENT_HASH_C="$Date: 2009/05/14 08:10:09 $"; #include "classes.h" #include "pa_vmethod_frame.h" @@ -74,9 +74,9 @@ public: empty(0) { } - bool add_column(SQL_Error& error, const char* str, size_t length) { + bool add_column(SQL_Error& error, const char* str, size_t) { try { - columns+=new String(str, length, true); + columns+=new String(str, String::L_TAINTED); return false; } catch(...) { error=SQL_Error("exception occured in Hash_sql_event_handlers::add_column"); @@ -113,11 +113,9 @@ public: return false; } - bool add_row_cell(SQL_Error& error, const char *ptr, size_t length) { + bool add_row_cell(SQL_Error& error, const char *ptr, size_t) { try { - String& cell=*new String; - if(length) - cell.append_know_length(ptr, length, String::L_TAINTED); + String& cell=*new String(ptr, String::L_TAINTED); bool duplicate=false; if(one_bool_column) { @@ -292,7 +290,7 @@ static void _intersects(Request& r, Meth result=GET_SELF(r, VHash).hash().first_that(intersects, b)!=0; // return result - r.write_no_lang(*new VBool(result)); + r.write_no_lang(VBool::get(result)); } @@ -310,7 +308,7 @@ static void _sql(Request& r, MethodParam Value& statement=params.as_junction(0, "statement must be code"); HashStringValue* bind=0; - ulong limit=0; + ulong limit=SQL_NO_LIMIT; ulong offset=0; bool distinct=false; Table2hash_value_type value_type=C_HASH; @@ -365,6 +363,7 @@ static void _sql(Request& r, MethodParam distinct, hash, value_type); + r.connection()->query( statement_cstr, placeholders_count, placeholders, @@ -410,9 +409,8 @@ static void _delete(Request& r, MethodPa } static void _contains(Request& r, MethodParams& params) { - - bool result = GET_SELF(r, VHash).hash().contains(params.as_string(0, "key must be string")); - r.write_no_lang(*new VBool(result)); + bool result=GET_SELF(r, VHash).hash().contains(params.as_string(0, "key must be string")); + r.write_no_lang(VBool::get(result)); } #ifndef DOXYGEN @@ -428,10 +426,10 @@ struct Foreach_info { bool need_delim; }; #endif -static bool one_foreach_cycle( - HashStringValue::key_type akey, - HashStringValue::value_type avalue, - Foreach_info *info) { +static bool one_foreach_cycle( + HashStringValue::key_type akey, + HashStringValue::value_type avalue, + Foreach_info *info) { Value& var_context=*info->var_context; if(info->key_var_name){ info->vkey->set_string(*new String(akey, String::L_TAINTED)); @@ -440,20 +438,24 @@ static bool one_foreach_cycle( if(info->value_var_name) var_context.put_element(var_context, *info->value_var_name, avalue, false); - StringOrValue sv_processed=info->r->process(*info->body_code); - Request::Skip lskip=info->r->get_skip(); info->r->set_skip(Request::SKIP_NOTHING); - - const String* s_processed=sv_processed.get_string(); - if(info->delim_maybe_code && s_processed && s_processed->length()) { // delimiter set and we have body - if(info->need_delim) // need delim & iteration produced string? - info->r->write_pass_lang(info->r->process(*info->delim_maybe_code)); - else - info->need_delim=true; + if(info->delim_maybe_code){ // delimiter set + StringOrValue sv_processed=info->r->process(*info->body_code); + Request::Skip lskip=info->r->get_skip(); info->r->set_skip(Request::SKIP_NOTHING); + + const String* s_processed=sv_processed.get_string(); + if(s_processed && !s_processed->is_empty()) { // we have body + if(info->need_delim) // need delim & iteration produced string? + info->r->write_pass_lang(info->r->process(*info->delim_maybe_code)); + else + info->need_delim=true; + } + info->r->write_pass_lang(sv_processed); + return lskip==Request::SKIP_BREAK; + } else { + info->r->process_write(*info->body_code); + Request::Skip lskip=info->r->get_skip(); info->r->set_skip(Request::SKIP_NOTHING); + return lskip==Request::SKIP_BREAK; } - - info->r->write_pass_lang(sv_processed); - - return lskip==Request::SKIP_BREAK; } static void _foreach(Request& r, MethodParams& params) { Temp_hash_value