--- parser3/src/include/pa_sql_connection.h 2001/05/17 12:51:05 1.8 +++ parser3/src/include/pa_sql_connection.h 2001/10/29 08:05:37 1.15 @@ -1,11 +1,10 @@ /** @file - Parser: sql connection decl. + Parser: sql fconnection decl. Copyright (c) 2001 ArtLebedev Group (http://www.artlebedev.com) - Author: Alexander Petrosyan (http://design.ru/paf) - $Id: pa_sql_connection.h,v 1.8 2001/05/17 12:51:05 parser Exp $ + $Id: pa_sql_connection.h,v 1.15 2001/10/29 08:05:37 paf Exp $ */ #ifndef PA_SQL_CONNECTION_H @@ -16,52 +15,93 @@ #include "pa_sql_driver.h" #include "pa_sql_driver_manager.h" +// defines + +/// @see SQL_Driver_services_impl::_throw +#define SQL_CONNECTION_FUNC_GUARDED(actions) \ + if(!setjmp(fservices->mark)) { \ + actions; \ + } else \ + fservices->propagate_exception(); + /// SQL connection. handy wrapper around low level SQL_Driver class SQL_Connection : public Pooled { public: - void set_services(SQL_Driver_services *services) { - fdriver.set_services(services); + SQL_Connection(Pool& pool, const String& aurl, SQL_Driver& adriver) : Pooled(pool), + furl(aurl), + fdriver(adriver), + fconnection(0), + time_stamp(0) { } + + const String& url() { return furl; } - SQL_Connection(Pool& pool, - const String& aurl, - SQL_Driver& adriver, - char *used_only_in_constructor_url_cstr) : Pooled(pool), - furl(aurl), - fdriver(adriver) { - fdriver.connect(used_only_in_constructor_url_cstr, &connection); + void set_services(SQL_Driver_services *aservices) { + time_stamp=time(0); // they started to use at this time + fservices=aservices; + } + bool expired(time_t older_dies) { + return time_stampclose_connection(furl, *this, pool); + void close() { + SQL_driver_manager->close_connection(furl, *this); } - void disconnect() { fdriver.disconnect(connection); } - void commit() { fdriver.commit(connection); } - void rollback() { fdriver.rollback(connection); } - bool ping() { return fdriver.ping(connection); } + bool connected() { return fconnection!=0; } + void connect(char *used_only_in_connect_url_cstr) { + SQL_CONNECTION_FUNC_GUARDED( + fdriver.connect(used_only_in_connect_url_cstr, *fservices, &fconnection) + ); + } + void disconnect() { + SQL_CONNECTION_FUNC_GUARDED( + fdriver.disconnect(fconnection); fconnection=0; + ); + } + void commit() { + SQL_CONNECTION_FUNC_GUARDED( + fdriver.commit(*fservices, fconnection) + ); + } + void rollback() { + SQL_CONNECTION_FUNC_GUARDED( + fdriver.rollback(*fservices, fconnection) + ); + } + bool ping() { + SQL_CONNECTION_FUNC_GUARDED( + return fdriver.ping(*fservices, fconnection) + ); + return 0; // never reached + } uint quote(char *to, const char *from, unsigned int length) { - return fdriver.quote(connection, to, from, length); + SQL_CONNECTION_FUNC_GUARDED( + return fdriver.quote(*fservices, fconnection, to, from, length) + ); + return 0; // never reached } void query( const char *statement, unsigned long offset, unsigned long limit, - unsigned int *column_count, SQL_Driver::Cell **columns, - unsigned long *row_count, SQL_Driver::Cell ***rows) { - fdriver.query(connection, - statement, offset, limit, - column_count, columns, - row_count, rows); + SQL_Driver_query_event_handlers& handlers) { + SQL_CONNECTION_FUNC_GUARDED( + fdriver.query(*fservices, fconnection, + statement, offset, limit, + handlers) + ); } private: - SQL_Driver& fdriver; - void *connection; const String& furl; + SQL_Driver& fdriver; + SQL_Driver_services *fservices; + void *fconnection; + time_t time_stamp; }; #endif