All Classes Files Functions Variables Typedefs Enumerations Enumerator Macros Groups Pages
Datasource.h
/* -*- mode: c++; indent-tabs-mode: nil -*- */
/*
Datasource.h
Qore Programming Language
Copyright (C) 2003 - 2014 David Nichols
The Datasource class provides the low-level interface to Qore DBI drivers.
This library is free software; you can redistribute it and/or
modify it under the terms of the GNU Lesser General Public
License as published by the Free Software Foundation; either
version 2.1 of the License, or (at your option) any later version.
This library is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
Lesser General Public License for more details.
You should have received a copy of the GNU Lesser General Public
License along with this library; if not, write to the Free Software
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
*/
#ifndef _QORE_DATASOURCE_H
#define _QORE_DATASOURCE_H
#include <qore/QoreThreadLock.h>
#include <qore/QoreQueue.h>
#include <string>
class DBIDriver;
class Datasource {
friend class QoreSQLStatement;
private:
struct qore_ds_private *priv; // private implementation
DLLLOCAL Datasource& operator=(const Datasource&);
DLLLOCAL AbstractQoreNode* 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:
DLLEXPORT Datasource(DBIDriver* driver);
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 AbstractQoreNode* select(const QoreString* query_str, const QoreListNode* args, ExceptionSink* xsink);
DLLEXPORT AbstractQoreNode* selectRows(const QoreString* query_str, const QoreListNode* args, ExceptionSink* xsink);
DLLEXPORT QoreHashNode* selectRow(const QoreString* query_str, const QoreListNode* args, ExceptionSink* xsink);
DLLEXPORT AbstractQoreNode* exec(const QoreString* query_str, const QoreListNode* args, ExceptionSink* xsink);
DLLEXPORT AbstractQoreNode* execRaw(const QoreString* query_str, const QoreListNode* args, ExceptionSink* xsink);
DLLEXPORT AbstractQoreNode* 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 AbstractQoreNode* getServerVersion(ExceptionSink* xsink);
DLLEXPORT AbstractQoreNode* getClientVersion(ExceptionSink* xsink) const;
DLLEXPORT const DBIDriver* getDriver() const;
DLLEXPORT void connectionAborted();
DLLEXPORT bool wasConnectionAborted() const;
DLLEXPORT int autoCommit(ExceptionSink* xsink);
DLLEXPORT QoreHashNode* getOptionHash() const;
DLLEXPORT QoreHashNode* getCurrentOptionHash() const;
DLLEXPORT int setOption(const char* opt, const AbstractQoreNode* val, ExceptionSink* xsink);
DLLEXPORT AbstractQoreNode* getOption(const char* opt, ExceptionSink* xsink);
DLLEXPORT const QoreHashNode* getConnectOptions() const;
DLLEXPORT QoreHashNode* getConfigHash() const;
DLLEXPORT QoreStringNode* getConfigString() const;
DLLEXPORT void setEventQueue(Queue* q, AbstractQoreNode* arg, ExceptionSink* xsink);
DLLEXPORT QoreHashNode* getEventQueueHash(Queue*& q, int event_code) const;
};
#endif // _QORE_DATASOURCE_H
Datasource::getAutoCommit
DLLEXPORT bool getAutoCommit() const
returns the autocommit status
Datasource::setPendingConnectionValues
DLLEXPORT void setPendingConnectionValues(const Datasource *other)
copies all pending connection values to another Datasource
Datasource::getDriver
DLLEXPORT const DBIDriver * getDriver() const
returns the DBIDriver pointer used for this object
Datasource::getPrivateData
DLLLOCAL T * getPrivateData() const
returns the private DBI-specific data structure for this object
Definition: Datasource.h:170
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::getPendingUsername
DLLEXPORT QoreStringNode * getPendingUsername() const
returns the pending username for the next connection
Datasource::getOption
DLLEXPORT AbstractQoreNode * getOption(const char *opt, ExceptionSink *xsink)
Returns the current value for the given option.
Datasource::getPendingDBName
DLLEXPORT QoreStringNode * getPendingDBName() const
returns the pending database (or schema) name for the next connection
Datasource::setPendingPort
DLLEXPORT void setPendingPort(int port)
sets the port number to be used for the next connection
Datasource::getPasswordStr
DLLEXPORT const std::string & getPasswordStr() const
returns the password used for the last connection
QoreEncoding
defines string encoding functions in Qore
Definition: QoreEncoding.h:72
Datasource::getConnectOptions
DLLEXPORT const QoreHashNode * getConnectOptions() const
returns the valid options for this driver with descriptions and current values for the current dataso...
Datasource::wasConnectionAborted
DLLEXPORT bool wasConnectionAborted() const
returns the connection aborted status
Datasource::commit
DLLEXPORT int commit(ExceptionSink *xsink)
commits the current transaction to the database
QoreHashNode
This is the hash or associative list container type in Qore, dynamically allocated only...
Definition: QoreHashNode.h:41
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::freeConnectionValues
DLLEXPORT void freeConnectionValues()
frees all connection values
Datasource::getUsernameStr
DLLEXPORT const std::string & getUsernameStr() const
returns the username used for the last connection
Datasource::getQoreEncoding
DLLEXPORT const QoreEncoding * getQoreEncoding() const
returns the QoreEncoding pointer used for this 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::getPendingDBEncoding
DLLEXPORT QoreStringNode * getPendingDBEncoding() const
returns the pending database-specific character encoding name for the next connection ...
Datasource::setPendingHostName
DLLEXPORT void setPendingHostName(const char *h)
sets the hostname to be used for the next connection
Datasource::getConfigString
DLLEXPORT QoreStringNode * getConfigString() const
returns a string representing the configuration of the current object
AbstractQoreNode
The base class for all value and parse types in Qore expression trees.
Definition: AbstractQoreNode.h:47
Datasource::reset
DLLEXPORT void reset(ExceptionSink *xsink)
closes and opens the connection
Datasource::getPrivateDataRef
DLLLOCAL T & getPrivateDataRef() const
returns the private DBI-specific data structure for this object
Definition: Datasource.h:176
Datasource::getPassword
DLLEXPORT const char * getPassword() const
returns the password used for the last connection
DBIDriver
this class provides the internal link to the database driver for Qore&#39;s DBI layer ...
Definition: DBI.h:348
Datasource::getDBEncodingStr
DLLEXPORT const std::string & getDBEncodingStr() const
returns the database-specific character encoding name used for the last connection ...
Datasource::setPendingDBName
DLLEXPORT void setPendingDBName(const char *d)
sets the database (or schema) name 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
QoreString
Qore&#39;s string type supported by the QoreEncoding class.
Definition: QoreString.h:42
QoreStringNode
Qore&#39;s string value type, reference counted, dynamically-allocated only.
Definition: QoreStringNode.h:40
Datasource::getDriverName
DLLEXPORT const char * getDriverName() const
returns the name of the current DBI driver
Datasource::setOption
DLLEXPORT int setOption(const char *opt, const AbstractQoreNode *val, ExceptionSink *xsink)
sets an option for the datasource
Datasource::isInTransaction
DLLEXPORT bool isInTransaction() const
returns the transaction status flag
Datasource::execRaw
DLLEXPORT AbstractQoreNode * execRaw(const QoreString *query_str, const QoreListNode *args, ExceptionSink *xsink)
executes SQL throught the &quot;execRaw&quot; function of the DBI driver and returns the result, makes an implicit connection if necessary
Datasource::beginTransaction
DLLEXPORT int beginTransaction(ExceptionSink *xsink)
Datasource::getPendingPassword
DLLEXPORT QoreStringNode * getPendingPassword() const
returns the pending password for the next connection
Datasource::getDBName
DLLEXPORT const char * getDBName() const
returns the database (or schema) name used for the last connection
Datasource::getCurrentOptionHash
DLLEXPORT QoreHashNode * getCurrentOptionHash() const
returns the options currently set for this object
QoreListNode
This is the list container type in Qore, dynamically allocated only, reference counted.
Definition: QoreListNode.h:44
Datasource::setPendingPassword
DLLEXPORT void setPendingPassword(const char *p)
sets the password to be used for the next connection
Datasource::Datasource
DLLEXPORT Datasource(DBIDriver *driver)
creates the object and binds it to a particular DBIDriver
Datasource::connectionAborted
DLLEXPORT void connectionAborted()
should be called by the DBIDriver if the connection to the server is lost
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::getDBEncoding
DLLEXPORT const char * getDBEncoding() const
returns the database-specific character encoding name used for the last connection ...
Datasource::setQoreEncoding
DLLEXPORT void setQoreEncoding(const QoreEncoding *enc)
sets the QoreEncoding used for this connection
Datasource
the base class for accessing databases in Qore through a Qore DBI driver
Definition: Datasource.h:46
Datasource::getClientVersion
DLLEXPORT AbstractQoreNode * getClientVersion(ExceptionSink *xsink) const
executes the &quot;get_client_version&quot; function of the driver, if any, and returns the result ...
Datasource::selectRows
DLLEXPORT AbstractQoreNode * selectRows(const QoreString *query_str, const QoreListNode *args, ExceptionSink *xsink)
executes SQL throught the &quot;selectRows&quot; function of the DBI driver and returns the result...
Datasource::getOSEncoding
DLLEXPORT const char * getOSEncoding() const
returns the OS (or Qore) character encoding name used for the last connection
Datasource::select
DLLEXPORT AbstractQoreNode * select(const QoreString *query_str, const QoreListNode *args, ExceptionSink *xsink)
executes SQL throught the &quot;select&quot; function of the DBI driver and returns the result, makes an implicit connection if necessary
Datasource::getCapabilityList
DLLEXPORT QoreListNode * getCapabilityList() const
returns a QoreListNode object of all capability strings of the current driver, the caller owns the re...
ExceptionSink
container for holding Qore-language exception information and also for registering a &quot;thread_exit&quot; ca...
Definition: ExceptionSink.h:35
Datasource::getPort
DLLEXPORT int getPort() const
returns the port number used for the last connection
Datasource::beginImplicitTransaction
DLLEXPORT int beginImplicitTransaction(ExceptionSink *xsink)
calls the &quot;begin_implicit_transaction&quot; DBI method if it exists
Datasource::isOpen
DLLEXPORT bool isOpen() const
returns true if the connection is currently open
Datasource::getServerVersion
DLLEXPORT AbstractQoreNode * getServerVersion(ExceptionSink *xsink)
executes the &quot;get_server_version&quot; function of the driver, if any, and returns the result...
Datasource::copy
DLLEXPORT Datasource * copy() const
returns a copy of this object with the same DBIDriver and pending connection values ...
Datasource::getUsername
DLLEXPORT const char * getUsername() const
returns the username used for the last connection
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::getCapabilities
DLLEXPORT int getCapabilities() const
returns the capability mask of the current driver
Datasource::getPendingPort
DLLEXPORT int getPendingPort() const
returns the pending port number for the next connection
Datasource::setEventQueue
DLLEXPORT void setEventQueue(Queue *q, AbstractQoreNode *arg, ExceptionSink *xsink)
sets an event queue for datasource events
Datasource::selectRow
DLLEXPORT QoreHashNode * selectRow(const QoreString *query_str, const QoreListNode *args, ExceptionSink *xsink)
executes SQL throught the &quot;selectRow&quot; 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::exec
DLLEXPORT AbstractQoreNode * exec(const QoreString *query_str, const QoreListNode *args, ExceptionSink *xsink)
executes SQL throught the &quot;exec&quot; function of the DBI driver and returns the result, makes an implicit connection if necessary
Datasource::open
DLLEXPORT int open(ExceptionSink *xsink)
opens a connection to the database
Datasource::getOptionHash
DLLEXPORT QoreHashNode * getOptionHash() const
returns the valid options for this driver with descriptions and current values for the current dataso...
Datasource::getHostNameStr
DLLEXPORT const std::string & getHostNameStr() const
returns the host name used for the last connection
Datasource::getConfigHash
DLLEXPORT QoreHashNode * getConfigHash() const
returns a hash representing the configuration of the current object
Datasource::setDBEncoding
DLLEXPORT void setDBEncoding(const char *name)
sets the database-specific character encoding name used for the current connection ...
Datasource::getPrivateData
DLLEXPORT void * getPrivateData() const
returns the private DBI-specific data structure for this object
Datasource::getHostName
DLLEXPORT const char * getHostName() const
returns the host name used for the last connection
Datasource::getPendingHostName
DLLEXPORT QoreStringNode * getPendingHostName() const
returns the pending host name for the next connection
Datasource::close
DLLEXPORT int close()
closes the connection