|
Qore Programming Language
0.9.16
|
39 #ifndef _QORE_MANAGEDDATASOURCE_H
40 #define _QORE_MANAGEDDATASOURCE_H
42 #include "qore/intern/DatasourceStatementHelper.h"
43 #include "qore/intern/QoreSQLStatement.h"
48 #define DEFAULT_TL_TIMEOUT 120000
51 friend class DatasourceActionHelper;
52 friend class DatasourceLockHelper;
65 DLLLOCAL
int startDBAction(
ExceptionSink* xsink,
bool& new_transaction);
67 DLLLOCAL
bool endDBActionIntern(
char cmd = DAH_NOCHANGE,
bool new_transaction =
false);
69 DLLLOCAL
bool endDBAction(
char cmd = DAH_NOCHANGE,
bool new_transaction =
false);
72 DLLLOCAL
int grabLockIntern();
73 DLLLOCAL
void grabLockUnconditionalIntern();
76 DLLLOCAL
void releaseLock();
77 DLLLOCAL
void releaseLockIntern();
78 DLLLOCAL
void forceReleaseLockIntern();
79 DLLLOCAL
void finish_transaction();
82 DLLLOCAL
virtual ~ManagedDatasource() {
86 DLLLOCAL ManagedDatasource(
DBIDriver *ndsl) :
Datasource(ndsl, this), tl_timeout_ms(DEFAULT_TL_TIMEOUT) {
89 DLLLOCAL ManagedDatasource(
const ManagedDatasource& old) :
Datasource(old, this), tl_timeout_ms(old.tl_timeout_ms) {
95 DLLLOCAL
virtual void deref();
123 DLLLOCAL
void setTransactionLockTimeout(
int t_ms);
124 DLLLOCAL
int getTransactionLockTimeout()
const;
128 using Datasource::setAutoCommit;
132 DLLLOCAL ManagedDatasource*
copy();
141 DLLLOCAL
int transactionTid()
const {
145 DLLLOCAL
bool currentThreadInTransaction()
const {
156 DLLLOCAL
virtual DatasourceStatementHelper* helperRefSelfImpl() {
162 DLLLOCAL
virtual void helperDestructorImpl(QoreSQLStatement* s,
ExceptionSink* xsink) {
167 if (!startDBAction(xsink, new_transaction))
171 return tid ==
q_gettid() ? this : 0;
177 if (cmd == DAH_RELEASE) {
180 return endDBAction(cmd, new_transaction) ? this : 0;
184 class DatasourceActionHelper {
186 ManagedDatasource& ds;
187 bool ok, new_transaction;
191 DLLLOCAL DatasourceActionHelper(ManagedDatasource& n_ds,
ExceptionSink* xsink,
char n_cmd = DAH_NOCHANGE) :
192 ds(n_ds), ok(n_cmd == DAH_NOCONN ? !ds.acquireLock(xsink) : !ds.startDBAction(xsink, new_transaction)), cmd(n_cmd) {
193 if (cmd == DAH_NOCONN) {
194 new_transaction =
false;
198 DLLLOCAL ~DatasourceActionHelper();
200 DLLLOCAL
bool newTransaction()
const {
return new_transaction; }
202 DLLLOCAL
operator bool()
const {
return ok; }
205 class DatasourceLockHelper {
207 ManagedDatasource& ds;
208 bool valid, had_lock;
211 DLLLOCAL DatasourceLockHelper(ManagedDatasource& n_ds,
ExceptionSink* xsink) : ds(n_ds) {
214 valid = !ds.grabLock(xsink);
219 DLLLOCAL ~DatasourceLockHelper() {
222 ds.releaseLockIntern();
227 DLLLOCAL
operator bool()
const {
return valid; }
230 #endif // _QORE_SQL_OBJECTS_DATASOURCE_H
DLLEXPORT Datasource * copy() const
returns a copy of this object with the same DBIDriver and pending connection values
DLLEXPORT void setPendingUsername(const char *u)
sets the username to be used for the next connection
DLLEXPORT QoreStringNode * getPendingDBName() const
returns the pending database (or schema) name for the next connection
DLLEXPORT void setPendingHostName(const char *h)
sets the hostname to be used for the next connection
DLLEXPORT void reset(ExceptionSink *xsink)
closes and opens the connection
The main value class in Qore, designed to be passed by value.
Definition: QoreValue.h:262
DLLEXPORT QoreStringNode * getPendingHostName() const
returns the pending host name for the next connection
DLLEXPORT QoreValue getOption(const char *opt, ExceptionSink *xsink)
Returns the current value for the given option.
DLLEXPORT QoreValue selectRows(const QoreString *query_str, const QoreListNode *args, ExceptionSink *xsink)
executes SQL throught the "selectRows" function of the DBI driver and returns the result,...
This is the hash or associative list container type in Qore, dynamically allocated only,...
Definition: QoreHashNode.h:50
DLLEXPORT void setPendingPort(int port)
sets the port number to be used for the next connection
DLLEXPORT void setEventQueue(Queue *q, QoreValue arg, ExceptionSink *xsink)
sets an event queue for datasource events
DLLEXPORT QoreStringNode * getPendingUsername() const
returns the pending username for the next connection
DLLEXPORT void setPendingDBName(const char *d)
sets the database (or schema) name to be used for the next connection
DLLLOCAL void ref()
increments the reference count of the object
Definition: AbstractPrivateData.h:53
DLLEXPORT int commit(ExceptionSink *xsink)
commits the current transaction to the database
DLLEXPORT int q_gettid() noexcept
returns the current TID number
DLLEXPORT int autoCommit(ExceptionSink *xsink)
called from subclasses when releasing the transaction lock
DLLEXPORT QoreHashNode * getConfigHash() const
returns a hash representing the configuration of the current object
This is the list container type in Qore, dynamically allocated only, reference counted.
Definition: QoreListNode.h:52
a thread condition class implementing a wrapper for pthread_cond_t
Definition: QoreCondition.h:45
DLLEXPORT QoreStringNode * getPendingDBEncoding() const
returns the pending database-specific character encoding name for the next connection
DLLEXPORT QoreValue getClientVersion(ExceptionSink *xsink) const
executes the "get_client_version" function of the driver, if any, and returns the result
DLLEXPORT void setPendingPassword(const char *p)
sets the password to be used for the next connection
DLLEXPORT QoreHashNode * describe(const QoreString *query_str, const QoreListNode *args, ExceptionSink *xsink)
executes SQL that returns a result set and then returns a hash description of the result set
DLLEXPORT QoreValue execRaw(const QoreString *query_str, const QoreListNode *args, ExceptionSink *xsink)
executes SQL throught the "execRaw" function of the DBI driver and returns the result,...
Qore's string type supported by the QoreEncoding class.
Definition: QoreString.h:81
base class for saving data using Qore's thread resource management system
Definition: AbstractThreadResource.h:51
DLLEXPORT void setPendingDBEncoding(const char *c)
sets the database-specific name of the character-encoding to be used for the next connection
DLLEXPORT QoreValue exec(const QoreString *query_str, const QoreListNode *args, ExceptionSink *xsink)
executes SQL throught the "exec" function of the DBI driver and returns the result,...
DLLEXPORT int beginTransaction(ExceptionSink *xsink)
container for holding Qore-language exception information and also for registering a "thread_exit" ca...
Definition: ExceptionSink.h:48
DLLEXPORT QoreStringNode * getConfigString() const
returns a string representing the configuration of the current object
DLLEXPORT QoreHashNode * getOptionHash() const
returns the valid options for this driver with descriptions and current values for the current dataso...
DLLEXPORT QoreStringNode * getPendingPassword() const
returns the pending password for the next connection
DLLEXPORT int rollback(ExceptionSink *xsink)
rolls back the current transaction to the database
DLLEXPORT int setOption(const char *opt, const QoreValue val, ExceptionSink *xsink)
sets an option for the datasource
DLLEXPORT QoreHashNode * selectRow(const QoreString *query_str, const QoreListNode *args, ExceptionSink *xsink)
executes SQL throught the "selectRow" function of the DBI driver and returns the result,...
virtual void cleanup(ExceptionSink *xsink)=0
this function is called when a thread terminates and a thread resource is still allocated to the thre...
provides a mutually-exclusive thread lock
Definition: QoreThreadLock.h:49
DLLEXPORT QoreValue getServerVersion(ExceptionSink *xsink)
executes the "get_server_version" function of the driver, if any, and returns the result,...
virtual DLLLOCAL void deref()
decrements the reference count of the object without the possibility of throwing a Qore-language exce...
Definition: AbstractPrivateData.h:67
DLLEXPORT int close()
closes the connection
DLLEXPORT int open(ExceptionSink *xsink)
opens a connection to the database
the base class for accessing databases in Qore through a Qore DBI driver
Definition: Datasource.h:55
DLLEXPORT QoreValue select(const QoreString *query_str, const QoreListNode *args, ExceptionSink *xsink)
executes SQL throught the "select" function of the DBI driver and returns the result,...
Qore's string value type, reference counted, dynamically-allocated only.
Definition: QoreStringNode.h:50
DLLEXPORT int getPendingPort() const
returns the pending port number for the next connection
this class provides the internal link to the database driver for Qore's DBI layer
Definition: DBI.h:350