Annotation of parser3/src/include/pa_sql_connection.h, revision 1.20
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)
1.19 paf 5: Author: Alexander Petrosyan <paf@design.ru> (http://paf.design.ru)
1.1 paf 6:
1.20 ! paf 7: $Id: pa_sql_connection.h,v 1.19 2001/11/05 11:46:25 paf Exp $
1.1 paf 8: */
9:
10: #ifndef PA_SQL_CONNECTION_H
11: #define PA_SQL_CONNECTION_H
12:
13: #include "pa_pool.h"
14: #include "pa_sql_driver.h"
1.4 paf 15: #include "pa_sql_driver_manager.h"
1.1 paf 16:
1.15 paf 17: // defines
18:
19: /// @see SQL_Driver_services_impl::_throw
1.17 paf 20: #define SQL_CONNECTION_SERVICED_FUNC_GUARDED(actions) \
1.16 paf 21: if(!fservices || !setjmp(fservices->mark)) { \
1.15 paf 22: actions; \
23: } else \
24: fservices->propagate_exception();
25:
1.14 parser 26: /// SQL connection. handy wrapper around low level SQL_Driver
1.1 paf 27: class SQL_Connection : public Pooled {
28:
29: public:
30:
1.9 parser 31: SQL_Connection(Pool& pool, const String& aurl, SQL_Driver& adriver) : Pooled(pool),
1.1 paf 32: furl(aurl),
1.10 parser 33: fdriver(adriver),
34: fconnection(0),
35: time_stamp(0) {
1.9 parser 36: }
1.12 parser 37:
1.18 paf 38: const String& get_url() { return furl; }
1.12 parser 39:
1.9 parser 40: void set_services(SQL_Driver_services *aservices) {
1.10 parser 41: time_stamp=time(0); // they started to use at this time
1.9 parser 42: fservices=aservices;
1.1 paf 43: }
1.10 parser 44: bool expired(time_t older_dies) {
45: return time_stamp<older_dies;
46: }
1.18 paf 47: time_t get_time_stamp() { return time_stamp; }
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.17 paf 55: SQL_CONNECTION_SERVICED_FUNC_GUARDED(
1.15 paf 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() {
1.17 paf 63: SQL_CONNECTION_SERVICED_FUNC_GUARDED(
1.15 paf 64: fdriver.commit(*fservices, fconnection)
65: );
66: }
67: void rollback() {
1.17 paf 68: SQL_CONNECTION_SERVICED_FUNC_GUARDED(
1.15 paf 69: fdriver.rollback(*fservices, fconnection)
70: );
71: }
72: bool ping() {
1.17 paf 73: SQL_CONNECTION_SERVICED_FUNC_GUARDED(
1.15 paf 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.17 paf 79: SQL_CONNECTION_SERVICED_FUNC_GUARDED(
1.15 paf 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.17 paf 88: SQL_CONNECTION_SERVICED_FUNC_GUARDED(
1.15 paf 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: