Annotation of parser3/src/include/pa_sql_connection.h, revision 1.15
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.15 ! paf 7: $Id: pa_sql_connection.h,v 1.14 2001/10/22 16:44:42 parser 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) \
! 22: if(!setjmp(fservices->mark)) { \
! 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() {
! 60: SQL_CONNECTION_FUNC_GUARDED(
! 61: fdriver.disconnect(fconnection); fconnection=0;
! 62: );
! 63: }
! 64: void commit() {
! 65: SQL_CONNECTION_FUNC_GUARDED(
! 66: fdriver.commit(*fservices, fconnection)
! 67: );
! 68: }
! 69: void rollback() {
! 70: SQL_CONNECTION_FUNC_GUARDED(
! 71: fdriver.rollback(*fservices, fconnection)
! 72: );
! 73: }
! 74: bool ping() {
! 75: SQL_CONNECTION_FUNC_GUARDED(
! 76: return fdriver.ping(*fservices, fconnection)
! 77: );
! 78: return 0; // never reached
1.9 parser 79: }
1.4 paf 80: uint quote(char *to, const char *from, unsigned int length) {
1.15 ! paf 81: SQL_CONNECTION_FUNC_GUARDED(
! 82: return fdriver.quote(*fservices, fconnection, to, from, length)
! 83: );
! 84: return 0; // never reached
1.4 paf 85: }
86:
1.2 paf 87: void query(
1.3 paf 88: const char *statement, unsigned long offset, unsigned long limit,
1.11 parser 89: SQL_Driver_query_event_handlers& handlers) {
1.15 ! paf 90: SQL_CONNECTION_FUNC_GUARDED(
! 91: fdriver.query(*fservices, fconnection,
! 92: statement, offset, limit,
! 93: handlers)
! 94: );
1.2 paf 95: }
96:
1.1 paf 97:
98: private:
99:
1.9 parser 100: const String& furl;
1.1 paf 101: SQL_Driver& fdriver;
1.9 parser 102: SQL_Driver_services *fservices;
103: void *fconnection;
1.10 parser 104: time_t time_stamp;
1.1 paf 105: };
106:
107: #endif
E-mail: