--- parser3/src/classes/table.C 2001/08/21 11:12:20 1.105 +++ parser3/src/classes/table.C 2001/09/07 12:46:19 1.111 @@ -5,7 +5,7 @@ Author: Alexander Petrosyan (http://design.ru/paf) */ -static const char *RCSId="$Id: table.C,v 1.105 2001/08/21 11:12:20 parser Exp $"; +static const char *RCSId="$Id: table.C,v 1.111 2001/09/07 12:46:19 parser Exp $"; #include "classes.h" #include "pa_config_includes.h" @@ -80,11 +80,11 @@ static void _set(Request& r, const Strin static void _load(Request& r, const String& method_name, MethodParams *params) { Pool& pool=r.pool(); // filename is last parameter - Value& vfilename=params->as_no_junction(params->size()-1, + const String& filename=params->as_string(params->size()-1, "file name must not be code"); // loading text - char *data=file_read_text(pool, r.absolute(vfilename.as_string())); + char *data=file_read_text(pool, r.absolute(filename)); // parse columns Array *columns; @@ -118,7 +118,9 @@ static void _load(Request& r, const Stri cell->APPEND_TAINTED(cell_chars, 0, file, line); *row+=cell; } +#ifndef NO_STRING_ORIGIN line++; +#endif table+=row; }; @@ -152,7 +154,7 @@ static Table *fill_month_days(Request& r for(int wday=0; wday<7; wday++, _day++) { String *cell=new(pool) String(pool); if(_day>=1 && _day<=monthDays) { - char *buf=(char *)malloc(2+1); + char *buf=(char *)pool.malloc(2+1); cell->APPEND_CLEAN(buf, sprintf(buf, "%02d", _day), method_name.origin().file, method_name.origin().line); } @@ -196,7 +198,7 @@ static Table *fill_week_days(Request& r, tm *tmOut=localtime(&t); Array& row=*new(pool) Array(pool, 4); #define WDFILL(size, value) { \ - char *buf=(char *)malloc(size+1); \ + char *buf=(char *)pool.malloc(size+1); \ String *cell=new(pool) String(pool); \ cell->APPEND_CLEAN(buf, sprintf(buf, "%0"#size"d", value), \ method_name.origin().file, \ @@ -261,7 +263,7 @@ static void _save(Request& r, const Stri } else { // nameless table if(int lsize=table.size()?static_cast(table.get(0))->size():0) for(int column=0; column(value); Row_info& ri=*static_cast(info); @@ -408,7 +411,7 @@ static void _hash(Request& r, const Stri r.write_no_lang(result); } -/// used by table: _sort / sort_cmp_string|sort_cmp_double +#ifndef DOXYGEN struct Table_seq_item { Array *row; union { @@ -416,6 +419,7 @@ struct Table_seq_item { double d; } value; }; +#endif static int sort_cmp_string(const void *a, const void *b) { return strcmp( static_cast(a)->value.c_str, @@ -615,16 +619,17 @@ static void _sql(Request& r, const Strin ulong limit=0; ulong offset=0; if(params->size()>1) { - Value& options_param=params->as_no_junction(1, "options must be hash, not code"); - if(Hash *options=options_param.get_hash()) { - if(Value *vlimit=(Value *)options->get(*sql_limit_name)) - limit=(ulong)r.process(*vlimit).as_double(); - if(Value *voffset=(Value *)options->get(*sql_offset_name)) - offset=(ulong)r.process(*voffset).as_double(); - } else - PTHROW(0, 0, - &method_name, - "options must be hash"); + Value& voptions=params->as_no_junction(1, "options must be hash, not code"); + if(voptions.is_defined()) + if(Hash *options=voptions.get_hash()) { + if(Value *vlimit=(Value *)options->get(*sql_limit_name)) + limit=(ulong)r.process(*vlimit).as_double(); + if(Value *voffset=(Value *)options->get(*sql_offset_name)) + offset=(ulong)r.process(*voffset).as_double(); + } else + PTHROW(0, 0, + &method_name, + "options must be hash"); } Temp_lang temp_lang(r, String::UL_SQL); @@ -634,7 +639,7 @@ static void _sql(Request& r, const Strin Table_sql_event_handlers handlers(pool, method_name, statement_string, statement_cstr); bool need_rethrow=false; Exception rethrow_me; - PTRY { + PTRY { r.connection->query( statement_cstr, offset, limit, handlers);