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

1.1       paf         1: /** @file
                      2:        Parser: sql driver interface.
                      3: 
                      4:        Copyright (c) 2001 ArtLebedev Group (http://www.artlebedev.com)
                      5: 
                      6:        Author: Alexander Petrosyan <paf@design.ru> (http://design.ru/paf)
                      7: 
1.4     ! paf         8:        $Id: pa_sql_driver.h,v 1.3 2001/04/05 11:50:10 paf Exp $
1.1       paf         9: 
                     10: 
                     11:        driver dynamic library must look like this:
                     12:        @code
                     13:                class X_SQL_Driver : public SQL_Driver {
                     14:                public:
                     15: 
                     16:                        X_SQL_Driver() : SQL_driver() {}
                     17: 
                     18:                        int api_version() { return SQL_DRIVER_API_VERSION; }
                     19:                        
                     20:                        //...
                     21:                };
                     22: 
                     23:                extern "C" SQL_Driver *create() {
                     24:                        return new X_SQL_Driver();
                     25:                }       
                     26:        @endcode
                     27: */
                     28: 
                     29: #ifndef PA_SQL_DRIVER_H
                     30: #define PA_SQL_DRIVER_H
                     31: 
1.2       paf        32: #include <sys/types.h>
1.1       paf        33: 
                     34: /// service functions for SQL driver to use
                     35: class Services_for_SQL_driver {
                     36: public:
                     37:        /// allocates some bytes on pool
                     38:        virtual void *malloc(size_t size) =0;
                     39:        /// allocates some bytes clearing them with zeros
                     40:        virtual void *calloc(size_t size) =0;
                     41:        /// throw exception
                     42:        virtual void _throw(const char *comment) =0;
                     43: };
                     44: 
                     45: #define SQL_DRIVER_API_VERSION 0x0300
                     46: 
                     47: /// SQL driver API
                     48: class SQL_Driver {
                     49: public:
                     50: 
1.2       paf        51:        struct Cell {
                     52:                void *ptr;
                     53:                size_t size;
                     54:        };
                     55: 
                     56: public:
                     57: 
1.1       paf        58:        /// assignes services to driver. you can not use driver until this
                     59:        void set_services(Services_for_SQL_driver *aservices) { fservices=aservices; }
                     60: 
                     61:        SQL_Driver() :
                     62:                fservices(0) {
                     63:        }
                     64:        /// get api version
                     65:        virtual int api_version() =0;
                     66:        /// connect. @returns true+'connection' on success. 'error' on failure
                     67:        virtual void connect(char *url, void **connection) =0;
                     68:        virtual void disconnect(void *connection) =0;
                     69:        virtual void commit(void *connection) =0;
                     70:        virtual void rollback(void *connection) =0;
1.3       paf        71:        /// @returns true to indicate that connection still alive 
                     72:        virtual bool ping(void *connection) =0;
1.4     ! paf        73:        /// encodes the string in 'from' to an escaped SQL string
        !            74:        virtual unsigned int quote(void *connection,
        !            75:                char *to, const char *from, unsigned int length) =0;
1.2       paf        76:        virtual void query(void *connection,
1.3       paf        77:                const char *statement, unsigned long offset, unsigned long limit,
1.2       paf        78:                unsigned int *column_count, Cell **columns,
                     79:                unsigned long *row_count, Cell ***rows) =0;
1.1       paf        80:        /// log error message
                     81:        //static void log(Pool& pool, const char *fmt, ...);
                     82: 
                     83: protected:
                     84: 
                     85:        Services_for_SQL_driver *fservices;
                     86: };
                     87: 
                     88: typedef SQL_Driver *(*SQL_Driver_create_func)();
                     89: 
                     90: #endif

E-mail: