34 #ifndef _QORE_DS_PRIVATE_H 36 #define _QORE_DS_PRIVATE_H 38 #include "qore/intern/qore_dbi_private.h" 39 #include "qore/intern/QoreSQLStatement.h" 40 #include "qore/intern/DatasourceStatementHelper.h" 44 typedef std::set<QoreSQLStatement*> stmt_set_t;
46 hashdecl qore_ds_private {
53 bool active_transaction;
56 bool connection_aborted;
57 bool keep_lock =
false;
64 std::string p_username,
87 DatasourceStatementHelper* dsh;
89 DLLLOCAL qore_ds_private(
Datasource* n_ds,
DBIDriver* ndsl, DatasourceStatementHelper* dsh) : ds(n_ds), in_transaction(false), active_transaction(false), isopen(false), autocommit(false), connection_aborted(false), dsl(ndsl), qorecharset(
QCS_DEFAULT), private_data(nullptr), p_port(0), port(0), opt(new
QoreHashNode(autoTypeInfo)), event_queue(nullptr), dsh(dsh) {
92 DLLLOCAL qore_ds_private(
const qore_ds_private& old,
Datasource* n_ds, DatasourceStatementHelper* dsh) :
93 ds(n_ds), in_transaction(false), active_transaction(false), isopen(false),
94 autocommit(old.autocommit), connection_aborted(false), dsl(old.dsl),
96 p_username(old.p_username), p_password(old.p_password),
97 p_dbname(old.p_dbname), p_db_encoding(old.p_db_encoding),
98 p_hostname(old.p_hostname), p_port(old.p_port),
101 opt(old.getCurrentOptionHash(true)),
102 event_queue(old.event_queue ? old.event_queue->queueRefSelf() : nullptr),
103 event_arg(old.event_arg.refSelf()),
107 DLLLOCAL ~qore_ds_private() {
108 assert(!private_data);
109 assert(stmt_set.empty());
115 event_queue->deref(&xsink);
118 DLLLOCAL
void setPendingConnectionValues(
const qore_ds_private *other) {
119 p_username = other->p_username;
120 p_password = other->p_password;
121 p_dbname = other->p_dbname;
122 p_hostname = other->p_hostname;
123 p_db_encoding = other->p_db_encoding;
124 autocommit = other->autocommit;
125 p_port = other->p_port;
128 DLLLOCAL
void setConnectionValues() {
130 username = p_username;
131 password = p_password;
132 hostname = p_hostname;
133 db_encoding = p_db_encoding;
137 DLLLOCAL
void statementExecuted(
int rc);
139 DLLLOCAL
void copyOptions(
const Datasource* ods);
146 return private_data ? qore_dbi_private::get(*dsl)->getOptionHash(ds) : opt->
hashRefSelf();
149 DLLLOCAL
QoreHashNode* getCurrentOptionHash(
bool ensure_hash =
false)
const;
157 event_queue->deref(xsink);
163 DLLLOCAL
QoreHashNode* getEventQueueHash(Queue*& q,
int event_code)
const {
168 if (!username.empty())
178 DLLLOCAL
void addStatement(QoreSQLStatement* stmt) {
180 assert(stmt_set.find(stmt) == stmt_set.end());
181 stmt_set.insert(stmt);
184 DLLLOCAL
void removeStatement(QoreSQLStatement* stmt) {
186 stmt_set_t::iterator i = stmt_set.find(stmt);
187 if (i != stmt_set.end())
194 transactionDone(
false,
true, xsink);
196 connection_aborted =
true;
204 transactionDone(
false,
false, xsink);
210 transactionDone(
false,
true, xsink);
214 DLLLOCAL
void transactionDone(
bool clear,
bool close,
ExceptionSink* xsink) {
216 for (stmt_set_t::iterator i = stmt_set.begin(), e = stmt_set.end(); i != e; ++i) {
218 (*i)->transactionDone(clear, close, xsink);
227 in_transaction =
false;
228 active_transaction =
false;
229 return qore_dbi_private::get(*dsl)->commit(ds, xsink);
235 in_transaction =
false;
236 active_transaction =
false;
237 return qore_dbi_private::get(*dsl)->rollback(ds, xsink);
241 int rc = commitIntern(xsink);
242 transactionDone(
true,
true, xsink);
247 int rc = rollbackIntern(xsink);
248 transactionDone(
true,
true, xsink);
252 DLLLOCAL
int close() {
255 qore_dbi_private::get(*dsl)->close(ds);
257 in_transaction =
false;
258 active_transaction =
false;
264 DLLLOCAL
void setStatementKeepLock(QoreSQLStatement* stmt) {
268 in_transaction =
true;
269 if (!active_transaction)
270 active_transaction =
true;
275 DLLLOCAL
bool keepLock() {
282 DLLLOCAL
static qore_ds_private*
get(
Datasource& ds) {
defines string encoding functions in Qore
Definition: QoreEncoding.h:83
This is the hash or associative list container type in Qore, dynamically allocated only...
Definition: QoreHashNode.h:50
DLLEXPORT const QoreEncoding * QCS_DEFAULT
the default encoding for the Qore library
DLLEXPORT int setKeyValue(const char *key, QoreValue value, ExceptionSink *xsink)
sets the value of "key" to "value"
this class provides the internal link to the database driver for Qore's DBI layer ...
Definition: DBI.h:350
DLLEXPORT QoreHashNode * hashRefSelf() const
returns "this" with an incremented reference count
Qore's string value type, reference counted, dynamically-allocated only.
Definition: QoreStringNode.h:50
provides a safe and exception-safe way to hold locks in Qore, only to be used on the stack...
Definition: QoreThreadLock.h:128
the base class for accessing databases in Qore through a Qore DBI driver
Definition: Datasource.h:55
The main value class in Qore, designed to be passed by value.
Definition: QoreValue.h:262
container for holding Qore-language exception information and also for registering a "thread_exit" ca...
Definition: ExceptionSink.h:46
DLLEXPORT void deref(ExceptionSink *xsink)
decrements the reference count and calls derefImpl() if there_can_be_only_one is false, otherwise does nothing
provides a mutually-exclusive thread lock
Definition: QoreThreadLock.h:47
DLLEXPORT QoreValue refSelf() const
references the contained value if type == QV_Node, returns itself
DLLEXPORT void discard(ExceptionSink *xsink)
dereferences any contained AbstractQoreNode pointer and sets to 0; does not modify other values ...