--- parser3/src/classes/table.C 2001/07/09 16:13:17 1.92 +++ parser3/src/classes/table.C 2001/07/23 11:19:25 1.94 @@ -5,7 +5,7 @@ Author: Alexander Petrosyan (http://design.ru/paf) */ -static const char *RCSId="$Id: table.C,v 1.92 2001/07/09 16:13:17 parser Exp $"; +static const char *RCSId="$Id: table.C,v 1.94 2001/07/23 11:19:25 parser Exp $"; #include "pa_config_includes.h" @@ -154,13 +154,12 @@ static Table *fill_month_days(Request& r for(int _day=1-weekDay1; _day<=monthDays;) { Array& row=*new(pool) Array(pool, 7); for(int wday=0; wday<7; wday++, _day++) { - String *cell; + String *cell=new(pool) String(pool); if(_day>=1 && _day<=monthDays) { char *buf=(char *)malloc(2+1); - sprintf(buf, "%02d", _day); - cell=new(pool) String(pool, buf); - } else - cell=new(pool) String(pool); + cell->APPEND_CLEAN(buf, sprintf(buf, "%02d", _day), + method_name.origin().file, method_name.origin().line); + } row+=cell; } *result+=&row; @@ -200,10 +199,18 @@ static Table *fill_week_days(Request& r, for(int curWeekDay=0; curWeekDay<7; curWeekDay++, t+=SECS_PER_DAY) { tm *tmOut=localtime(&t); Array& row=*new(pool) Array(pool, 4); - {char *buf=(char *)malloc(4+1); sprintf(buf, "%04d", 1900+tmOut->tm_year); row+=new(pool) String(pool, buf);} - {char *buf=(char *)malloc(2+1); sprintf(buf, "%02d", 1+tmOut->tm_mon); row+=new(pool) String(pool, buf);} - {char *buf=(char *)malloc(2+1); sprintf(buf, "%02d", tmOut->tm_mday); row+=new(pool) String(pool, buf);} - {char *buf=(char *)malloc(2+1); sprintf(buf, "%02d", tmOut->tm_wday); row+=new(pool) String(pool, buf);} +#define WDFILL(size, value) { \ + char *buf=(char *)malloc(size+1); \ + String *cell=new(pool) String(pool); \ + cell->APPEND_CLEAN(buf, sprintf(buf, "%0"#size"d", value), \ + method_name.origin().file, \ + method_name.origin().line); \ + row+=cell; \ + } + WDFILL(4, 1900+tmOut->tm_year); + WDFILL(2, 1+tmOut->tm_mon); + WDFILL(2, tmOut->tm_mday); + WDFILL(2, tmOut->tm_wday); *result+=&row; } @@ -284,15 +291,17 @@ static void _save(Request& r, const Stri sdata.cstr(), sdata.size(), true); } -static void _count(Request& r, const String&, MethodParams *) { +static void _count(Request& r, const String& method_name, MethodParams *) { Pool& pool=r.pool(); Value& value=*new(pool) VInt(pool, static_cast(r.self)->table().size()); + value.set_name(method_name); r.write_no_lang(value); } static void _line(Request& r, const String& method_name, MethodParams *) { Pool& pool=r.pool(); Value& value=*new(pool) VInt(pool, 1+static_cast(r.self)->table().current()); + value.set_name(method_name); r.write_no_lang(value); } @@ -304,6 +313,7 @@ static void _offset(Request& r, const St table.shift(r.process(offset_expr).as_int()); } else { Value& value=*new(pool) VInt(pool, table.current()); + value.set_name(method_name); r.write_no_lang(value); } } @@ -576,6 +586,54 @@ static void _join(Request& r, const Stri } } +#ifndef DOXYGEN +class Table_sql_event_handlers : public SQL_Driver_query_event_handlers { +public: + Table_sql_event_handlers(Pool& apool, const String& amethod_name, + const String& astatement_string, const char *astatement_cstr) : + pool(apool), + method_name(amethod_name), + statement_string(astatement_string), + statement_cstr(astatement_cstr), + columns(*new(pool) Array(pool)), + row(0), row_index(0), + table(0) + { + } + + void add_column(void *ptr, size_t size) { + String *column=new(pool) String(pool); + column->APPEND_TAINTED( + (const char *)ptr, size, + statement_cstr, 0); + columns+=column; + } + void before_rows() { + table=new(pool) Table(pool, &method_name, &columns); + } + void add_row() { + (*table)+=(row=new(pool) Array(pool)); + } + void add_row_cell(void *ptr, size_t size) { + String *cell=new(pool) String(pool); + if(size) + cell->APPEND_TAINTED( + (const char *)ptr, size, + statement_cstr, row_index++); + (*row)+=cell; + } + +private: + Pool& pool; + const String& method_name; + const String& statement_string; const char *statement_cstr; + Array& columns; + Array *row; + uint row_index; +public: + Table *table; +}; +#endif static void _sql(Request& r, const String& method_name, MethodParams *params) { Pool& pool=r.pool(); @@ -602,14 +660,13 @@ static void _sql(Request& r, const Strin const String& statement_string=r.process(statement).as_string(); const char *statement_cstr= statement_string.cstr(String::UL_UNSPECIFIED, r.connection); - unsigned int sql_column_count; SQL_Driver::Cell *sql_columns; - unsigned long sql_row_count; SQL_Driver::Cell **sql_rows; + Table_sql_event_handlers handlers(pool, method_name, + statement_string, statement_cstr); bool need_rethrow=false; Exception rethrow_me; PTRY { r.connection->query( statement_cstr, offset, limit, - &sql_column_count, &sql_columns, - &sql_row_count, &sql_rows); + handlers); } PCATCH(e) { // query problem rethrow_me=e; need_rethrow=true; @@ -620,34 +677,13 @@ static void _sql(Request& r, const Strin &statement_string, // setting more specific source [were url] rethrow_me.comment()); - Array& table_columns=*new(pool) Array(pool); - for(unsigned int i=0; i(r.self)->set_table(table); + static_cast(r.self)->set_table(*handlers.table); } static void _dir(Request& r, const String& method_name, MethodParams *params) {