Annotation of parser3/src/sql/pa_sql_driver.h, revision 1.8
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.8 ! paf 8: $Id: pa_sql_driver.h,v 1.7 2001/04/17 19:31:19 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
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.1 paf 59: /// assignes services to driver. you can not use driver until this
1.7 paf 60: void set_services(SQL_Driver_services *aservices) { services=aservices; }
1.1 paf 61:
62: SQL_Driver() :
1.5 paf 63: services(0) {
1.1 paf 64: }
65: /// get api version
66: virtual int api_version() =0;
1.6 paf 67: /// initialize driver by loading sql dynamic link library
68: virtual const char *initialize(const char *dlopen_file_spec) =0;
1.1 paf 69: /// connect. @returns true+'connection' on success. 'error' on failure
70: virtual void connect(char *url, void **connection) =0;
71: virtual void disconnect(void *connection) =0;
72: virtual void commit(void *connection) =0;
73: virtual void rollback(void *connection) =0;
1.3 paf 74: /// @returns true to indicate that connection still alive
75: virtual bool ping(void *connection) =0;
1.4 paf 76: /// encodes the string in 'from' to an escaped SQL string
77: virtual unsigned int quote(void *connection,
78: char *to, const char *from, unsigned int length) =0;
1.2 paf 79: virtual void query(void *connection,
1.3 paf 80: const char *statement, unsigned long offset, unsigned long limit,
1.2 paf 81: unsigned int *column_count, Cell **columns,
82: unsigned long *row_count, Cell ***rows) =0;
1.1 paf 83: /// log error message
84: //static void log(Pool& pool, const char *fmt, ...);
85:
86: protected:
87:
1.7 paf 88: SQL_Driver_services *services;
1.1 paf 89: };
90:
91: typedef SQL_Driver *(*SQL_Driver_create_func)();
92:
93: #endif
E-mail: