Annotation of parser3/src/sql/pa_sql_driver.h, revision 1.26

1.22      paf         1: /** @file
                      2:        Parser: sql driver interface.
                      3: 
1.25      paf         4:        Copyright (c) 2001, 2002 ArtLebedev Group (http://www.artlebedev.com)
1.26    ! paf         5:        Author: Alexandr Petrosian <paf@design.ru> (http://paf.design.ru)
1.22      paf         6: 
1.26    ! paf         7:        $Id: pa_sql_driver.h,v 1.25 2002/02/08 07:27:49 paf Exp $
1.22      paf         8: 
                      9: 
                     10:        driver dynamic library must look like this:
                     11:        @code
                     12:                class X_SQL_Driver : public SQL_Driver {
                     13:                public:
                     14: 
                     15:                        X_SQL_Driver() : SQL_driver() {}
                     16: 
                     17:                        int api_version() { return SQL_DRIVER_API_VERSION; }
                     18:                        
                     19:                        //...
                     20:                };
                     21: 
                     22:                extern "C" SQL_Driver *create() {
                     23:                        return new X_SQL_Driver();
                     24:                }       
                     25:        @endcode
                     26: */
                     27: 
                     28: #ifndef PA_SQL_DRIVER_H
                     29: #define PA_SQL_DRIVER_H
                     30: 
                     31: #include <sys/types.h>
                     32: 
                     33: /// service functions for SQL driver to use
                     34: class SQL_Driver_services {
                     35: public:
                     36:        /// allocates some bytes on pool
                     37:        virtual void *malloc(size_t size) =0;
                     38:        /// allocates some bytes clearing them with zeros
                     39:        virtual void *calloc(size_t size) =0;
                     40:        /// prepare throw exception
                     41:        virtual void _throw(const char *comment) =0;
                     42:        /// throw C++ exception from prepared
                     43:        virtual void propagate_exception() =0;
                     44: public:
                     45:        /// regretrully public, because can't make stack frames: "nowhere to return to"
                     46:        jmp_buf mark;
                     47: };
                     48: 
1.24      paf        49: #define SQL_DRIVER_API_VERSION 0x0003
                     50: #define SQL_DRIVER_CREATE create /* used in driver implementation */
1.22      paf        51: #define SQL_DRIVER_CREATE_NAME "create" /* could not figure out how to # it :( */
                     52: 
                     53: /// events, occuring when SQL_Driver::query()-ing
                     54: class SQL_Driver_query_event_handlers {
                     55: public:
                     56:        virtual void add_column(void *ptr, size_t size) =0;
                     57:        virtual void before_rows() =0;
                     58:        virtual void add_row() =0;
                     59:        virtual void add_row_cell(void *ptr, size_t size) =0;
                     60: };
                     61: 
                     62: /// SQL driver API
                     63: class SQL_Driver {
                     64: public:
                     65: 
                     66:        /// get api version
                     67:        virtual int api_version() =0;
                     68:        /// initialize driver by loading sql dynamic link library
                     69:        virtual const char *initialize(char *dlopen_file_spec) =0;
                     70:        /**     connect to sql database using 
                     71:                @param used_only_to_connect_url 
                     72:                        format is driver specific
                     73:                        WARNING: must be used only to connect, for buffer doesn't live long enough
                     74: 
                     75:                @returns true+'connection' on success. 'error' on failure
                     76:        */
                     77:        virtual void connect(char *used_only_in_connect_url_cstr, 
                     78:                SQL_Driver_services& services, void **connection) =0;
                     79:        virtual void disconnect(void *connection) =0;
                     80:        virtual void commit(
                     81:                SQL_Driver_services& services, void *connection) =0;
                     82:        virtual void rollback(
                     83:                SQL_Driver_services& services, void *connection) =0;
                     84:        /// @returns true to indicate that connection still alive 
                     85:        virtual bool ping(
                     86:                SQL_Driver_services& services, void *connection) =0;
                     87:        /// encodes the string in 'from' to an escaped SQL string
                     88:        virtual unsigned int quote(
                     89:                SQL_Driver_services& services, void *connection,
                     90:                char *to, const char *from, unsigned int length) =0;
                     91:        virtual void query(
                     92:                SQL_Driver_services& services, void *connection,
                     93:                const char *statement, unsigned long offset, unsigned long limit,
                     94:                SQL_Driver_query_event_handlers& handlers) =0;
                     95: };
                     96: 
                     97: typedef SQL_Driver *(*SQL_Driver_create_func)();
                     98: 
                     99: #endif

E-mail: