--- parser3/src/classes/hash.C 2010/11/26 06:40:01 1.109 +++ parser3/src/classes/hash.C 2012/02/28 05:07:44 1.112 @@ -5,7 +5,7 @@ Author: Alexandr Petrosian (http://paf.design.ru) */ -static const char * const IDENT_HASH_C="$Date: 2010/11/26 06:40:01 $"; +static const char * const IDENT="$Id: hash.C,v 1.112 2012/02/28 05:07:44 moko Exp $"; #include "classes.h" #include "pa_vmethod_frame.h" @@ -191,7 +191,7 @@ VBool Hash_sql_event_handlers::only_one_ static void _create_or_add(Request& r, MethodParams& params) { if(params.count()) { - Value& vsrc=params.as_no_junction(0, "param must be hash"); + Value& vsrc=params.as_no_junction(0, PARAM_MUST_BE_HASH); if(HashStringValue* src=vsrc.get_hash()) { VHash& self=GET_SELF(r, VHash); HashStringValue* self_hash=&(self.hash()); @@ -200,22 +200,15 @@ static void _create_or_add(Request& r, M src->for_each(copy_all_overwrite_to, self_hash); if(VHash* vhash_src=static_cast(vsrc.as(VHASH_TYPE))) - { if(Value* vdefault=vhash_src->get_default()) - { if(vdefault->is_defined()) - { self.set_default(vdefault); - } - } - } } } } static void _sub(Request& r, MethodParams& params) { - Value& vsrc=params.as_no_junction(0, "param must be hash"); - if(HashStringValue* src=vsrc.get_hash()) { + if(HashStringValue* src=params.as_no_junction(0, PARAM_MUST_BE_HASH).get_hash()) { HashStringValue* self=&(GET_SELF(r, VHash).hash()); if(src==self) { // same: clearing self->clear(); @@ -235,8 +228,7 @@ static void _union(Request& r, MethodPar // dest = copy of self Value& result=*new VHash(GET_SELF(r, VHash).hash()); // dest += b - Value& vsrc=params.as_no_junction(0, "param must be hash"); - if(HashStringValue* src=vsrc.get_hash()) + if(HashStringValue* src=params.as_no_junction(0, PARAM_MUST_BE_HASH).get_hash()) src->for_each(copy_all_dontoverwrite_to, result.get_hash()); // return result @@ -259,8 +251,7 @@ static void copy_intersection_to( static void _intersection(Request& r, MethodParams& params) { Value& result=*new VHash; // dest += b - Value& vb=params.as_no_junction(0, "param must be hash"); - if(HashStringValue* b=vb.get_hash()) { + if(HashStringValue* b=params.as_no_junction(0, PARAM_MUST_BE_HASH).get_hash()) { Copy_intersection_to_info info={b, result.get_hash()}; GET_SELF(r, VHash).hash().for_each(copy_intersection_to, &info); } @@ -279,8 +270,7 @@ static bool intersects( static void _intersects(Request& r, MethodParams& params) { bool result=false; - Value& vb=params.as_no_junction(0, "param must be hash"); - if(HashStringValue* b=vb.get_hash()) + if(HashStringValue* b=params.as_no_junction(0, PARAM_MUST_BE_HASH).get_hash()) result=GET_SELF(r, VHash).hash().first_that(intersects, b)!=0; // return result @@ -306,36 +296,32 @@ static void _sql(Request& r, MethodParam ulong offset=0; bool distinct=false; Table2hash_value_type value_type=C_HASH; - if(params.count()>1) { - Value& voptions=params.as_no_junction(1, "options must be hash, not code"); - if(voptions.is_defined() && !voptions.is_string()) - if(HashStringValue* options=voptions.get_hash()) { - int valid_options=0; - if(Value* vbind=options->get(sql_bind_name)) { - valid_options++; - bind=vbind->get_hash(); - } - if(Value* vlimit=options->get(sql_limit_name)) { - valid_options++; - limit=(ulong)r.process_to_value(*vlimit).as_double(); - } - if(Value* voffset=options->get(sql_offset_name)) { - valid_options++; - offset=(ulong)r.process_to_value(*voffset).as_double(); - } - if(Value* vdistinct=options->get(sql_distinct_name)) { - valid_options++; - distinct=r.process_to_value(*vdistinct).as_bool(); - } - if(Value* vvalue_type=options->get(sql_value_type_name)) { - valid_options++; - value_type=get_value_type(r.process_to_value(*vvalue_type)); - } - if(valid_options!=options->count()) - throw Exception(PARSER_RUNTIME, 0, CALLED_WITH_INVALID_OPTION); - } else - throw Exception(PARSER_RUNTIME, 0, OPTIONS_MUST_BE_HASH); - } + if(params.count()>1) + if(HashStringValue* options=params.as_hash(1)) { + int valid_options=0; + if(Value* vbind=options->get(sql_bind_name)) { + valid_options++; + bind=vbind->get_hash(); + } + if(Value* vlimit=options->get(sql_limit_name)) { + valid_options++; + limit=(ulong)r.process_to_value(*vlimit).as_double(); + } + if(Value* voffset=options->get(sql_offset_name)) { + valid_options++; + offset=(ulong)r.process_to_value(*voffset).as_double(); + } + if(Value* vdistinct=options->get(sql_distinct_name)) { + valid_options++; + distinct=r.process_to_value(*vdistinct).as_bool(); + } + if(Value* vvalue_type=options->get(sql_value_type_name)) { + valid_options++; + value_type=get_value_type(r.process_to_value(*vvalue_type)); + } + if(valid_options!=options->count()) + throw Exception(PARSER_RUNTIME, 0, CALLED_WITH_INVALID_OPTION); + } SQL_Driver::Placeholder* placeholders=0; uint placeholders_count=0;