Annotation of parser3/src/include/pa_sql_connection.h, revision 1.19

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.19    ! paf         7:        $Id: pa_sql_connection.h,v 1.18 2001/11/05 10:21:26 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
1.17      paf        21: #define SQL_CONNECTION_SERVICED_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:        
1.18      paf        39:        const String& get_url() { return furl; }
1.12      parser     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.18      paf        48:        time_t get_time_stamp() { return time_stamp; }
1.1       paf        49: 
1.9       parser     50:        void close() {
                     51:                SQL_driver_manager->close_connection(furl, *this);
1.1       paf        52:        }
                     53: 
1.10      parser     54:        bool connected() { return fconnection!=0; }
1.9       parser     55:        void connect(char *used_only_in_connect_url_cstr) { 
1.17      paf        56:                SQL_CONNECTION_SERVICED_FUNC_GUARDED(
1.15      paf        57:                        fdriver.connect(used_only_in_connect_url_cstr, *fservices, &fconnection)
                     58:                );
                     59:        }
                     60:        void disconnect() { 
1.16      paf        61:                fdriver.disconnect(fconnection); fconnection=0; 
1.15      paf        62:        }
                     63:        void commit() { 
1.17      paf        64:                SQL_CONNECTION_SERVICED_FUNC_GUARDED(
1.15      paf        65:                        fdriver.commit(*fservices, fconnection) 
                     66:                );
                     67:        }
                     68:        void rollback() { 
1.17      paf        69:                SQL_CONNECTION_SERVICED_FUNC_GUARDED(
1.15      paf        70:                        fdriver.rollback(*fservices, fconnection)
                     71:                );
                     72:        }
                     73:        bool ping() { 
1.17      paf        74:                SQL_CONNECTION_SERVICED_FUNC_GUARDED(
1.15      paf        75:                        return fdriver.ping(*fservices, fconnection)
                     76:                );
                     77:                return 0; // never reached
1.9       parser     78:        }
1.4       paf        79:        uint quote(char *to, const char *from, unsigned int length) {
1.17      paf        80:                SQL_CONNECTION_SERVICED_FUNC_GUARDED(
1.15      paf        81:                        return fdriver.quote(*fservices, fconnection, to, from, length)
                     82:                );
                     83:                return 0; // never reached
1.4       paf        84:        }
                     85: 
1.2       paf        86:        void query(
1.3       paf        87:                const char *statement, unsigned long offset, unsigned long limit,
1.11      parser     88:                SQL_Driver_query_event_handlers& handlers) { 
1.17      paf        89:                SQL_CONNECTION_SERVICED_FUNC_GUARDED(
1.15      paf        90:                        fdriver.query(*fservices, fconnection, 
                     91:                                statement, offset, limit, 
                     92:                                handlers)
                     93:                );
1.2       paf        94:        }
                     95: 
1.1       paf        96: 
                     97: private:
                     98: 
1.9       parser     99:        const String& furl;
1.1       paf       100:        SQL_Driver& fdriver;
1.9       parser    101:        SQL_Driver_services *fservices;
                    102:        void *fconnection;
1.10      parser    103:        time_t time_stamp;
1.1       paf       104: };
                    105: 
                    106: #endif

E-mail: