|
|
| version 1.69, 2001/05/02 11:49:17 | version 1.73, 2001/05/08 06:42:54 |
|---|---|
| Line 19 | Line 19 |
| #include "pa_vint.h" | #include "pa_vint.h" |
| #include "pa_sql_connection.h" | #include "pa_sql_connection.h" |
| #include "pa_dir.h" | #include "pa_dir.h" |
| #include "pa_vbool.h" | |
| // defines | // defines |
| Line 28 | Line 29 |
| class MTable : public Methoded { | class MTable : public Methoded { |
| public: // VStateless_class | public: // VStateless_class |
| Value *create_new_value(Pool& pool) { return new(pool) VTable(pool); } | Value *create_new_value(Pool& pool) { return new(pool) VTable(pool); } |
| public: | public: |
| MTable(Pool& pool); | MTable(Pool& pool); |
| bool used_directly() { return true; } | |
| public: // Methoded | |
| bool used_directly() { return true; } | |
| }; | }; |
| // methods | // methods |
| Line 241 struct Record_info { | Line 242 struct Record_info { |
| static void store_column_item_to_hash(Array::Item *item, void *info) { | static void store_column_item_to_hash(Array::Item *item, void *info) { |
| Record_info& ri=*static_cast<Record_info *>(info); | Record_info& ri=*static_cast<Record_info *>(info); |
| String& column_name=*static_cast<String *>(item); | String& column_name=*static_cast<String *>(item); |
| const String *column_item=ri.table->item(column_name); | |
| Value *value; | Value *value; |
| if(column_item) | if(const String *column_item=ri.table->item(column_name)) |
| value=new(*ri.pool) VString(*column_item); | value=new(*ri.pool) VString(*column_item); |
| else | else |
| value=new(*ri.pool) VUnknown(*ri.pool); | value=new(*ri.pool) VUnknown(*ri.pool); |
| Line 253 static void _record(Request& r, const St | Line 253 static void _record(Request& r, const St |
| Table& table=static_cast<VTable *>(r.self)->table(); | Table& table=static_cast<VTable *>(r.self)->table(); |
| if(const Array *columns=table.columns()) { | if(const Array *columns=table.columns()) { |
| Pool& pool=r.pool(); | Pool& pool=r.pool(); |
| Value& value=*new(pool) VHash(pool); | Value& result=*new(pool) VHash(pool); |
| Record_info record_info={&pool, &table, value.get_hash()}; | Record_info record_info={&pool, &table, result.get_hash()}; |
| columns->for_each(store_column_item_to_hash, &record_info); | columns->for_each(store_column_item_to_hash, &record_info); |
| result.set_name(method_name); | |
| r.write_no_lang(value); | r.write_no_lang(result); |
| } | } |
| } | } |
| Line 328 static void _sort(Request& r, const Stri | Line 328 static void _sort(Request& r, const Stri |
| } | } |
| static void _locate(Request& r, const String& method_name, MethodParams *params) { | static void _locate(Request& r, const String& method_name, MethodParams *params) { |
| Pool& pool=r.pool(); | |
| VTable& vtable=*static_cast<VTable *>(r.self); | VTable& vtable=*static_cast<VTable *>(r.self); |
| Table& table=vtable.table(); | Table& table=vtable.table(); |
| vtable.last_locate_was_successful=table.locate( | Value& result=*new(pool) VBool(pool, table.locate( |
| params->get(0).as_string(), | params->get(0).as_string(), |
| params->get(1).as_string()); | params->get(1).as_string())); |
| } | result.set_name(method_name); |
| r.write_no_lang(result); | |
| static void _found(Request& r, const String& method_name, MethodParams *params) { | |
| if(static_cast<VTable *>(r.self)->last_locate_was_successful) | |
| r.write_pass_lang(r.process(params->get_junction(0, "found-parameter must be code"))); | |
| else if(params->size()==2) | |
| r.write_pass_lang(r.process(params->get_junction(0, "else-parameter must be code"))); | |
| } | } |
| static void _flip(Request& r, const String& method_name, MethodParams *params) { | static void _flip(Request& r, const String& method_name, MethodParams *params) { |
| Line 411 static void _join(Request& r, const Stri | Line 408 static void _join(Request& r, const Stri |
| } | } |
| } | } |
| /// ^table:sql{query}[(count[;offset])] | |
| static void _sql(Request& r, const String& method_name, MethodParams *params) { | static void _sql(Request& r, const String& method_name, MethodParams *params) { |
| Pool& pool=r.pool(); | Pool& pool=r.pool(); |
| Line 487 static void _sql(Request& r, const Strin | Line 483 static void _sql(Request& r, const Strin |
| static_cast<VTable *>(r.self)->set_table(table); | static_cast<VTable *>(r.self)->set_table(table); |
| } | } |
| /// ^table:dir[path] | |
| /// ^table:dir[path][regexp] | |
| static void _dir(Request& r, const String& method_name, MethodParams *params) { | static void _dir(Request& r, const String& method_name, MethodParams *params) { |
| Pool& pool=r.pool(); | Pool& pool=r.pool(); |
| Line 608 MTable::MTable(Pool& apool) : Methoded(a | Line 602 MTable::MTable(Pool& apool) : Methoded(a |
| // ^table.locate[field;value] | // ^table.locate[field;value] |
| add_native_method("locate", Method::CT_DYNAMIC, _locate, 2, 2); | add_native_method("locate", Method::CT_DYNAMIC, _locate, 2, 2); |
| // ^table.found{when-found} | |
| // ^table.found{when-found}{when-not-found} | |
| add_native_method("found", Method::CT_DYNAMIC, _found, 1, 2); | |
| // ^table.flip[] | // ^table.flip[] |
| add_native_method("flip", Method::CT_DYNAMIC, _flip, 0, 0); | add_native_method("flip", Method::CT_DYNAMIC, _flip, 0, 0); |