32 #ifndef _QORE_QORE_DBI_PRIVATE_H
33 #define _QORE_QORE_DBI_PRIVATE_H
38 typedef std::map<int, void*> dbi_method_list_t;
40 const char* desc =
nullptr;
41 const QoreTypeInfo *typeInfo =
nullptr;
43 DLLLOCAL DbiOptInfo() {
46 DLLLOCAL DbiOptInfo(
const char* d,
const QoreTypeInfo* t) : desc(d), typeInfo(t) {
49 typedef std::map<const char*, DbiOptInfo, ltcstrcase> dbi_opt_map_t;
51 hashdecl dbi_driver_stmt {
55 bind_placeholders =
nullptr,
56 bind_values =
nullptr;
58 exec_describe =
nullptr;
59 q_dbi_stmt_fetch_row_t fetch_row =
nullptr;
60 q_dbi_stmt_fetch_rows_t fetch_rows =
nullptr;
61 q_dbi_stmt_fetch_columns_t fetch_columns =
nullptr;
62 q_dbi_stmt_fetch_row_t describe =
nullptr;
63 q_dbi_stmt_next_t next =
nullptr;
64 q_dbi_stmt_define_t define =
nullptr;
65 q_dbi_stmt_close_t close =
nullptr,
71 DLLLOCAL dbi_driver_stmt() {
75 hashdecl dbi_driver_opt {
76 q_dbi_option_set_t set =
nullptr;
77 q_dbi_option_get_t get =
nullptr;
79 DLLLOCAL dbi_driver_opt() {
83 hashdecl DBIDriverFunctions {
101 DLLLOCAL DBIDriverFunctions() {
115 DLLLOCAL ~DbiArgHelper() {
121 return nl ? nl : orig;
125 return nl ? nl : orig;
129 hashdecl OptInputHelper {
136 DLLLOCAL ~OptInputHelper() {
141 DLLLOCAL
operator bool()
const {
147 hashdecl qore_dbi_private {
150 DBIDriverFunctions f;
153 DLLLOCAL qore_dbi_private(
const char* nme,
const qore_dbi_mlist_private& methods,
int cps);
155 DLLLOCAL
bool hasStatementAPI()
const {
161 int rc = f.open(ds, xsink);
162 assert((!rc && !*xsink) || (rc && *xsink));
164 if (!rc && f.opt.set) {
167 f.opt.set(ds, hi.getKey(), hi.get(), xsink);
179 return f.select(ds, sql, *dargs, xsink);
184 return f.selectRows(ds, sql, *dargs, xsink);
191 return f.selectRow(ds, sql, *dargs, xsink);
194 ValueHolder res(f.selectRows(ds, sql, *dargs, xsink), xsink);
199 if (res->getType() !=
NT_HASH) {
200 assert(res->getType() ==
NT_LIST);
201 assert(res->getInternalNode()->reference_count() == 1);
203 assert(l->
size() <= 1);
205 assert(n.isNothing() || n.getType() ==
NT_HASH);
214 return f.execSQL(ds, sql, *dargs, xsink);
219 xsink->
raiseException(
"DBI-EXEC-RAW-SQL-ERROR",
"this driver does not implement the Datasource::execRawSQL() method");
222 return f.execRawSQL(ds, sql, xsink);
227 xsink->
raiseException(
"DBI-DESCRIBE-ERROR",
"this driver does not implement the Datasource::describe() method");
231 return f.describe(ds, sql, *dargs, xsink);
235 return f.commit(ds, xsink);
239 return f.rollback(ds, xsink);
243 if (f.begin_transaction)
244 return f.begin_transaction(ds, xsink);
251 if (!f.begin_transaction)
252 return f.commit(ds, xsink);
258 if (f.get_server_version)
259 return f.get_server_version(ds, xsink);
264 if (f.get_client_version)
265 return f.get_client_version(ds, xsink);
269 DLLLOCAL
int getCaps()
const {
275 DLLLOCAL
bool hasExecDefine()
const {
276 return (
bool)f.stmt.exec_describe;
281 return f.stmt.prepare(stmt, str, *dargs, xsink);
285 return f.stmt.prepare_raw(stmt, str, xsink);
289 return f.stmt.bind(stmt, l, xsink);
293 if (!f.stmt.bind_placeholders) {
294 xsink->
raiseException(
"SQLSTATEMENT-BIND-PLACEHOLDERS-ERROR",
"the '%s' driver does not require placeholder buffer specifications so the SQLStatement::bindPlaceholders() method is not supported", name);
298 return f.stmt.bind_placeholders(stmt, l, xsink);
302 return f.stmt.bind_values(stmt, l, xsink);
306 return f.stmt.define(stmt, xsink);
310 assert(f.stmt.exec_describe);
311 return f.stmt.exec_describe(stmt, xsink);
315 return f.stmt.exec(stmt, xsink);
319 return f.stmt.affected_rows(stmt, xsink);
323 return f.stmt.get_output(stmt, xsink);
327 return f.stmt.get_output_rows(stmt, xsink);
331 return f.stmt.fetch_row(stmt, xsink);
335 return f.stmt.fetch_rows(stmt, rows, xsink);
339 return f.stmt.fetch_columns(stmt, rows, xsink);
343 if (!f.stmt.describe) {
344 xsink->
raiseException(
"DBI-DESCRIBE-ERROR",
"this driver does not implement the SQLStatement::describe() method");
347 return f.stmt.describe(stmt, xsink);
351 return f.stmt.next(stmt, xsink);
355 return f.stmt.close(stmt, xsink);
359 return f.stmt.free ? f.stmt.free(stmt, xsink) : 0;
363 OptInputHelper oh(xsink, *
this, opt,
true, val);
367 return f.opt.set(ds, opt, oh.val, xsink);
371 OptInputHelper oh(xsink, *
this, opt);
375 return f.opt.get(ds, opt);
381 for (dbi_opt_map_t::const_iterator i = omap.begin(), e = omap.end(); i != e; ++i) {
385 h->
setKeyValue(
"value", f.opt.get(ds, i->first), 0);
395 for (dbi_opt_map_t::const_iterator i = omap.begin(), e = omap.end(); i != e; ++i) {
405 DLLLOCAL
static qore_dbi_private* get(
const DBIDriver& d) {
int(* q_dbi_rollback_t)(Datasource *ds, ExceptionSink *xsink)
signature for the DBI "rollback" method - must be defined in each DBI driver
Definition: DBI.h:200
QoreValue(* q_dbi_get_client_version_t)(const Datasource *ds, ExceptionSink *xsink)
signature for the "get_client_version" method
Definition: DBI.h:224
QoreHashNode *(* q_dbi_select_row_t)(Datasource *ds, const QoreString *str, const QoreListNode *args, ExceptionSink *xsink)
signature for the DBI "selectRow" method - must be defined in each DBI driver
Definition: DBI.h:165
#define DBI_CAP_HAS_NUMBER_SUPPORT
supports arbitrary-precision numeric support for binding and retrieving values; if this is not true t...
Definition: DBI.h:49
#define DBI_CAP_HAS_STATEMENT
supports the SQLStatement class (set automatically by the Qore library)
Definition: DBI.h:47
QoreValue(* q_dbi_exec_t)(Datasource *ds, const QoreString *str, const QoreListNode *args, ExceptionSink *xsink)
signature for the DBI "execSQL" method - must be defined in each DBI driver
Definition: DBI.h:175
int(* q_dbi_stmt_exec_t)(SQLStatement *stmt, ExceptionSink *xsink)
execute statement
Definition: DBI.h:244
int(* q_dbi_stmt_prepare_raw_t)(SQLStatement *stmt, const QoreString &str, ExceptionSink *xsink)
prepare statement with no bind parsing
Definition: DBI.h:234
QoreValue(* q_dbi_select_t)(Datasource *ds, const QoreString *str, const QoreListNode *args, ExceptionSink *xsink)
signature for the DBI "select" method - must be defined in each DBI driver
Definition: DBI.h:144
QoreValue(* q_dbi_select_rows_t)(Datasource *ds, const QoreString *str, const QoreListNode *args, ExceptionSink *xsink)
signature for the DBI "selectRows" method - must be defined in each DBI driver
Definition: DBI.h:154
QoreHashNode *(* q_dbi_stmt_get_output_t)(SQLStatement *stmt, ExceptionSink *xsink)
get output values, any row sets are returned as a hash of lists
Definition: DBI.h:254
int(* q_dbi_begin_transaction_t)(Datasource *ds, ExceptionSink *xsink)
signature for the DBI "begin_transaction" method, should only be defined for drivers needing this to ...
Definition: DBI.h:208
int(* q_dbi_stmt_bind_t)(SQLStatement *stmt, const QoreListNode &l, ExceptionSink *xsink)
bind input values and optionally describe output parameters
Definition: DBI.h:239
int(* q_dbi_commit_t)(Datasource *ds, ExceptionSink *xsink)
signature for the DBI "commit" method - must be defined in each DBI driver
Definition: DBI.h:192
int(* q_dbi_open_t)(Datasource *ds, ExceptionSink *xsink)
signature for the DBI "open" method - must be defined in each DBI driver
Definition: DBI.h:127
int(* q_dbi_close_t)(Datasource *ds)
signature for the DBI "close" method - must be defined in each DBI driver
Definition: DBI.h:134
QoreValue(* q_dbi_get_server_version_t)(Datasource *ds, ExceptionSink *xsink)
signature for the "get_server_version" method
Definition: DBI.h:216
int(* q_dbi_stmt_affected_rows_t)(SQLStatement *stmt, ExceptionSink *xsink)
get number of affected rows
Definition: DBI.h:249
QoreValue(* q_dbi_execraw_t)(Datasource *ds, const QoreString *str, ExceptionSink *xsink)
signature for the DBI "execRawSQL" method - must be defined in each DBI driver
Definition: DBI.h:184
QoreHashNode *(* q_dbi_describe_t)(Datasource *ds, const QoreString *str, const QoreListNode *args, ExceptionSink *xsink)
signature for the DBI "describe" method
Definition: DBI.h:279
QoreHashNode *(* q_dbi_stmt_get_output_rows_t)(SQLStatement *stmt, ExceptionSink *xsink)
get output values, any row sets are returned as a list of hashes
Definition: DBI.h:259
int(* q_dbi_stmt_prepare_t)(SQLStatement *stmt, const QoreString &str, const QoreListNode *args, ExceptionSink *xsink)
prepare statement and process placeholder specifications and bind parameters
Definition: DBI.h:229
DLLEXPORT void deref(ExceptionSink *xsink)
decrements the reference count and calls derefImpl() if there_can_be_only_one is false,...
constant iterator class for QoreHashNode, to be only created on the stack
Definition: QoreHashNode.h:577
this class provides the internal link to the database driver for Qore's DBI layer
Definition: DBI.h:354
the base class for accessing databases in Qore through a Qore DBI driver
Definition: Datasource.h:55
DLLEXPORT const QoreHashNode * getConnectOptions() const
returns the valid options for this driver with descriptions and current values for the current dataso...
container for holding Qore-language exception information and also for registering a "thread_exit" ca...
Definition: ExceptionSink.h:48
DLLEXPORT AbstractQoreNode * raiseException(const char *err, const char *fmt,...)
appends a Qore-language exception to the list
This is the hash or associative list container type in Qore, dynamically allocated only,...
Definition: QoreHashNode.h:50
DLLEXPORT int setKeyValue(const char *key, QoreValue value, ExceptionSink *xsink)
sets the value of "key" to "value"
This is the list container type in Qore, dynamically allocated only, reference counted.
Definition: QoreListNode.h:52
DLLEXPORT QoreValue shift()
returns the first element of the list, all other entries are moved down to fill up the first position...
DLLEXPORT size_t size() const
returns the number of elements in the list
Qore's string type supported by the QoreEncoding class.
Definition: QoreString.h:93
Qore's string value type, reference counted, dynamically-allocated only.
Definition: QoreStringNode.h:50
This is the public class for DBI drivers supporting Qore's new prepared statement API.
Definition: SQLStatement.h:38
holds an object and dereferences it in the destructor
Definition: QoreValue.h:476
const qore_type_t NT_LIST
type value for QoreListNode
Definition: node_types.h:50
const qore_type_t NT_HASH
type value for QoreHashNode
Definition: node_types.h:51
The main value class in Qore, designed to be passed by value.
Definition: QoreValue.h:275
DLLEXPORT void discard(ExceptionSink *xsink)
dereferences any contained AbstractQoreNode pointer and sets to 0; does not modify other values