32#ifndef _QORE_QORE_DBI_PRIVATE_H
33#define _QORE_QORE_DBI_PRIVATE_H
38typedef 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) {
49typedef std::map<const char*, DbiOptInfo, ltcstrcase> dbi_opt_map_t;
51hashdecl 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() {
75hashdecl dbi_driver_opt {
76 q_dbi_option_set_t set =
nullptr;
77 q_dbi_option_get_t get =
nullptr;
79 DLLLOCAL dbi_driver_opt() {
83hashdecl DBIDriverFunctions {
102 DLLLOCAL DBIDriverFunctions() {
116 DLLLOCAL ~DbiArgHelper() {
122 return nl ? nl : orig;
126 return nl ? nl : orig;
130hashdecl OptInputHelper {
137 DLLLOCAL ~OptInputHelper() {
142 DLLLOCAL
operator bool()
const {
148hashdecl qore_dbi_private {
151 DBIDriverFunctions f;
154 DLLLOCAL qore_dbi_private(
const char* nme,
const qore_dbi_mlist_private& methods,
int cps);
156 DLLLOCAL
bool hasStatementAPI()
const {
162 int rc = f.open(ds, xsink);
163 assert((!rc && !*xsink) || (rc && *xsink));
165 if (!rc && f.opt.set) {
168 f.opt.set(ds, hi.getKey(), hi.get(), xsink);
180 return f.select(ds, sql, *dargs, xsink);
185 return f.selectRows(ds, sql, *dargs, xsink);
192 return f.selectRow(ds, sql, *dargs, xsink);
195 ValueHolder res(f.selectRows(ds, sql, *dargs, xsink), xsink);
200 if (res->getType() !=
NT_HASH) {
201 assert(res->getType() ==
NT_LIST);
202 assert(res->getInternalNode()->reference_count() == 1);
204 assert(l->
size() <= 1);
215 return f.execSQL(ds, sql, *dargs, xsink);
220 xsink->
raiseException(
"DBI-EXEC-RAW-SQL-ERROR",
"this driver does not implement the Datasource::execRawSQL() method");
223 return f.execRawSQL(ds, sql, xsink);
228 xsink->
raiseException(
"DBI-DESCRIBE-ERROR",
"this driver does not implement the Datasource::describe() method");
232 return f.describe(ds, sql, *dargs, xsink);
236 return f.commit(ds, xsink);
240 return f.rollback(ds, xsink);
244 if (f.begin_transaction)
245 return f.begin_transaction(ds, xsink);
252 if (!f.begin_transaction)
253 return f.commit(ds, xsink);
259 if (f.get_server_version)
260 return f.get_server_version(ds, xsink);
265 if (f.get_client_version)
266 return f.get_client_version(ds, xsink);
271 if (f.get_driver_real_name) {
272 return f.get_driver_real_name(ds, xsink);
277 DLLLOCAL
int getCaps()
const {
283 DLLLOCAL
bool hasExecDefine()
const {
284 return (
bool)f.stmt.exec_describe;
289 return f.stmt.prepare(stmt, str, *dargs, xsink);
293 return f.stmt.prepare_raw(stmt, str, xsink);
297 return f.stmt.bind(stmt, l, xsink);
301 if (!f.stmt.bind_placeholders) {
302 xsink->
raiseException(
"SQLSTATEMENT-BIND-PLACEHOLDERS-ERROR",
"the '%s' driver does not require placeholder buffer specifications so the SQLStatement::bindPlaceholders() method is not supported", name);
306 return f.stmt.bind_placeholders(stmt, l, xsink);
310 return f.stmt.bind_values(stmt, l, xsink);
314 return f.stmt.define(stmt, xsink);
318 assert(f.stmt.exec_describe);
319 return f.stmt.exec_describe(stmt, xsink);
323 return f.stmt.exec(stmt, xsink);
327 return f.stmt.affected_rows(stmt, xsink);
331 return f.stmt.get_output(stmt, xsink);
335 return f.stmt.get_output_rows(stmt, xsink);
339 return f.stmt.fetch_row(stmt, xsink);
343 return f.stmt.fetch_rows(stmt, rows, xsink);
347 return f.stmt.fetch_columns(stmt, rows, xsink);
351 if (!f.stmt.describe) {
352 xsink->
raiseException(
"DBI-DESCRIBE-ERROR",
"this driver does not implement the SQLStatement::describe() method");
355 return f.stmt.describe(stmt, xsink);
359 return f.stmt.next(stmt, xsink);
363 return f.stmt.close(stmt, xsink);
367 return f.stmt.free ? f.stmt.free(stmt, xsink) : 0;
371 OptInputHelper oh(xsink, *
this, opt,
true, val);
375 return f.opt.set(ds, opt, oh.val, xsink);
379 OptInputHelper oh(xsink, *
this, opt);
383 return f.opt.get(ds, opt);
389 for (dbi_opt_map_t::const_iterator i = omap.begin(), e = omap.end(); i != e; ++i) {
393 h->
setKeyValue(
"value", f.opt.get(ds, i->first), 0);
403 for (dbi_opt_map_t::const_iterator i = omap.begin(), e = omap.end(); i != e; ++i) {
413 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:203
QoreValue(* q_dbi_get_client_version_t)(const Datasource *ds, ExceptionSink *xsink)
signature for the "get_client_version" method
Definition: DBI.h:227
#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:51
#define DBI_CAP_HAS_STATEMENT
supports the SQLStatement class (set automatically by the Qore library)
Definition: DBI.h:49
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:178
int(* q_dbi_stmt_exec_t)(SQLStatement *stmt, ExceptionSink *xsink)
execute statement
Definition: DBI.h:255
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:168
QoreStringNode *(* q_dbi_get_driver_real_name_t)(Datasource *ds, ExceptionSink *xsink)
signature for the "get_driver_real_name" method
Definition: DBI.h:235
int(* q_dbi_stmt_prepare_raw_t)(SQLStatement *stmt, const QoreString &str, ExceptionSink *xsink)
prepare statement with no bind parsing
Definition: DBI.h:245
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:147
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:157
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:265
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:211
int(* q_dbi_stmt_bind_t)(SQLStatement *stmt, const QoreListNode &l, ExceptionSink *xsink)
bind input values and optionally describe output parameters
Definition: DBI.h:250
QoreHashNode *(* q_dbi_describe_t)(Datasource *ds, const QoreString *str, const QoreListNode *args, ExceptionSink *xsink)
signature for the DBI "describe" method
Definition: DBI.h:290
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:195
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:130
int(* q_dbi_close_t)(Datasource *ds)
signature for the DBI "close" method - must be defined in each DBI driver
Definition: DBI.h:137
QoreValue(* q_dbi_get_server_version_t)(Datasource *ds, ExceptionSink *xsink)
signature for the "get_server_version" method
Definition: DBI.h:219
int(* q_dbi_stmt_affected_rows_t)(SQLStatement *stmt, ExceptionSink *xsink)
get number of affected rows
Definition: DBI.h:260
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:270
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:187
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:240
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:590
this class provides the internal link to the database driver for Qore's DBI layer
Definition: DBI.h:367
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...
DLLEXPORT const char * getDriverName() const
returns the name of the current Qore DBI driver
container for holding Qore-language exception information and also for registering a "thread_exit" ca...
Definition: ExceptionSink.h:50
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
DLLLOCAL detail::QoreValueCastHelper< T >::Result get()
returns the value as the given type
Definition: QoreValue.h:214
DLLEXPORT qore_type_t getType() const
returns the type of value contained
DLLEXPORT bool isNothing() const
returns true if the object contains NOTHING
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:487
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:276
DLLEXPORT void discard(ExceptionSink *xsink)
dereferences any contained AbstractQoreNode pointer and sets to 0; does not modify other values