Qore Programming Language: include/qore/Datasource.h (6585) Source File

Qore Programming Language 0.8.11

- Main Page
- Related Pages
- Modules
- Classes
- Files

- File List
- File Members

All Classes Files Functions Variables Typedefs Enumerations Enumerator Macros Groups Pages
Datasource.h
1 /* -*- mode: c++; indent-tabs-mode: nil -*- */
2 /*
3 Datasource.h
4
5 Qore Programming Language
6
7 Copyright (C) 2003 - 2014 David Nichols
8
9 The Datasource class provides the low-level interface to Qore DBI drivers.
10
11 This library is free software; you can redistribute it and/or
12 modify it under the terms of the GNU Lesser General Public
13 License as published by the Free Software Foundation; either
14 version 2.1 of the License, or (at your option) any later version.
15
16 This library is distributed in the hope that it will be useful,
17 but WITHOUT ANY WARRANTY; without even the implied warranty of
18 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
19 Lesser General Public License for more details.
20
21 You should have received a copy of the GNU Lesser General Public
22 License along with this library; if not, write to the Free Software
23 Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
24 */
25
26 #ifndef _QORE_DATASOURCE_H
27
28 #define _QORE_DATASOURCE_H
29
30 #include <qore/QoreThreadLock.h>
31 #include <qore/QoreQueue.h>
32
33 #include <string>
34
35 class DBIDriver;
36
38
46 class Datasource {
47 friend class QoreSQLStatement;
48
49 private:
50 struct qore_ds_private *priv; // private implementation
51
53 DLLLOCAL Datasource& operator=(const Datasource&);
54
56 DLLLOCAL AbstractQoreNode* exec_internal(bool doBind, const QoreString* query_str, const QoreListNode* args, ExceptionSink* xsink);
57
58 protected:
60 DLLEXPORT void freeConnectionValues();
61
63 DLLEXPORT void setConnectionValues();
64
66 DLLEXPORT void setTransactionStatus(bool);
67
69 DLLEXPORT void setPendingConnectionValues(const Datasource* other);
70
72 DLLEXPORT int beginImplicitTransaction(ExceptionSink* xsink);
73
74 public:
76
79 DLLEXPORT Datasource(DBIDriver* driver);
80
82 DLLEXPORT Datasource(const Datasource& old);
83
85 DLLEXPORT virtual ~Datasource();
86
88
91 DLLEXPORT bool getAutoCommit() const;
92
94
97 DLLEXPORT const char* getUsername() const;
98
100
103 DLLEXPORT const char* getPassword() const;
104
106
109 DLLEXPORT const char* getDBName() const;
110
112
115 DLLEXPORT const char* getDBEncoding() const;
116
118
121 DLLEXPORT const char* getOSEncoding() const;
122
124
127 DLLEXPORT const char* getHostName() const;
128
130
133 DLLEXPORT int getPort() const;
134
136
139 DLLEXPORT const std::string& getUsernameStr() const;
140
142
145 DLLEXPORT const std::string& getPasswordStr() const;
146
148
151 DLLEXPORT const std::string& getDBNameStr() const;
152
154
157 DLLEXPORT const std::string& getDBEncodingStr() const;
158
160
163 DLLEXPORT const std::string& getHostNameStr() const;
164
166 DLLEXPORT void* getPrivateData() const;
167
169 template <typename T>
170 DLLLOCAL T* getPrivateData() const {
171 return reinterpret_cast<T*>(getPrivateData());
172 }
173
175 template <typename T>
176 DLLLOCAL T& getPrivateDataRef() const {
177 return *getPrivateData<T>();
178 }
179
181
184 DLLEXPORT void setPrivateData(void* data);
185
187
190 DLLEXPORT void setDBEncoding(const char* name);
191
193 DLLEXPORT const QoreEncoding* getQoreEncoding() const;
194
196
199 DLLEXPORT void setQoreEncoding(const QoreEncoding* enc);
200
202
205 DLLEXPORT void setQoreEncoding(const char* name);
206
208
211 DLLEXPORT void setPendingUsername(const char* u);
212
214
217 DLLEXPORT void setPendingPassword(const char* p);
218
220
223 DLLEXPORT void setPendingDBName(const char* d);
224
226
229 DLLEXPORT void setPendingDBEncoding(const char* c);
230
232
235 DLLEXPORT void setPendingHostName(const char* h);
236
238
241 DLLEXPORT void setPendingPort(int port);
242
243 DLLEXPORT void setAutoCommit(bool ac);
244
246
249 DLLEXPORT int open(ExceptionSink* xsink);
250
252
257 DLLEXPORT AbstractQoreNode* select(const QoreString* query_str, const QoreListNode* args, ExceptionSink* xsink);
258
260
265 DLLEXPORT AbstractQoreNode* selectRows(const QoreString* query_str, const QoreListNode* args, ExceptionSink* xsink);
266
268
275 DLLEXPORT QoreHashNode* selectRow(const QoreString* query_str, const QoreListNode* args, ExceptionSink* xsink);
276
278
285 DLLEXPORT AbstractQoreNode* exec(const QoreString* query_str, const QoreListNode* args, ExceptionSink* xsink);
286
288
298 DLLEXPORT AbstractQoreNode* execRaw(const QoreString* query_str, const QoreListNode* args, ExceptionSink* xsink);
299
301
308 DLLEXPORT AbstractQoreNode* execRaw(const QoreString* query_str, ExceptionSink* xsink);
309
311
318 DLLEXPORT QoreHashNode* describe(const QoreString* query_str, const QoreListNode* args, ExceptionSink* xsink);
319
321
325 DLLEXPORT int commit(ExceptionSink* xsink);
326
328
332 DLLEXPORT int rollback(ExceptionSink* xsink);
333
335 DLLEXPORT int close();
336
338 DLLEXPORT void reset(ExceptionSink* xsink);
339
341
344 DLLEXPORT QoreListNode* getCapabilityList() const;
345
347
350 DLLEXPORT int getCapabilities() const;
351
353
355 DLLEXPORT QoreStringNode* getPendingUsername() const;
356
358
360 DLLEXPORT QoreStringNode* getPendingPassword() const;
361
363
365 DLLEXPORT QoreStringNode* getPendingDBName() const;
366
368
370 DLLEXPORT QoreStringNode* getPendingDBEncoding() const;
371
373
376 DLLEXPORT QoreStringNode* getPendingHostName() const;
377
379
382 DLLEXPORT int getPendingPort() const;
383
389 DLLEXPORT int beginTransaction(ExceptionSink* xsink);
390
392
395 DLLEXPORT bool isInTransaction() const;
396
398
402 DLLEXPORT bool activeTransaction() const;
403
405
408 DLLEXPORT bool isOpen() const;
409
411
414 DLLEXPORT Datasource* copy() const;
415
417 DLLEXPORT const char* getDriverName() const;
418
420
424 DLLEXPORT AbstractQoreNode* getServerVersion(ExceptionSink* xsink);
425
427
430 DLLEXPORT AbstractQoreNode* getClientVersion(ExceptionSink* xsink) const;
431
433
436 DLLEXPORT const DBIDriver* getDriver() const;
437
439
443 DLLEXPORT void connectionAborted();
444
446
448 DLLEXPORT bool wasConnectionAborted() const;
449
451
455 DLLEXPORT int autoCommit(ExceptionSink* xsink);
456
458
465 DLLEXPORT QoreHashNode* getOptionHash() const;
466
468
474 DLLEXPORT QoreHashNode* getCurrentOptionHash() const;
475
477
483 DLLEXPORT int setOption(const char* opt, const AbstractQoreNode* val, ExceptionSink* xsink);
484
486
493 DLLEXPORT AbstractQoreNode* getOption(const char* opt, ExceptionSink* xsink);
494
496
504 DLLEXPORT const QoreHashNode* getConnectOptions() const;
505
507
510 DLLEXPORT QoreHashNode* getConfigHash() const;
511
513
516 DLLEXPORT QoreStringNode* getConfigString() const;
517
519
522 DLLEXPORT void setEventQueue(Queue* q, AbstractQoreNode* arg, ExceptionSink* xsink);
523
525
527 DLLEXPORT QoreHashNode* getEventQueueHash(Queue*& q, int event_code) const;
528 };
529
530 #endif // _QORE_DATASOURCE_H
531
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'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'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's string type supported by the QoreEncoding class.
Definition: QoreString.h:42
QoreStringNode
Qore'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 "execRaw" 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 "get_client_version" 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 "selectRows" 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 "select" 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 "thread_exit" 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 "begin_implicit_transaction" 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 "get_server_version" 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 "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::exec
DLLEXPORT AbstractQoreNode * 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::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