|
|
| version 1.13, 2001/09/26 10:32:25 | version 1.18, 2001/11/05 10:21:26 |
|---|---|
| Line 15 | Line 15 |
| #include "pa_sql_driver.h" | #include "pa_sql_driver.h" |
| #include "pa_sql_driver_manager.h" | #include "pa_sql_driver_manager.h" |
| /// SQL fconnection. handy wrapper around low level SQL_Driver | // defines |
| /// @see SQL_Driver_services_impl::_throw | |
| #define SQL_CONNECTION_SERVICED_FUNC_GUARDED(actions) \ | |
| if(!fservices || !setjmp(fservices->mark)) { \ | |
| actions; \ | |
| } else \ | |
| fservices->propagate_exception(); | |
| /// SQL connection. handy wrapper around low level SQL_Driver | |
| class SQL_Connection : public Pooled { | class SQL_Connection : public Pooled { |
| public: | public: |
| Line 27 public: | Line 36 public: |
| time_stamp(0) { | time_stamp(0) { |
| } | } |
| const String& url() { return furl; } | const String& get_url() { return furl; } |
| void set_services(SQL_Driver_services *aservices) { | void set_services(SQL_Driver_services *aservices) { |
| time_stamp=time(0); // they started to use at this time | time_stamp=time(0); // they started to use at this time |
| Line 36 public: | Line 45 public: |
| bool expired(time_t older_dies) { | bool expired(time_t older_dies) { |
| return time_stamp<older_dies; | return time_stamp<older_dies; |
| } | } |
| time_t get_time_stamp() { return time_stamp; } | |
| void close() { | void close() { |
| SQL_driver_manager->close_connection(furl, *this); | SQL_driver_manager->close_connection(furl, *this); |
| Line 43 public: | Line 53 public: |
| bool connected() { return fconnection!=0; } | bool connected() { return fconnection!=0; } |
| void connect(char *used_only_in_connect_url_cstr) { | void connect(char *used_only_in_connect_url_cstr) { |
| fdriver.connect(used_only_in_connect_url_cstr, *fservices, &fconnection); | SQL_CONNECTION_SERVICED_FUNC_GUARDED( |
| fdriver.connect(used_only_in_connect_url_cstr, *fservices, &fconnection) | |
| ); | |
| } | |
| void disconnect() { | |
| fdriver.disconnect(fconnection); fconnection=0; | |
| } | |
| void commit() { | |
| SQL_CONNECTION_SERVICED_FUNC_GUARDED( | |
| fdriver.commit(*fservices, fconnection) | |
| ); | |
| } | |
| void rollback() { | |
| SQL_CONNECTION_SERVICED_FUNC_GUARDED( | |
| fdriver.rollback(*fservices, fconnection) | |
| ); | |
| } | |
| bool ping() { | |
| SQL_CONNECTION_SERVICED_FUNC_GUARDED( | |
| return fdriver.ping(*fservices, fconnection) | |
| ); | |
| return 0; // never reached | |
| } | } |
| void disconnect() { fdriver.disconnect(fconnection); fconnection=0; } | |
| void commit() { fdriver.commit(*fservices, fconnection); } | |
| void rollback() { fdriver.rollback(*fservices, fconnection); } | |
| bool ping() { return fdriver.ping(*fservices, fconnection); } | |
| uint quote(char *to, const char *from, unsigned int length) { | uint quote(char *to, const char *from, unsigned int length) { |
| return fdriver.quote(*fservices, fconnection, to, from, length); | SQL_CONNECTION_SERVICED_FUNC_GUARDED( |
| return fdriver.quote(*fservices, fconnection, to, from, length) | |
| ); | |
| return 0; // never reached | |
| } | } |
| void query( | void query( |
| const char *statement, unsigned long offset, unsigned long limit, | const char *statement, unsigned long offset, unsigned long limit, |
| SQL_Driver_query_event_handlers& handlers) { | SQL_Driver_query_event_handlers& handlers) { |
| fdriver.query(*fservices, fconnection, | SQL_CONNECTION_SERVICED_FUNC_GUARDED( |
| statement, offset, limit, | fdriver.query(*fservices, fconnection, |
| handlers); | statement, offset, limit, |
| handlers) | |
| ); | |
| } | } |