--- parser3/src/classes/table.C 2001/10/09 13:17:45 1.124 +++ parser3/src/classes/table.C 2001/10/31 14:08:36 1.129 @@ -4,7 +4,7 @@ Copyright (c) 2001 ArtLebedev Group (http://www.artlebedev.com) Author: Alexander Petrosyan (http://design.ru/paf) - $Id: table.C,v 1.124 2001/10/09 13:17:45 parser Exp $ + $Id: table.C,v 1.129 2001/10/31 14:08:36 paf Exp $ */ #include "classes.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, + Value& vfile_name=params->as_no_junction(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(vfile_name.as_string())); // parse columns Array *columns; @@ -129,15 +129,17 @@ static void _load(Request& r, const Stri static_cast(r.self)->set_table(table); } +/// @todo "z\nz" "zzz""zz" static void _save(Request& r, const String& method_name, MethodParams *params) { Pool& pool=r.pool(); - Value& vtable_name=params->as_no_junction(params->size()-1, + Value& vfile_name=params->as_no_junction(params->size()-1, "file name must not be code"); Table& table=static_cast(r.self)->table(); + bool do_append=false; String sdata(pool); - if(params->size()==1) { // not nameless=named output + if(params->size()==1) { // named output // write out names line if(table.columns()) { // named table Array_iter i(*table.columns()); @@ -158,6 +160,17 @@ static void _save(Request& r, const Stri sdata.APPEND_CONST("empty nameless table"); } sdata.APPEND_CONST("\n"); + } else { // mode specified + const String& mode=params->as_string(0, "mode must be string"); + if(mode=="append") + do_append=true; + else if(mode=="nameless") + /*ok, already skipped names output*/; + else + throw Exception(0, 0, + &mode, + "unknown mode, must be 'append'"); + } // data lines Array_iter i(table); @@ -173,8 +186,8 @@ static void _save(Request& r, const Stri } // write - file_write(pool, r.absolute(vtable_name.as_string()), - sdata.cstr(), sdata.size(), true); + file_write(pool, r.absolute(vfile_name.as_string()), + sdata.cstr(), sdata.size(), true, do_append); } static void _count(Request& r, const String& method_name, MethodParams *) { @@ -244,7 +257,7 @@ static void table_row_to_hash(Array::Ite if(ri.key_fieldsize(); i++) { int value_field=ri.value_fields->get_int(i); if(value_fieldas_no_junction(0, "table ref must not be code").get_table(); if(!maybe_src) - PTHROW(0, 0, + throw Exception(0, 0, &method_name, "source is not a table"); Table& src=*maybe_src; Table& dest=static_cast(r.self)->table(); if(&src == &dest) - PTHROW(0, 0, + throw Exception(0, 0, &method_name, "source and destination are same table"); @@ -496,7 +509,7 @@ static void _sql(Request& r, const Strin Pool& pool=r.pool(); if(!r.connection) - PTHROW(0, 0, + throw Exception(0, 0, &method_name, "without connect"); @@ -507,13 +520,13 @@ static void _sql(Request& r, const Strin if(params->size()>1) { Value& voptions=params->as_no_junction(1, "options must be hash, not code"); if(voptions.is_defined()) - if(Hash *options=voptions.get_hash()) { + if(Hash *options=voptions.get_hash(&method_name)) { 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, + throw Exception(0, 0, &method_name, "options must be hash"); } @@ -524,20 +537,16 @@ static void _sql(Request& r, const Strin statement_string.cstr(String::UL_UNSPECIFIED, r.connection); Table_sql_event_handlers handlers(pool, method_name, statement_string, statement_cstr); - bool need_rethrow=false; Exception rethrow_me; - PTRY { + try { r.connection->query( statement_cstr, offset, limit, handlers); + } catch(const Exception& e) { // query problem + // more specific source [were url] + throw Exception(e.type(), e.code(), + &statement_string, + "%s", e.comment()); } - PCATCH(e) { // query problem - rethrow_me=e; need_rethrow=true; - } - PEND_CATCH - if(need_rethrow) - PTHROW(rethrow_me.type(), rethrow_me.code(), - &statement_string, // setting more specific source [were url] - rethrow_me.comment()); Table *result= handlers.table?handlers.table: // query resulted in table? return it