Annotation of parser3/src/include/pa_sql_connection.h, revision 1.16
1.1 paf 1: /** @file
1.9 parser 2: Parser: sql fconnection decl.
1.1 paf 3:
4: Copyright (c) 2001 ArtLebedev Group (http://www.artlebedev.com)
5: Author: Alexander Petrosyan <paf@design.ru> (http://design.ru/paf)
6:
1.16 ! paf 7: $Id: pa_sql_connection.h,v 1.15 2001/10/29 08:05:37 paf Exp $
1.1 paf 8: */
9:
10: #ifndef PA_SQL_CONNECTION_H
11: #define PA_SQL_CONNECTION_H
12:
1.7 parser 13: #include "pa_config_includes.h"
1.1 paf 14: #include "pa_pool.h"
15: #include "pa_sql_driver.h"
1.4 paf 16: #include "pa_sql_driver_manager.h"
1.1 paf 17:
1.15 paf 18: // defines
19:
20: /// @see SQL_Driver_services_impl::_throw
21: #define SQL_CONNECTION_FUNC_GUARDED(actions) \
1.16 ! paf 22: if(!fservices || !setjmp(fservices->mark)) { \
1.15 paf 23: actions; \
24: } else \
25: fservices->propagate_exception();
26:
1.14 parser 27: /// SQL connection. handy wrapper around low level SQL_Driver
1.1 paf 28: class SQL_Connection : public Pooled {
29:
30: public:
31:
1.9 parser 32: SQL_Connection(Pool& pool, const String& aurl, SQL_Driver& adriver) : Pooled(pool),
1.1 paf 33: furl(aurl),
1.10 parser 34: fdriver(adriver),
35: fconnection(0),
36: time_stamp(0) {
1.9 parser 37: }
1.12 parser 38:
39: const String& url() { return furl; }
40:
1.9 parser 41: void set_services(SQL_Driver_services *aservices) {
1.10 parser 42: time_stamp=time(0); // they started to use at this time
1.9 parser 43: fservices=aservices;
1.1 paf 44: }
1.10 parser 45: bool expired(time_t older_dies) {
46: return time_stamp<older_dies;
47: }
1.1 paf 48:
1.9 parser 49: void close() {
50: SQL_driver_manager->close_connection(furl, *this);
1.1 paf 51: }
52:
1.10 parser 53: bool connected() { return fconnection!=0; }
1.9 parser 54: void connect(char *used_only_in_connect_url_cstr) {
1.15 paf 55: SQL_CONNECTION_FUNC_GUARDED(
56: fdriver.connect(used_only_in_connect_url_cstr, *fservices, &fconnection)
57: );
58: }
59: void disconnect() {
1.16 ! paf 60: fdriver.disconnect(fconnection); fconnection=0;
1.15 paf 61: }
62: void commit() {
63: SQL_CONNECTION_FUNC_GUARDED(
64: fdriver.commit(*fservices, fconnection)
65: );
66: }
67: void rollback() {
68: SQL_CONNECTION_FUNC_GUARDED(
69: fdriver.rollback(*fservices, fconnection)
70: );
71: }
72: bool ping() {
73: SQL_CONNECTION_FUNC_GUARDED(
74: return fdriver.ping(*fservices, fconnection)
75: );
76: return 0; // never reached
1.9 parser 77: }
1.4 paf 78: uint quote(char *to, const char *from, unsigned int length) {
1.15 paf 79: SQL_CONNECTION_FUNC_GUARDED(
80: return fdriver.quote(*fservices, fconnection, to, from, length)
81: );
82: return 0; // never reached
1.4 paf 83: }
84:
1.2 paf 85: void query(
1.3 paf 86: const char *statement, unsigned long offset, unsigned long limit,
1.11 parser 87: SQL_Driver_query_event_handlers& handlers) {
1.15 paf 88: SQL_CONNECTION_FUNC_GUARDED(
89: fdriver.query(*fservices, fconnection,
90: statement, offset, limit,
91: handlers)
92: );
1.2 paf 93: }
94:
1.1 paf 95:
96: private:
97:
1.9 parser 98: const String& furl;
1.1 paf 99: SQL_Driver& fdriver;
1.9 parser 100: SQL_Driver_services *fservices;
101: void *fconnection;
1.10 parser 102: time_t time_stamp;
1.1 paf 103: };
104:
105: #endif
E-mail: