|
|
| version 1.30, 2001/11/05 11:46:20 | version 1.35, 2002/02/08 08:30:10 |
|---|---|
| Line 1 | Line 1 |
| /** @file | /** @file |
| Parser: @b hash parser class. | Parser: @b hash parser class. |
| Copyright (c) 2001 ArtLebedev Group (http://www.artlebedev.com) | Copyright (c) 2001, 2002 ArtLebedev Group (http://www.artlebedev.com) |
| Author: Alexander Petrosyan <paf@design.ru> (http://paf.design.ru) | Author: Alexandr Petrosian <paf@design.ru> (http://paf.design.ru) |
| $Id$ | $Id$ |
| */ | */ |
| Line 95 static void copy_all_overwrite_to(const | Line 95 static void copy_all_overwrite_to(const |
| Hash& dest=*static_cast<Hash *>(info); | Hash& dest=*static_cast<Hash *>(info); |
| dest.put(key, value); | dest.put(key, value); |
| } | } |
| static void _create_or_add(Request& r, const String& method_name, MethodParams *params) { | static void _create_or_add(Request& r, const String& method_name, MethodParams *params) { |
| Pool& pool=r.pool(); | Pool& pool=r.pool(); |
| Line 110 static void remove_key_from(const Hash:: | Line 109 static void remove_key_from(const Hash:: |
| Hash& dest=*static_cast<Hash *>(info); | Hash& dest=*static_cast<Hash *>(info); |
| dest.remove(key); | dest.remove(key); |
| } | } |
| static void _sub(Request& r, const String& method_name, MethodParams *params) { | static void _sub(Request& r, const String& method_name, MethodParams *params) { |
| Pool& pool=r.pool(); | Pool& pool=r.pool(); |
| Line 123 static void copy_all_dontoverwrite_to(co | Line 121 static void copy_all_dontoverwrite_to(co |
| Hash& dest=*static_cast<Hash *>(info); | Hash& dest=*static_cast<Hash *>(info); |
| dest.put_dont_replace(key, value); | dest.put_dont_replace(key, value); |
| } | } |
| static void _union(Request& r, const String& method_name, MethodParams *params) { | static void _union(Request& r, const String& method_name, MethodParams *params) { |
| Pool& pool=r.pool(); | Pool& pool=r.pool(); |
| Line 153 static void copy_intersection_to(const H | Line 150 static void copy_intersection_to(const H |
| if(i.b->get(key)) | if(i.b->get(key)) |
| i.dest->put_dont_replace(key, value); | i.dest->put_dont_replace(key, value); |
| } | } |
| static void _intersection(Request& r, const String& method_name, MethodParams *params) { | static void _intersection(Request& r, const String& method_name, MethodParams *params) { |
| Pool& pool=r.pool(); | Pool& pool=r.pool(); |
| Line 201 static void _intersects(Request& r, cons | Line 197 static void _intersects(Request& r, cons |
| 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(); |
| if(!r.connection) | |
| throw Exception(0, 0, | |
| &method_name, | |
| "without connect"); | |
| Value& statement=params->as_junction(0, "statement must be code"); | Value& statement=params->as_junction(0, "statement must be code"); |
| ulong limit=0; | ulong limit=0; |
| if(params->size()>1) { | |
| Value& limit_code=params->as_junction(1, "limit must be expression"); | |
| limit=(uint)r.process(limit_code).as_double(); | |
| } | |
| ulong offset=0; | ulong offset=0; |
| if(params->size()>2) { | if(params->size()>1) { |
| Value& offset_code=params->as_junction(2, "offset must be expression"); | Value& voptions=params->as_no_junction(1, "options must be hash, not code"); |
| offset=(ulong)r.process(offset_code).as_double(); | if(voptions.is_defined()) |
| 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 | |
| throw Exception(0, 0, | |
| &method_name, | |
| "options must be hash"); | |
| } | } |
| Temp_lang temp_lang(r, String::UL_SQL); | Temp_lang temp_lang(r, String::UL_SQL); |
| const String& statement_string=r.process(statement).as_string(); | const String& statement_string=r.process(statement).as_string(); |
| const char *statement_cstr= | const char *statement_cstr= |
| statement_string.cstr(String::UL_UNSPECIFIED, r.connection); | statement_string.cstr(String::UL_UNSPECIFIED, r.connection(&method_name)); |
| Hash& hash=static_cast<VHash *>(r.self)->hash(&method_name); | Hash& hash=static_cast<VHash *>(r.self)->hash(&method_name); |
| hash.clear(); | hash.clear(); |
| Hash_sql_event_handlers handlers(pool, method_name, | Hash_sql_event_handlers handlers(pool, method_name, |
| statement_string, statement_cstr, hash); | statement_string, statement_cstr, hash); |
| r.connection->query( | r.connection(&method_name)->query( |
| statement_cstr, offset, limit, | statement_cstr, offset, limit, |
| handlers); | handlers); |
| } | } |
| Line 343 MHash::MHash(Pool& apool) : Methoded(apo | Line 338 MHash::MHash(Pool& apool) : Methoded(apo |
| // ^a.delete[key] | // ^a.delete[key] |
| add_native_method("delete", Method::CT_DYNAMIC, _delete, 1, 1); | add_native_method("delete", Method::CT_DYNAMIC, _delete, 1, 1); |
| // ^hash:sql[query][(count[;offset])] | // ^hash:sql[query][$.limit(1) $.offset(2)] |
| add_native_method("sql", Method::CT_DYNAMIC, _sql, 1, 3); | add_native_method("sql", Method::CT_DYNAMIC, _sql, 1, 2); |
| // ^hash._keys[] | // ^hash._keys[] |
| add_native_method("_keys", Method::CT_DYNAMIC, _keys, 0, 0); | add_native_method("_keys", Method::CT_DYNAMIC, _keys, 0, 0); |