Datasource.h
/* -*- mode: c++; indent-tabs-mode: nil -*- */
/*
Datasource.h
Qore Programming Language
Copyright (C) 2003 - 2020 Qore Technologies, s.r.o.
The Datasource class provides the low-level interface to Qore DBI drivers.
Permission is hereby granted, free of charge, to any person obtaining a
copy of this software and associated documentation files (the "Software"),
to deal in the Software without restriction, including without limitation
the rights to use, copy, modify, merge, publish, distribute, sublicense,
and/or sell copies of the Software, and to permit persons to whom the
Software is furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in
all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
DEALINGS IN THE SOFTWARE.
Note that the Qore library is released under a choice of three open-source
licenses: MIT (as above), LGPL 2+, or GPL 2+; see README-LICENSE for more
information.
*/
#ifndef _QORE_DATASOURCE_H
#define _QORE_DATASOURCE_H
#include <qore/QoreThreadLock.h>
#include <qore/QoreQueue.h>
#include <string>
class DBIDriver;
class DatasourceStatementHelper;
class Datasource {
friend class QoreSQLStatement;
friend struct qore_ds_private;
private:
struct qore_ds_private *priv; // private implementation
Datasource& operator=(const Datasource&) = delete;
DLLLOCAL QoreValue exec_internal(bool doBind, const QoreString* query_str, const QoreListNode* args, ExceptionSink* xsink);
protected:
DLLEXPORT void freeConnectionValues();
DLLEXPORT void setConnectionValues();
DLLEXPORT void setTransactionStatus(bool);
DLLEXPORT void setPendingConnectionValues(const Datasource* other);
DLLEXPORT int beginImplicitTransaction(ExceptionSink* xsink);
public:
DLLLOCAL Datasource(DBIDriver* driver, DatasourceStatementHelper* dsh);
DLLLOCAL Datasource(const Datasource& old, DatasourceStatementHelper* dsh);
DLLEXPORT Datasource(DBIDriver* driver);
/*
@deprecated do not use
*/
DLLEXPORT Datasource(const Datasource& old);
DLLEXPORT virtual ~Datasource();
DLLEXPORT bool getAutoCommit() const;
DLLEXPORT const char* getUsername() const;
DLLEXPORT const char* getPassword() const;
DLLEXPORT const char* getDBName() const;
DLLEXPORT const char* getDBEncoding() const;
DLLEXPORT const char* getOSEncoding() const;
DLLEXPORT const char* getHostName() const;
DLLEXPORT int getPort() const;
DLLEXPORT const std::string& getUsernameStr() const;
DLLEXPORT const std::string& getPasswordStr() const;
DLLEXPORT const std::string& getDBNameStr() const;
DLLEXPORT const std::string& getDBEncodingStr() const;
DLLEXPORT const std::string& getHostNameStr() const;
DLLEXPORT void* getPrivateData() const;
template <typename T>
DLLLOCAL T* getPrivateData() const {
return reinterpret_cast<T*>(getPrivateData());
}
template <typename T>
DLLLOCAL T& getPrivateDataRef() const {
return *getPrivateData<T>();
}
DLLEXPORT void setPrivateData(void* data);
DLLEXPORT void setDBEncoding(const char* name);
DLLEXPORT const QoreEncoding* getQoreEncoding() const;
DLLEXPORT void setQoreEncoding(const QoreEncoding* enc);
DLLEXPORT void setQoreEncoding(const char* name);
DLLEXPORT void setPendingUsername(const char* u);
DLLEXPORT void setPendingPassword(const char* p);
DLLEXPORT void setPendingDBName(const char* d);
DLLEXPORT void setPendingDBEncoding(const char* c);
DLLEXPORT void setPendingHostName(const char* h);
DLLEXPORT void setPendingPort(int port);
DLLEXPORT void setAutoCommit(bool ac);
DLLEXPORT int open(ExceptionSink* xsink);
DLLEXPORT QoreValue select(const QoreString* query_str, const QoreListNode* args, ExceptionSink* xsink);
DLLEXPORT QoreValue selectRows(const QoreString* query_str, const QoreListNode* args, ExceptionSink* xsink);
DLLEXPORT QoreHashNode* selectRow(const QoreString* query_str, const QoreListNode* args, ExceptionSink* xsink);
DLLEXPORT QoreValue exec(const QoreString* query_str, const QoreListNode* args, ExceptionSink* xsink);
DLLEXPORT QoreValue execRaw(const QoreString* query_str, const QoreListNode* args, ExceptionSink* xsink);
DLLEXPORT QoreValue execRaw(const QoreString* query_str, ExceptionSink* xsink);
DLLEXPORT QoreHashNode* describe(const QoreString* query_str, const QoreListNode* args, ExceptionSink* xsink);
DLLEXPORT int commit(ExceptionSink* xsink);
DLLEXPORT int rollback(ExceptionSink* xsink);
DLLEXPORT int close();
DLLEXPORT void reset(ExceptionSink* xsink);
DLLEXPORT QoreListNode* getCapabilityList() const;
DLLEXPORT int getCapabilities() const;
DLLEXPORT QoreStringNode* getPendingUsername() const;
DLLEXPORT QoreStringNode* getPendingPassword() const;
DLLEXPORT QoreStringNode* getPendingDBName() const;
DLLEXPORT QoreStringNode* getPendingDBEncoding() const;
DLLEXPORT QoreStringNode* getPendingHostName() const;
DLLEXPORT int getPendingPort() const;
DLLEXPORT int beginTransaction(ExceptionSink* xsink);
DLLEXPORT bool isInTransaction() const;
DLLEXPORT bool activeTransaction() const;
DLLEXPORT bool isOpen() const;
DLLEXPORT Datasource* copy() const;
DLLEXPORT const char* getDriverName() const;
DLLEXPORT QoreValue getServerVersion(ExceptionSink* xsink);
DLLEXPORT QoreValue getClientVersion(ExceptionSink* xsink) const;
DLLEXPORT const DBIDriver* getDriver() const;
DLLEXPORT void connectionAborted();
DLLEXPORT void connectionAborted(ExceptionSink* xsink);
DLLEXPORT void connectionLost(ExceptionSink* xsink);
DLLEXPORT void connectionRecovered(ExceptionSink* xsink);
DLLEXPORT bool wasConnectionAborted() const;
DLLEXPORT int autoCommit(ExceptionSink* xsink);
DLLEXPORT QoreHashNode* getOptionHash() const;
DLLEXPORT QoreHashNode* getCurrentOptionHash() const;
DLLEXPORT int setOption(const char* opt, const QoreValue val, ExceptionSink* xsink);
DLLEXPORT QoreValue getOption(const char* opt, ExceptionSink* xsink);
DLLEXPORT const QoreHashNode* getConnectOptions() const;
DLLEXPORT QoreHashNode* getConfigHash() const;
DLLEXPORT QoreStringNode* getConfigString() const;
DLLEXPORT void setEventQueue(Queue* q, QoreValue arg, ExceptionSink* xsink);
DLLEXPORT QoreHashNode* getEventQueueHash(Queue*& q, int event_code) const;
DLLEXPORT QoreObject* getSQLStatementObjectForResultSet(void* stmt_private_data);
};
#endif // _QORE_DATASOURCE_H
Datasource::getPendingDBName
DLLEXPORT QoreStringNode * getPendingDBName() const
returns the pending database (or schema) name for the next connection
Datasource::setPendingConnectionValues
DLLEXPORT void setPendingConnectionValues(const Datasource *other)
copies all pending connection values to another Datasource
Datasource::getCurrentOptionHash
DLLEXPORT QoreHashNode * getCurrentOptionHash() const
returns the options currently set for this object
Datasource::select
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, makes an implicit connection if necessary
Datasource::setPendingPort
DLLEXPORT void setPendingPort(int port)
sets the port number to be used for the next connection
Datasource::getDBNameStr
DLLEXPORT const std::string & getDBNameStr() const
returns the database (or schema) name used for the last connection
Datasource::copy
DLLEXPORT Datasource * copy() const
returns a copy of this object with the same DBIDriver and pending connection values ...
Datasource::getCapabilities
DLLEXPORT int getCapabilities() const
returns the capability mask of the current driver
Datasource::getDriverName
DLLEXPORT const char * getDriverName() const
returns the name of the current DBI driver
QoreEncoding
defines string encoding functions in Qore
Definition: QoreEncoding.h:83
Datasource::getPendingHostName
DLLEXPORT QoreStringNode * getPendingHostName() const
returns the pending host name for the next connection
Datasource::getSQLStatementObjectForResultSet
DLLEXPORT QoreObject * getSQLStatementObjectForResultSet(void *stmt_private_data)
returns an SQLStatement object representing a result set
Datasource::commit
DLLEXPORT int commit(ExceptionSink *xsink)
commits the current transaction to the database
Datasource::getPendingPort
DLLEXPORT int getPendingPort() const
returns the pending port number for the next connection
QoreHashNode
This is the hash or associative list container type in Qore, dynamically allocated only...
Definition: QoreHashNode.h:50
Datasource::~Datasource
virtual DLLEXPORT ~Datasource()
the Datasource is closed if it&#39;s still open and the object is destroyed
Datasource::setPendingUsername
DLLEXPORT void setPendingUsername(const char *u)
sets the username to be used for the next connection
Datasource::autoCommit
DLLEXPORT int autoCommit(ExceptionSink *xsink)
called from subclasses when releasing the transaction lock
Datasource::getOSEncoding
DLLEXPORT const char * getOSEncoding() const
returns the OS (or Qore) character encoding name used for the last connection
Datasource::getPort
DLLEXPORT int getPort() const
returns the port number used for the last connection
Datasource::isOpen
DLLEXPORT bool isOpen() const
returns true if the connection is currently open
Datasource::freeConnectionValues
DLLEXPORT void freeConnectionValues()
frees all connection values
Datasource::getPendingUsername
DLLEXPORT QoreStringNode * getPendingUsername() const
returns the pending username for the next connection
Datasource::selectRows
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...
Datasource::setPendingHostName
DLLEXPORT void setPendingHostName(const char *h)
sets the hostname to be used for the next connection
Datasource::execRaw
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, makes an implicit connection if necessary
Datasource::reset
DLLEXPORT void reset(ExceptionSink *xsink)
closes and opens the connection
Datasource::setEventQueue
DLLEXPORT void setEventQueue(Queue *q, QoreValue arg, ExceptionSink *xsink)
sets an event queue for datasource events
DBIDriver
this class provides the internal link to the database driver for Qore&#39;s DBI layer ...
Definition: DBI.h:353
Datasource::getClientVersion
DLLEXPORT QoreValue getClientVersion(ExceptionSink *xsink) const
executes the "get_client_version" function of the driver, if any, and returns the result ...
Datasource::getQoreEncoding
DLLEXPORT const QoreEncoding * getQoreEncoding() const
returns the QoreEncoding pointer used for this connection
Datasource::connectionRecovered
DLLEXPORT void connectionRecovered(ExceptionSink *xsink)
should be called be the DBI driver to signify that the connection to the server has been recovered ...
Datasource::setPendingDBName
DLLEXPORT void setPendingDBName(const char *d)
sets the database (or schema) name to be used for the next connection
Datasource::getDBEncoding
DLLEXPORT const char * getDBEncoding() const
returns the database-specific character encoding name used for the last connection ...
Datasource::getCapabilityList
DLLEXPORT QoreListNode * getCapabilityList() const
returns a QoreListNode object of all capability strings of the current driver, the caller owns the re...
Datasource::getHostNameStr
DLLEXPORT const std::string & getHostNameStr() const
returns the host name used for the last connection
Datasource::getDBEncodingStr
DLLEXPORT const std::string & getDBEncodingStr() const
returns the database-specific character encoding name used for the last connection ...
QoreString
Qore&#39;s string type supported by the QoreEncoding class.
Definition: QoreString.h:81
QoreStringNode
Qore&#39;s string value type, reference counted, dynamically-allocated only.
Definition: QoreStringNode.h:50
Datasource::exec
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, makes an implicit connection if necessary
Datasource::beginTransaction
DLLEXPORT int beginTransaction(ExceptionSink *xsink)
Datasource::getPassword
DLLEXPORT const char * getPassword() const
returns the password used for the last connection
Datasource::getUsernameStr
DLLEXPORT const std::string & getUsernameStr() const
returns the username used for the last connection
Datasource::getConfigHash
DLLEXPORT QoreHashNode * getConfigHash() const
returns a hash representing the configuration of the current object
QoreListNode
This is the list container type in Qore, dynamically allocated only, reference counted.
Definition: QoreListNode.h:52
Datasource::getPendingDBEncoding
DLLEXPORT QoreStringNode * getPendingDBEncoding() const
returns the pending database-specific character encoding name for the next connection ...
Datasource::activeTransaction
DLLEXPORT bool activeTransaction() const
returns true if a transaction is in progress and DB commands have been issued since the transaction w...
Datasource::setPendingPassword
DLLEXPORT void setPendingPassword(const char *p)
sets the password to be used for the next connection
Datasource::connectionAborted
DLLEXPORT void connectionAborted()
should be called by the DBIDriver if the connection to the server is lost
Datasource::getDriver
DLLEXPORT const DBIDriver * getDriver() const
returns the DBIDriver pointer used for this object
Datasource::getAutoCommit
DLLEXPORT bool getAutoCommit() const
returns the autocommit status
Datasource::rollback
DLLEXPORT int rollback(ExceptionSink *xsink)
rolls back the current transaction to the database
Datasource::describe
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 ...
Datasource::setConnectionValues
DLLEXPORT void setConnectionValues()
copies pending values to current values
Datasource::setOption
DLLEXPORT int setOption(const char *opt, const QoreValue val, ExceptionSink *xsink)
sets an option for the datasource
Datasource::setQoreEncoding
DLLEXPORT void setQoreEncoding(const QoreEncoding *enc)
sets the QoreEncoding used for this connection
Datasource::getOptionHash
DLLEXPORT QoreHashNode * getOptionHash() const
returns the valid options for this driver with descriptions and current values for the current dataso...
Datasource
the base class for accessing databases in Qore through a Qore DBI driver
Definition: Datasource.h:55
Datasource::getPrivateData
DLLEXPORT void * getPrivateData() const
returns the private DBI-specific data structure for this object
Datasource::getPasswordStr
DLLEXPORT const std::string & getPasswordStr() const
returns the password used for the last connection
Datasource::connectionLost
DLLEXPORT void connectionLost(ExceptionSink *xsink)
should be called be the DBI driver to signify that the connection to the server has been lost ...
QoreValue
The main value class in Qore, designed to be passed by value.
Definition: QoreValue.h:267
QoreObject
the implementation of Qore&#39;s object data type, reference counted, dynamically-allocated only ...
Definition: QoreObject.h:60
ExceptionSink
container for holding Qore-language exception information and also for registering a "thread_exit" ca...
Definition: ExceptionSink.h:48
Datasource::beginImplicitTransaction
DLLEXPORT int beginImplicitTransaction(ExceptionSink *xsink)
calls the "begin_implicit_transaction" DBI method if it exists
Datasource::wasConnectionAborted
DLLEXPORT bool wasConnectionAborted() const
returns the connection aborted status
Datasource::setPendingDBEncoding
DLLEXPORT void setPendingDBEncoding(const char *c)
sets the database-specific name of the character-encoding to be used for the next connection ...
Datasource::getConnectOptions
DLLEXPORT const QoreHashNode * getConnectOptions() const
returns the valid options for this driver with descriptions and current values for the current dataso...
Datasource::getConfigString
DLLEXPORT QoreStringNode * getConfigString() const
returns a string representing the configuration of the current object
Datasource::getUsername
DLLEXPORT const char * getUsername() const
returns the username used for the last connection
Datasource::getPendingPassword
DLLEXPORT QoreStringNode * getPendingPassword() const
returns the pending password for the next connection
Datasource::getPrivateDataRef
DLLLOCAL T & getPrivateDataRef() const
returns the private DBI-specific data structure for this object
Definition: Datasource.h:209
Datasource::selectRow
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, makes an implicit connection if necessary
Datasource::setTransactionStatus
DLLEXPORT void setTransactionStatus(bool)
sets the transaction status
Datasource::setPrivateData
DLLEXPORT void setPrivateData(void *data)
sets the private DBI-specific data structure for this object
Datasource::Datasource
DLLLOCAL Datasource(DBIDriver *driver, DatasourceStatementHelper *dsh)
creates the object; internal only
Datasource::open
DLLEXPORT int open(ExceptionSink *xsink)
opens a connection to the database
Datasource::getServerVersion
DLLEXPORT QoreValue getServerVersion(ExceptionSink *xsink)
executes the "get_server_version" function of the driver, if any, and returns the result...
Datasource::getEventQueueHash
DLLEXPORT QoreHashNode * getEventQueueHash(Queue *&q, int event_code) const
returns an event hash with only default information in it or 0 if no event queue is set ...
Datasource::setDBEncoding
DLLEXPORT void setDBEncoding(const char *name)
sets the database-specific character encoding name used for the current connection ...
Datasource::getDBName
DLLEXPORT const char * getDBName() const
returns the database (or schema) name used for the last connection
Datasource::getHostName
DLLEXPORT const char * getHostName() const
returns the host name used for the last connection
Datasource::getOption
DLLEXPORT QoreValue getOption(const char *opt, ExceptionSink *xsink)
Returns the current value for the given option.
Datasource::close
DLLEXPORT int close()
closes the connection
Datasource::isInTransaction
DLLEXPORT bool isInTransaction() const
returns the transaction status flag