Annotation of parser3/src/sql/pa_sql_driver.h, revision 1.10
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.10 ! parser 8: $Id: pa_sql_driver.h,v 1.9 2001/05/17 08:42:22 parser 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
1.7 paf 35: class SQL_Driver_services {
1.1 paf 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:
1.6 paf 45: #define SQL_DRIVER_API_VERSION 0x0301
1.1 paf 46:
47: /// SQL driver API
48: class SQL_Driver {
49: public:
50:
1.8 paf 51: /// row cell & column title storage
1.2 paf 52: struct Cell {
53: void *ptr;
54: size_t size;
55: };
56:
57: public:
58:
1.10 ! parser 59: SQL_Driver() {}
1.1 paf 60: /// get api version
61: virtual int api_version() =0;
1.6 paf 62: /// initialize driver by loading sql dynamic link library
63: virtual const char *initialize(const char *dlopen_file_spec) =0;
1.9 parser 64: /** connect to sql database using
65: @param used_only_to_connect_url
66: format is driver specific
67: WARNING: must be used only to connect, for buffer doesn't live long enough
68:
69: @returns true+'connection' on success. 'error' on failure
70: */
1.10 ! parser 71: virtual void connect(char *used_only_in_connect_url_cstr,
! 72: SQL_Driver_services& services, void **connection) =0;
! 73: virtual void disconnect(
! 74: SQL_Driver_services& services, void *connection) =0;
! 75: virtual void commit(
! 76: SQL_Driver_services& services, void *connection) =0;
! 77: virtual void rollback(
! 78: SQL_Driver_services& services, void *connection) =0;
1.3 paf 79: /// @returns true to indicate that connection still alive
1.10 ! parser 80: virtual bool ping(
! 81: SQL_Driver_services& services, void *connection) =0;
1.4 paf 82: /// encodes the string in 'from' to an escaped SQL string
1.10 ! parser 83: virtual unsigned int quote(
! 84: SQL_Driver_services& services, void *connection,
1.4 paf 85: char *to, const char *from, unsigned int length) =0;
1.10 ! parser 86: virtual void query(
! 87: SQL_Driver_services& services, void *connection,
1.3 paf 88: const char *statement, unsigned long offset, unsigned long limit,
1.2 paf 89: unsigned int *column_count, Cell **columns,
90: unsigned long *row_count, Cell ***rows) =0;
1.1 paf 91: /// log error message
92: //static void log(Pool& pool, const char *fmt, ...);
93:
94: };
95:
96: typedef SQL_Driver *(*SQL_Driver_create_func)();
97:
98: #endif
E-mail: