00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024 #ifndef _QORE_DBI_H
00025
00026 #define _QORE_DBI_H
00027
00032
00033 #define DBI_CAP_NONE 0
00034 #define DBI_CAP_TIME_ZONE_SUPPORT (1 << 0)
00035 #define DBI_CAP_CHARSET_SUPPORT (1 << 1)
00036 #define DBI_CAP_TRANSACTION_MANAGEMENT (1 << 2)
00037 #define DBI_CAP_STORED_PROCEDURES (1 << 3)
00038 #define DBI_CAP_LOB_SUPPORT (1 << 4)
00039 #define DBI_CAP_BIND_BY_VALUE (1 << 5)
00040 #define DBI_CAP_BIND_BY_PLACEHOLDER (1 << 6)
00041 #define DBI_CAP_HAS_EXECRAW (1 << 7)
00042
00043 #define BN_PLACEHOLDER 0
00044 #define BN_VALUE 1
00045
00046 #define DBI_DEFAULT_STR_LEN 512
00047
00048
00049 #define QDBI_METHOD_OPEN 1
00050 #define QDBI_METHOD_CLOSE 2
00051 #define QDBI_METHOD_SELECT 3
00052 #define QDBI_METHOD_SELECT_ROWS 4
00053 #define QDBI_METHOD_EXEC 5
00054 #define QDBI_METHOD_COMMIT 6
00055 #define QDBI_METHOD_ROLLBACK 7
00056 #define QDBI_METHOD_BEGIN_TRANSACTION 8
00057 #define QDBI_METHOD_ABORT_TRANSACTION_START 9
00058 #define QDBI_METHOD_GET_SERVER_VERSION 10
00059 #define QDBI_METHOD_GET_CLIENT_VERSION 11
00060 #define QDBI_METHOD_EXECRAW 12
00061
00062 #define QDBI_VALID_CODES 13
00063
00064 class Datasource;
00065 class ExceptionSink;
00066 class QoreString;
00067 class QoreListNode;
00068 class AbstractQoreNode;
00069 class QoreHashNode;
00070 class QoreNamespace;
00071
00072
00073
00074
00075
00077
00081 typedef int (*q_dbi_open_t)(Datasource *ds, ExceptionSink *xsink);
00082
00084
00088 typedef int (*q_dbi_close_t)(Datasource *ds);
00089
00091
00098 typedef AbstractQoreNode *(*q_dbi_select_t)(Datasource *ds, const QoreString *str, const QoreListNode *args, ExceptionSink *xsink);
00099
00101
00108 typedef AbstractQoreNode *(*q_dbi_select_rows_t)(Datasource *ds, const QoreString *str, const QoreListNode *args, ExceptionSink *xsink);
00109
00111
00118 typedef AbstractQoreNode *(*q_dbi_exec_t)(Datasource *ds, const QoreString *str, const QoreListNode *args, ExceptionSink *xsink);
00119
00121
00127 typedef AbstractQoreNode *(*q_dbi_execraw_t)(Datasource *ds, const QoreString *str, ExceptionSink *xsink);
00128
00130
00135 typedef int (*q_dbi_commit_t)(Datasource *ds, ExceptionSink *xsink);
00136
00138
00143 typedef int (*q_dbi_rollback_t)(Datasource *ds, ExceptionSink *xsink);
00144
00146
00151 typedef int (*q_dbi_begin_transaction_t)(Datasource *ds, ExceptionSink *xsink);
00152
00154
00159 typedef int (*q_dbi_abort_transaction_start_t)(Datasource *ds, ExceptionSink *xsink);
00160
00162
00167 typedef AbstractQoreNode *(*q_dbi_get_server_version_t)(Datasource *ds, ExceptionSink *xsink);
00168
00170
00175 typedef AbstractQoreNode *(*q_dbi_get_client_version_t)(const Datasource *ds, ExceptionSink *xsink);
00176
00177 typedef std::pair<int, void *> qore_dbi_method_t;
00178
00179 typedef safe_dslist<qore_dbi_method_t> dbi_method_list_t;
00180
00182
00184 class qore_dbi_method_list
00185 {
00186 private:
00187 struct qore_dbi_mlist_private *priv;
00188
00189
00190 DLLLOCAL qore_dbi_method_list(const qore_dbi_method_list&);
00191 DLLLOCAL qore_dbi_method_list& operator=(const qore_dbi_method_list&);
00192
00193 public:
00194 DLLEXPORT qore_dbi_method_list();
00195 DLLEXPORT ~qore_dbi_method_list();
00196
00197
00198 DLLEXPORT void add(int code, q_dbi_open_t method);
00199
00200 DLLEXPORT void add(int code, q_dbi_close_t method);
00201
00202 DLLEXPORT void add(int code, q_dbi_select_t method);
00203
00204 DLLEXPORT void add(int code, q_dbi_execraw_t method);
00205
00206 DLLEXPORT void add(int code, q_dbi_get_server_version_t method);
00207
00208 DLLEXPORT void add(int code, q_dbi_get_client_version_t method);
00209
00210
00211 DLLLOCAL dbi_method_list_t *getMethods() const;
00212 };
00213
00215
00220 class DBIDriver {
00221 private:
00223 struct qore_dbi_private *priv;
00224
00226 DLLLOCAL DBIDriver(const DBIDriver&);
00228 DLLLOCAL DBIDriver& operator=(const DBIDriver&);
00229
00230 public:
00232
00235 DLLEXPORT const char *getName() const;
00236
00237 DLLLOCAL DBIDriver(const char *name, const dbi_method_list_t &methods, int cps);
00238 DLLLOCAL ~DBIDriver();
00239 DLLLOCAL int init(Datasource *ds, ExceptionSink *xsink);
00240 DLLLOCAL int close(Datasource *ds);
00241 DLLLOCAL AbstractQoreNode *select(Datasource *ds, const QoreString *sql, const QoreListNode *args, ExceptionSink *xsink);
00242 DLLLOCAL AbstractQoreNode *selectRows(Datasource *ds, const QoreString *sql, const QoreListNode *args, ExceptionSink *xsink);
00243 DLLLOCAL AbstractQoreNode *execSQL(Datasource *ds, const QoreString *sql, const QoreListNode *args, ExceptionSink *xsink);
00244 DLLLOCAL AbstractQoreNode *execRawSQL(Datasource *ds, const QoreString *sql, ExceptionSink *xsink);
00245 DLLLOCAL int commit(Datasource *, ExceptionSink *xsink);
00246 DLLLOCAL int rollback(Datasource *, ExceptionSink *xsink);
00247 DLLLOCAL int autoCommit(Datasource *, ExceptionSink *xsink);
00248 DLLLOCAL int beginTransaction(Datasource *, ExceptionSink *xsink);
00249 DLLLOCAL int abortTransactionStart(Datasource *, ExceptionSink *xsink);
00250 DLLLOCAL AbstractQoreNode *getServerVersion(Datasource *, ExceptionSink *xsink);
00251 DLLLOCAL AbstractQoreNode *getClientVersion(const Datasource *, ExceptionSink *xsink);
00252
00253 DLLLOCAL int getCaps() const;
00254 DLLLOCAL QoreListNode *getCapList() const;
00255 };
00256
00257 struct qore_dbi_dlist_private;
00258
00260
00264 class DBIDriverList
00265 {
00266 private:
00268 struct qore_dbi_dlist_private *priv;
00269
00270 DLLLOCAL DBIDriver *find_intern(const char *name) const;
00271
00272 public:
00274
00280 DLLEXPORT class DBIDriver *registerDriver(const char *name, const struct qore_dbi_method_list &methods, int caps);
00281
00283
00288 DLLEXPORT DBIDriver *find(const char *name) const;
00289
00291
00297 DLLEXPORT DBIDriver *find(const char *name, ExceptionSink *xsink) const;
00298
00299 DLLLOCAL DBIDriverList();
00300 DLLLOCAL ~DBIDriverList();
00301 DLLLOCAL QoreListNode *getDriverList() const;
00302 };
00303
00305 DLLEXPORT extern DBIDriverList DBI;
00306
00308 DLLEXPORT QoreHashNode *parseDatasource(const char *ds, ExceptionSink *xsink);
00309
00311 DLLEXPORT void DBI_concat_numeric(QoreString *str, const AbstractQoreNode *v);
00312
00314
00317 DLLEXPORT int DBI_concat_string(QoreString *str, const AbstractQoreNode *v, ExceptionSink *xsink);
00318
00319 DLLLOCAL void init_dbi_functions();
00320 DLLLOCAL QoreNamespace *getSQLNamespace();
00321
00322 #endif // _QORE_DBI_H