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