Annotation of parser3/src/sql/pa_sql_driver.h, revision 1.20
1.1 paf 1: /** @file
2: Parser: sql driver interface.
3:
4: Copyright (c) 2001 ArtLebedev Group (http://www.artlebedev.com)
1.20 ! paf 5: Author: Alexander Petrosyan <paf@design.ru> (http://paf.design.ru)
1.1 paf 6:
1.20 ! paf 7: $Id: pa_sql_driver.h,v 1.19 2001/10/29 08:05:37 paf Exp $
1.1 paf 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:
1.2 paf 31: #include <sys/types.h>
1.1 paf 32:
33: /// service functions for SQL driver to use
1.7 paf 34: class SQL_Driver_services {
1.1 paf 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;
1.19 paf 40: /// prepare throw exception
1.1 paf 41: virtual void _throw(const char *comment) =0;
1.19 paf 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;
1.1 paf 47: };
48:
1.19 paf 49: #define SQL_DRIVER_API_VERSION 0x0100
1.15 parser 50: #define SQL_DRIVER_CREATE create
1.16 parser 51: #define SQL_DRIVER_CREATE_NAME "create" /* could not figure out how to # it :( */
1.11 parser 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: };
1.1 paf 61:
62: /// SQL driver API
63: class SQL_Driver {
64: public:
65:
1.10 parser 66: SQL_Driver() {}
1.1 paf 67: /// get api version
68: virtual int api_version() =0;
1.6 paf 69: /// initialize driver by loading sql dynamic link library
70: virtual const char *initialize(const char *dlopen_file_spec) =0;
1.9 parser 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: */
1.10 parser 78: virtual void connect(char *used_only_in_connect_url_cstr,
79: SQL_Driver_services& services, void **connection) =0;
1.13 parser 80: virtual void disconnect(void *connection) =0;
1.10 parser 81: virtual void commit(
82: SQL_Driver_services& services, void *connection) =0;
83: virtual void rollback(
84: SQL_Driver_services& services, void *connection) =0;
1.3 paf 85: /// @returns true to indicate that connection still alive
1.10 parser 86: virtual bool ping(
87: SQL_Driver_services& services, void *connection) =0;
1.4 paf 88: /// encodes the string in 'from' to an escaped SQL string
1.10 parser 89: virtual unsigned int quote(
90: SQL_Driver_services& services, void *connection,
1.4 paf 91: char *to, const char *from, unsigned int length) =0;
1.10 parser 92: virtual void query(
93: SQL_Driver_services& services, void *connection,
1.3 paf 94: const char *statement, unsigned long offset, unsigned long limit,
1.11 parser 95: SQL_Driver_query_event_handlers& handlers) =0;
1.1 paf 96: };
97:
98: typedef SQL_Driver *(*SQL_Driver_create_func)();
99:
100: #endif
E-mail: