|
|
| version 1.172.2.14.2.14, 2003/03/24 13:05:15 | version 1.172.2.14.2.21, 2003/04/02 08:49:57 |
|---|---|
| Line 50 String sql_distinct_name(SQL_DISTINCT_NA | Line 50 String sql_distinct_name(SQL_DISTINCT_NA |
| // methods | // methods |
| static void get_copy_options(Request& r, MethodParams* params, int param_index, | static void get_copy_options(Request& r, MethodParams* params, size_t param_index, |
| const Table& source, | const Table& source, |
| int& offset, | int& offset, |
| int& limit) { | int& limit) { |
| Line 110 static void _create(Request& r, MethodPa | Line 110 static void _create(Request& r, MethodPa |
| r.process_to_string(params->as_junction(params->count()-1, "body must be code")); | r.process_to_string(params->as_junction(params->count()-1, "body must be code")); |
| // parse columns | // parse columns |
| size_t raw_pos_after=0; | |
| Table::columns_type columns; | Table::columns_type columns; |
| if(params->count()==2) { | if(params->count()==2) { |
| columns=Table::columns_type(0); // nameless | columns=Table::columns_type(0); // nameless |
| Line 117 static void _create(Request& r, MethodPa | Line 118 static void _create(Request& r, MethodPa |
| columns=Table::columns_type(new ArrayString); | columns=Table::columns_type(new ArrayString); |
| ArrayString head; | ArrayString head; |
| size_t pos_after=0; | data.split(head, raw_pos_after, "\n", String::L_AS_IS, 1); |
| data.split(head, pos_after, "\n", String::L_AS_IS, 1); | |
| if(head.count()) { | if(head.count()) { |
| size_t pos_after=0; | size_t col_pos_after=0; |
| head[0]->split(*columns, pos_after, "\t", String::L_AS_IS); | head[0]->split(*columns, col_pos_after, "\t", String::L_AS_IS); |
| } | } |
| } | } |
| Line 129 static void _create(Request& r, MethodPa | Line 129 static void _create(Request& r, MethodPa |
| // parse cells | // parse cells |
| ArrayString rows; | ArrayString rows; |
| size_t pos_after=0; | data.split(rows, raw_pos_after, "\n", String::L_AS_IS); |
| data.split(rows, pos_after, "\n", String::L_AS_IS); | |
| Array_iterator<const String*> i(rows); | Array_iterator<const String*> i(rows); |
| while(i.has_next()) { | while(i.has_next()) { |
| Table::element_type row(new ArrayString); | Table::element_type row(new ArrayString); |
| Line 139 static void _create(Request& r, MethodPa | Line 138 static void _create(Request& r, MethodPa |
| if(!string.length()) | if(!string.length()) |
| continue; | continue; |
| size_t pos_after=0; | size_t col_pos_after=0; |
| string.split(*row, pos_after, "\t", String::L_AS_IS); | string.split(*row, col_pos_after, "\t", String::L_AS_IS); |
| table+=row; | table+=row; |
| } | } |
| Line 154 static void _load(Request& r, MethodPara | Line 153 static void _load(Request& r, MethodPara |
| bool nameless=first_param=="nameless"; | bool nameless=first_param=="nameless"; |
| if(nameless) | if(nameless) |
| filename_param_index++; | filename_param_index++; |
| int options_param_index=filename_param_index+1; | size_t options_param_index=filename_param_index+1; |
| // loading text | // loading text |
| char *data=file_read_text(r.charsets.source(), | char *data=file_read_text(r.charsets.source(), |
| Line 211 static void _save(Request& r, MethodPara | Line 210 static void _save(Request& r, MethodPara |
| if(params->count()==1) { // named output | if(params->count()==1) { // named output |
| // write out names line | // write out names line |
| if(table.columns()) { // named table | if(table.columns()) { // named table |
| Array_iterator<const String*> i(*table.columns()); | for(Array_iterator<const String*> i(*table.columns()); i.has_next(); ) { |
| while(i.has_next()) { | |
| sdata.append(*i.next(), String::L_TABLE); | sdata.append(*i.next(), String::L_TABLE); |
| if(i.has_next()) | if(i.has_next()) |
| sdata.append("\t", 1, String::L_CLEAN); | sdata.append_help_length("\t", 1, String::L_CLEAN); |
| } | } |
| } else { // nameless table | } else { // nameless table |
| if(int lsize=table.count()?table[0]->count():0) | if(int lsize=table.count()?table[0]->count():0) |
| for(int column=0; column<lsize; column++) { | for(int column=0; column<lsize; column++) { |
| char *cindex_tab=new char[MAX_NUMBER]; | char *cindex_tab=new(PointerFreeGC) char[MAX_NUMBER]; |
| sdata.append(cindex_tab, | sdata.append_help_length(cindex_tab, |
| snprintf(cindex_tab, MAX_NUMBER, "%d\t", column), | snprintf(cindex_tab, MAX_NUMBER, "%d\t", column), |
| String::L_CLEAN); | String::L_CLEAN); |
| } | } |
| else | else |
| sdata.append("empty nameless table", 0, String::L_CLEAN); | sdata.append_help_length("empty nameless table", 0, String::L_CLEAN); |
| } | } |
| sdata.append("\n", 1, String::L_CLEAN); | sdata.append_help_length("\n", 1, String::L_CLEAN); |
| } else { // mode specified | } else { // mode specified |
| const String& mode=params->as_string(0, "mode must be string"); | const String& mode=params->as_string(0, "mode must be string"); |
| if(mode=="append") | if(mode=="append") |
| Line 244 static void _save(Request& r, MethodPara | Line 242 static void _save(Request& r, MethodPara |
| // data lines | // data lines |
| Array_iterator<ArrayString*> i(table); | Array_iterator<ArrayString*> i(table); |
| while(i.has_next()) { | while(i.has_next()) { |
| Array_iterator<const String*> c(*i.next()); | for(Array_iterator<const String*> c(*i.next()); c.has_next(); ) { |
| while(c.has_next()) { | sdata.append(*c.next(), String::L_TABLE); |
| if(const String* s=c.next()) | |
| sdata.append(*s, String::L_TABLE); | |
| if(c.has_next()) | if(c.has_next()) |
| sdata.append("\t", 1, String::L_CLEAN); | sdata.append_help_length("\t", 1, String::L_CLEAN); |
| } | } |
| sdata.append("\n", 1, String::L_CLEAN); | sdata.append_help_length("\n", 1, String::L_CLEAN); |
| } | } |
| // write | // write |
| Line 320 struct Row_info { | Line 316 struct Row_info { |
| Request *r; | Request *r; |
| Table *table; | Table *table; |
| Value* key_code; | Value* key_code; |
| int key_field; | size_t key_field; |
| Array<int>* value_fields; | Array<int>* value_fields; |
| HashStringValue* hash; | HashStringValue* hash; |
| bool distinct; | bool distinct; |
| int row; | size_t row; |
| }; | }; |
| #endif | #endif |
| static void table_row_to_hash(Table::element_type row, Row_info *info) { | static void table_row_to_hash(Table::element_type row, Row_info *info) { |
| Line 341 static void table_row_to_hash(Table::ele | Line 337 static void table_row_to_hash(Table::ele |
| VHash* vhash=new VHash; | VHash* vhash=new VHash; |
| HashStringValue& hash=vhash->hash(); | HashStringValue& hash=vhash->hash(); |
| for(int i=0; i<info->value_fields->count(); i++) { | for(Array_iterator<int> i(*info->value_fields); i.has_next(); ) { |
| int value_field=info->value_fields->get(i); | size_t value_field=i.next(); |
| if(value_field<row->count()) | if(value_field<row->count()) |
| hash.put( | hash.put( |
| *info->table->columns()->get(value_field), | *info->table->columns()->get(value_field), |
| Line 389 static void _hash(Request& r, MethodPara | Line 385 static void _hash(Request& r, MethodPara |
| value_fields+=self_table.column_name2index( | value_fields+=self_table.column_name2index( |
| *value_fields_param.get_string(), true); | *value_fields_param.get_string(), true); |
| } else if(Table* value_fields_table=value_fields_param.get_table()) { | } else if(Table* value_fields_table=value_fields_param.get_table()) { |
| for(int i=0; i<value_fields_table->count(); i++) { | for(Array_iterator<Table::element_type> i(*value_fields_table); |
| const String& value_field_name= | i.has_next(); ) { |
| *value_fields_table->get(i)->get(0); | const String& value_field_name |
| value_fields+=self_table.column_name2index(value_field_name, true); | =*i.next()->get(0); |
| value_fields | |
| +=self_table.column_name2index(value_field_name, true); | |
| } | } |
| } else | } else |
| throw Exception("parser.runtime", | throw Exception("parser.runtime", |
| Line 400 static void _hash(Request& r, MethodPara | Line 398 static void _hash(Request& r, MethodPara |
| "value field(s) must be string or self_table" | "value field(s) must be string or self_table" |
| ); | ); |
| } else { // by all columns, including key | } else { // by all columns, including key |
| for(int i=0; i<columns->count(); i++) | for(size_t i=0; i<columns->count(); i++) |
| value_fields+=i; | value_fields+=i; |
| } | } |
| Line 461 static void _sort(Request& r, MethodPara | Line 459 static void _sort(Request& r, MethodPara |
| Table& old_table=GET_SELF(r, VTable).table(); | Table& old_table=GET_SELF(r, VTable).table(); |
| Table& new_table=*new Table(old_table.columns()); | Table& new_table=*new Table(old_table.columns()); |
| Table_seq_item* seq=new Table_seq_item[old_table.count()]; | Table_seq_item* seq=new(PointerFreeGC) Table_seq_item[old_table.count()]; |
| int i; | int i; |
| // calculate key values | // calculate key values |
| bool key_values_are_strings=true; | bool key_values_are_strings=true; |
| for(i=0; i<old_table.count(); i++) { | int old_count=old_table.count(); |
| for(i=0; i<old_count; i++) { | |
| old_table.set_current(i); | old_table.set_current(i); |
| // calculate key value | // calculate key value |
| seq[i].row=old_table[i]; | seq[i].row=old_table[i]; |
| Line 480 static void _sort(Request& r, MethodPara | Line 479 static void _sort(Request& r, MethodPara |
| seq[i].value.d=value->as_double(); | seq[i].value.d=value->as_double(); |
| } | } |
| // sort keys | // sort keys |
| _qsort(seq, old_table.count(), sizeof(Table_seq_item), | _qsort(seq, old_count, sizeof(Table_seq_item), |
| key_values_are_strings?sort_cmp_string:sort_cmp_double); | key_values_are_strings?sort_cmp_string:sort_cmp_double); |
| // reorder table as they require in 'seq' | // reorder table as they require in 'seq' |
| for(i=0; i<old_table.count(); i++) | for(i=0; i<old_count; i++) |
| new_table+=Table::element_type(seq[reverse?old_table.count()-1-i:i].row); | new_table+=Table::element_type(seq[reverse?old_count-1-i:i].row); |
| delete[] seq; | |
| // replace any previous table value | // replace any previous table value |
| GET_SELF(r, VTable).set_table(new_table); | GET_SELF(r, VTable).set_table(new_table); |
| Line 533 static void _locate(Request& r, MethodPa | Line 534 static void _locate(Request& r, MethodPa |
| static void _flip(Request& r, MethodParams* params) { | static void _flip(Request& r, MethodParams* params) { |
| Table& old_table=GET_SELF(r, VTable).table(); | Table& old_table=GET_SELF(r, VTable).table(); |
| Table& new_table=*new Table(old_table.columns()); | Table& new_table=*new Table(old_table.columns()); |
| if(old_table.count()) | if(size_t old_count=old_table.count()) |
| if(int old_cols=old_table[0]->count()) | if(size_t old_cols=old_table[0]->count()) |
| for(int column=0; column<old_cols; column++) { | for(size_t column=0; column<old_cols; column++) { |
| Table::element_type new_row(new ArrayString(old_table.count())); | Table::element_type new_row(new ArrayString(old_count)); |
| for(int i=0; i<old_table.count(); i++) { | for(size_t i=0; i<old_count; i++) { |
| Table::element_type old_row=old_table[i]; | Table::element_type old_row=old_table[i]; |
| *new_row+=column<old_row->count()?old_row->get(column):new String; | *new_row+=column<old_row->count()?old_row->get(column):new String; |
| } | } |
| Line 587 static void _join(Request& r, MethodPara | Line 588 static void _join(Request& r, MethodPara |
| for(int src_row=offset; src_row<end; src_row++) { | for(int src_row=offset; src_row<end; src_row++) { |
| src.set_current(src_row); | src.set_current(src_row); |
| Table::element_type dest_row(new ArrayString(src.count())); | Table::element_type dest_row(new ArrayString(src.count())); |
| for(int dest_column=0; dest_column<dest_columns->count(); dest_column++) { | for(size_t dest_column=0; dest_column<dest_columns->count(); dest_column++) { |
| const String* src_item=src.item(*dest_columns->get(dest_column)); | const String* src_item=src.item(*dest_columns->get(dest_column)); |
| *dest_row+=src_item?src_item:new String; | *dest_row+=src_item?src_item:new String; |
| } | } |
| Line 595 static void _join(Request& r, MethodPara | Line 596 static void _join(Request& r, MethodPara |
| } | } |
| src.set_current(saved_src_current); | src.set_current(saved_src_current); |
| } else { // dest is nameless | } else { // dest is nameless |
| for(int src_row=0; src_row<src.count(); src_row++) | size_t src_count=src.count(); |
| for(size_t src_row=0; src_row<src_count; src_row++) | |
| dest+=src[src_row]; | dest+=src[src_row]; |
| } | } |
| } | } |
| Line 611 public: | Line 613 public: |
| columns(*new ArrayString), row(0), table(0) { | columns(*new ArrayString), row(0), table(0) { |
| } | } |
| bool add_column(SQL_Error& error, void *ptr, size_t size) { | bool add_column(SQL_Error& error, const char *str, size_t size) { |
| try { | try { |
| columns+=new String((const char* )ptr, size, true); | columns+=new String(str, size, true); |
| return false; | return false; |
| } catch(...) { | } catch(...) { |
| error=SQL_Error("exception occured in Table_sql_event_handlers::add_column"); | error=SQL_Error("exception occured in Table_sql_event_handlers::add_column"); |
| Line 638 public: | Line 640 public: |
| return true; | return true; |
| } | } |
| } | } |
| bool add_row_cell(SQL_Error& error, void *ptr, size_t size) { | bool add_row_cell(SQL_Error& error, const char* str, size_t size) { |
| try { | try { |
| String& cell=*new String; | String& cell=*new String; |
| if(size) | if(size) |
| cell.append((const char* )ptr, size, String::L_TAINTED); | cell.append_help_length(str, size, String::L_TAINTED); |
| *row+=&cell; | *row+=&cell; |
| return false; | return false; |
| } catch(...) { | } catch(...) { |
| Line 722 static void _columns(Request& r, MethodP | Line 724 static void _columns(Request& r, MethodP |
| Table& source_table=GET_SELF(r, VTable).table(); | Table& source_table=GET_SELF(r, VTable).table(); |
| if(Table::columns_type source_columns=source_table.columns()) { | if(Table::columns_type source_columns=source_table.columns()) { |
| Array_iterator<const String*> i(*source_columns); | for(Array_iterator<const String*> i(*source_columns); i.has_next(); ) { |
| while(i.has_next()) { | |
| Table::element_type result_row(new ArrayString); | Table::element_type result_row(new ArrayString); |
| *result_row+=i.next(); | *result_row+=i.next(); |
| result_table+=result_row; | result_table+=result_row; |