00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023 #ifndef _QORE_DBI_H
00024
00025 #define _QORE_DBI_H
00026
00031
00032 #define DBI_CAP_NONE 0
00033 #define DBI_CAP_CHARSET_SUPPORT (1 << 1)
00034 #define DBI_CAP_TRANSACTION_MANAGEMENT (1 << 2)
00035 #define DBI_CAP_STORED_PROCEDURES (1 << 3)
00036 #define DBI_CAP_LOB_SUPPORT (1 << 4)
00037 #define DBI_CAP_BIND_BY_VALUE (1 << 5)
00038 #define DBI_CAP_BIND_BY_PLACEHOLDER (1 << 6)
00039
00040 #define BN_PLACEHOLDER 0
00041 #define BN_VALUE 1
00042
00043 #define DBI_DEFAULT_STR_LEN 512
00044
00045
00046 #define QDBI_METHOD_OPEN 1
00047 #define QDBI_METHOD_CLOSE 2
00048 #define QDBI_METHOD_SELECT 3
00049 #define QDBI_METHOD_SELECT_ROWS 4
00050 #define QDBI_METHOD_EXEC 5
00051 #define QDBI_METHOD_COMMIT 6
00052 #define QDBI_METHOD_ROLLBACK 7
00053 #define QDBI_METHOD_BEGIN_TRANSACTION 8
00054 #define QDBI_METHOD_ABORT_TRANSACTION_START 9
00055 #define QDBI_METHOD_GET_SERVER_VERSION 10
00056 #define QDBI_METHOD_GET_CLIENT_VERSION 11
00057
00058 #define QDBI_VALID_CODES 12
00059
00060 class Datasource;
00061 class ExceptionSink;
00062 class QoreString;
00063 class QoreListNode;
00064 class AbstractQoreNode;
00065 class QoreHashNode;
00066 class QoreNamespace;
00067
00068
00069
00070
00071
00073
00077 typedef int (*q_dbi_open_t)(Datasource *ds, ExceptionSink *xsink);
00078
00080
00084 typedef int (*q_dbi_close_t)(Datasource *ds);
00085
00087
00094 typedef AbstractQoreNode *(*q_dbi_select_t)(Datasource *ds, const QoreString *str, const QoreListNode *args, ExceptionSink *xsink);
00095
00097
00104 typedef AbstractQoreNode *(*q_dbi_select_rows_t)(Datasource *ds, const QoreString *str, const QoreListNode *args, ExceptionSink *xsink);
00105
00107
00114 typedef AbstractQoreNode *(*q_dbi_exec_t)(Datasource *ds, const QoreString *str, const QoreListNode *args, ExceptionSink *xsink);
00115
00117
00122 typedef int (*q_dbi_commit_t)(Datasource *ds, ExceptionSink *xsink);
00123
00125
00130 typedef int (*q_dbi_rollback_t)(Datasource *ds, ExceptionSink *xsink);
00131
00133
00138 typedef int (*q_dbi_begin_transaction_t)(Datasource *ds, ExceptionSink *xsink);
00139
00141
00146 typedef int (*q_dbi_abort_transaction_start_t)(Datasource *ds, ExceptionSink *xsink);
00147
00149
00154 typedef AbstractQoreNode *(*q_dbi_get_server_version_t)(Datasource *ds, ExceptionSink *xsink);
00155
00157
00162 typedef AbstractQoreNode *(*q_dbi_get_client_version_t)(const Datasource *ds, ExceptionSink *xsink);
00163
00164 typedef std::pair<int, void *> qore_dbi_method_t;
00165
00166 typedef safe_dslist<qore_dbi_method_t> dbi_method_list_t;
00167
00169
00171 class qore_dbi_method_list
00172 {
00173 private:
00174 struct qore_dbi_mlist_private *priv;
00175
00176
00177 DLLLOCAL qore_dbi_method_list(const qore_dbi_method_list&);
00178 DLLLOCAL qore_dbi_method_list& operator=(const qore_dbi_method_list&);
00179
00180 public:
00181 DLLEXPORT qore_dbi_method_list();
00182 DLLEXPORT ~qore_dbi_method_list();
00183
00184
00185 DLLEXPORT void add(int code, q_dbi_open_t method);
00186
00187 DLLEXPORT void add(int code, q_dbi_close_t method);
00188
00189 DLLEXPORT void add(int code, q_dbi_select_t method);
00190
00191 DLLEXPORT void add(int code, q_dbi_get_server_version_t method);
00192
00193 DLLEXPORT void add(int code, q_dbi_get_client_version_t method);
00194
00195
00196 DLLLOCAL dbi_method_list_t *getMethods() const;
00197 };
00198
00200
00205 class DBIDriver {
00206 private:
00208 struct qore_dbi_private *priv;
00209
00211 DLLLOCAL DBIDriver(const DBIDriver&);
00213 DLLLOCAL DBIDriver& operator=(const DBIDriver&);
00214
00215 public:
00217
00220 DLLEXPORT const char *getName() const;
00221
00222 DLLLOCAL DBIDriver(const char *name, const dbi_method_list_t &methods, int cps);
00223 DLLLOCAL ~DBIDriver();
00224 DLLLOCAL int init(Datasource *ds, ExceptionSink *xsink);
00225 DLLLOCAL int close(Datasource *ds);
00226 DLLLOCAL AbstractQoreNode *select(Datasource *ds, const QoreString *sql, const QoreListNode *args, ExceptionSink *xsink);
00227 DLLLOCAL AbstractQoreNode *selectRows(Datasource *ds, const QoreString *sql, const QoreListNode *args, ExceptionSink *xsink);
00228 DLLLOCAL AbstractQoreNode *execSQL(Datasource *ds, const QoreString *sql, const QoreListNode *args, ExceptionSink *xsink);
00229 DLLLOCAL int commit(Datasource *, ExceptionSink *xsink);
00230 DLLLOCAL int rollback(Datasource *, ExceptionSink *xsink);
00231 DLLLOCAL int autoCommit(Datasource *, ExceptionSink *xsink);
00232 DLLLOCAL int beginTransaction(Datasource *, ExceptionSink *xsink);
00233 DLLLOCAL int abortTransactionStart(Datasource *, ExceptionSink *xsink);
00234 DLLLOCAL AbstractQoreNode *getServerVersion(Datasource *, ExceptionSink *xsink);
00235 DLLLOCAL AbstractQoreNode *getClientVersion(const Datasource *, ExceptionSink *xsink);
00236
00237 DLLLOCAL int getCaps() const;
00238 DLLLOCAL QoreListNode *getCapList() const;
00239 };
00240
00241 struct qore_dbi_dlist_private;
00242
00244
00248 class DBIDriverList
00249 {
00250 private:
00252 struct qore_dbi_dlist_private *priv;
00253
00254 DLLLOCAL DBIDriver *find_intern(const char *name) const;
00255
00256 public:
00258
00264 DLLEXPORT class DBIDriver *registerDriver(const char *name, const struct qore_dbi_method_list &methods, int caps);
00265
00267
00272 DLLEXPORT DBIDriver *find(const char *name) const;
00273
00275
00281 DLLEXPORT DBIDriver *find(const char *name, ExceptionSink *xsink) const;
00282
00283 DLLLOCAL DBIDriverList();
00284 DLLLOCAL ~DBIDriverList();
00285 DLLLOCAL QoreListNode *getDriverList() const;
00286 };
00287
00289 DLLEXPORT extern DBIDriverList DBI;
00290
00292 DLLEXPORT QoreHashNode *parseDatasource(const char *ds, ExceptionSink *xsink);
00293
00295 DLLEXPORT void DBI_concat_numeric(QoreString *str, const AbstractQoreNode *v);
00296
00298
00301 DLLEXPORT int DBI_concat_string(QoreString *str, const AbstractQoreNode *v, ExceptionSink *xsink);
00302
00303 DLLLOCAL void init_dbi_functions();
00304 DLLLOCAL QoreNamespace *getSQLNamespace();
00305
00306 #endif // _QORE_DBI_H