Annotation of parser3/src/sql/pa_sql_driver.h, revision 1.21
1.21 ! paf 1: /** @file
! 2: Parser: sql driver interface.
! 3:
! 4: Copyright (c) 2001 ArtLebedev Group (http://www.artlebedev.com)
! 5: Author: Alexander Petrosyan <paf@design.ru> (http://paf.design.ru)
! 6:
! 7: $Id: pa_sql_driver.h,v 1.20 2001/11/05 11:46:29 paf Exp $
! 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:
! 49: #define SQL_DRIVER_API_VERSION 0x0002
! 50: #define SQL_DRIVER_CREATE create
! 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: SQL_Driver() {}
! 67: /// get api version
! 68: virtual int api_version() =0;
! 69: /// initialize driver by loading sql dynamic link library
! 70: virtual const char *initialize(char *dlopen_file_spec) =0;
! 71: /** connect to sql database using
! 72: @param used_only_to_connect_url
! 73: format is driver specific
! 74: WARNING: must be used only to connect, for buffer doesn't live long enough
! 75:
! 76: @returns true+'connection' on success. 'error' on failure
! 77: */
! 78: virtual void connect(char *used_only_in_connect_url_cstr,
! 79: SQL_Driver_services& services, void **connection) =0;
! 80: virtual void disconnect(void *connection) =0;
! 81: virtual void commit(
! 82: SQL_Driver_services& services, void *connection) =0;
! 83: virtual void rollback(
! 84: SQL_Driver_services& services, void *connection) =0;
! 85: /// @returns true to indicate that connection still alive
! 86: virtual bool ping(
! 87: SQL_Driver_services& services, void *connection) =0;
! 88: /// encodes the string in 'from' to an escaped SQL string
! 89: virtual unsigned int quote(
! 90: SQL_Driver_services& services, void *connection,
! 91: char *to, const char *from, unsigned int length) =0;
! 92: virtual void query(
! 93: SQL_Driver_services& services, void *connection,
! 94: const char *statement, unsigned long offset, unsigned long limit,
! 95: SQL_Driver_query_event_handlers& handlers) =0;
! 96: };
! 97:
! 98: typedef SQL_Driver *(*SQL_Driver_create_func)();
! 99:
! 100: #endif
E-mail: