Annotation of parser3/src/sql/pa_sql_driver.h, revision 1.30
1.22 paf 1: /** @file
2: Parser: sql driver interface.
3:
1.25 paf 4: Copyright (c) 2001, 2002 ArtLebedev Group (http://www.artlebedev.com)
1.26 paf 5: Author: Alexandr Petrosian <paf@design.ru> (http://paf.design.ru)
1.22 paf 6:
7:
8: driver dynamic library must look like this:
9: @code
10: class X_SQL_Driver : public SQL_Driver {
11: public:
12:
13: X_SQL_Driver() : SQL_driver() {}
14:
15: int api_version() { return SQL_DRIVER_API_VERSION; }
16:
17: //...
18: };
19:
20: extern "C" SQL_Driver *create() {
21: return new X_SQL_Driver();
22: }
23: @endcode
24: */
25:
26: #ifndef PA_SQL_DRIVER_H
27: #define PA_SQL_DRIVER_H
1.27 paf 28:
1.30 ! paf 29: static const char* IDENT_SQL_DRIVER_H="$Date: 2002/12/09 11:07:40 $";
1.22 paf 30:
31: #include <sys/types.h>
32:
1.29 paf 33: #define SQL_DRIVER_API_VERSION 0x0004
34: #define SQL_DRIVER_CREATE create /* used in driver implementation */
35: #define SQL_DRIVER_CREATE_NAME "create" /* could not figure out how to # it :( */
36:
37: /// fields are freed elsewhere
38: class SQL_Exception {
39: friend class SQL_Driver_services_impl;
40:
41: bool fdefined;
42: const char *ftype;
43: const void *fproblem_source;
44: const char *fcomment;
45: public:
46: SQL_Exception():
47: fdefined(false) {}
48: SQL_Exception(
49: const char *atype,
50: const void *aproblem_source,
51: const char *acomment):
52: fdefined(true),
53: ftype(atype),
54: fproblem_source(aproblem_source),
55: fcomment(acomment) {}
56: SQL_Exception(const char *acomment):
57: fdefined(true),
58: ftype(0),
59: fproblem_source(0),
60: fcomment(acomment) {}
61: /*
62: SQL_Exception(const SQL_Exception& src) :
63: fdefined(src.fdefined),
64: ftype(src.ftype),
65: fproblem_source(src.fproblem_source),
66: fcomment(src.fcomment) {}
67: */
1.30 ! paf 68: const SQL_Exception& operator =(const SQL_Exception& src) {
1.29 paf 69: fdefined=src.fdefined;
70: ftype=src.ftype;
71: fproblem_source=src.fproblem_source;
72: fcomment=src.fcomment;
73: return *this;
74: }
75:
76: bool defined() { return fdefined; }
77: const char *type() { return ftype; }
78: const void *problem_source() { return fproblem_source; }
79: const char *comment() { return fcomment; }
80: };
81:
1.22 paf 82: /// service functions for SQL driver to use
83: class SQL_Driver_services {
84: public:
85: /// allocates some bytes on pool
86: virtual void *malloc(size_t size) =0;
87: /// allocates some bytes clearing them with zeros
88: virtual void *calloc(size_t size) =0;
89: /// prepare throw exception
1.29 paf 90: virtual void _throw(const SQL_Exception& e) =0;
1.22 paf 91: /// throw C++ exception from prepared
92: virtual void propagate_exception() =0;
1.29 paf 93: /// helper func
94: void _throw(const char *comment) { _throw(SQL_Exception(0, 0, comment)); }
1.22 paf 95: public:
96: /// regretrully public, because can't make stack frames: "nowhere to return to"
97: jmp_buf mark;
98: };
99:
100: /// events, occuring when SQL_Driver::query()-ing
101: class SQL_Driver_query_event_handlers {
102: public:
103: virtual void add_column(void *ptr, size_t size) =0;
104: virtual void before_rows() =0;
105: virtual void add_row() =0;
106: virtual void add_row_cell(void *ptr, size_t size) =0;
107: };
108:
109: /// SQL driver API
110: class SQL_Driver {
111: public:
112:
113: /// get api version
114: virtual int api_version() =0;
115: /// initialize driver by loading sql dynamic link library
116: virtual const char *initialize(char *dlopen_file_spec) =0;
117: /** connect to sql database using
118: @param used_only_to_connect_url
119: format is driver specific
120: WARNING: must be used only to connect, for buffer doesn't live long enough
121:
122: @returns true+'connection' on success. 'error' on failure
123: */
124: virtual void connect(char *used_only_in_connect_url_cstr,
125: SQL_Driver_services& services, void **connection) =0;
126: virtual void disconnect(void *connection) =0;
127: virtual void commit(
128: SQL_Driver_services& services, void *connection) =0;
129: virtual void rollback(
130: SQL_Driver_services& services, void *connection) =0;
131: /// @returns true to indicate that connection still alive
132: virtual bool ping(
133: SQL_Driver_services& services, void *connection) =0;
134: /// encodes the string in 'from' to an escaped SQL string
135: virtual unsigned int quote(
136: SQL_Driver_services& services, void *connection,
137: char *to, const char *from, unsigned int length) =0;
138: virtual void query(
139: SQL_Driver_services& services, void *connection,
140: const char *statement, unsigned long offset, unsigned long limit,
141: SQL_Driver_query_event_handlers& handlers) =0;
142: };
143:
144: typedef SQL_Driver *(*SQL_Driver_create_func)();
145:
146: #endif
E-mail: