|
Qore Programming Language
0.8.3
|
00001 /* -*- mode: c++; indent-tabs-mode: nil -*- */ 00002 /* 00003 Datasource.h 00004 00005 Qore Programming Language 00006 00007 Copyright 2003 - 2011 David Nichols 00008 00009 The Datasource class provides the low-level interface to Qore DBI drivers. 00010 00011 This library is free software; you can redistribute it and/or 00012 modify it under the terms of the GNU Lesser General Public 00013 License as published by the Free Software Foundation; either 00014 version 2.1 of the License, or (at your option) any later version. 00015 00016 This library is distributed in the hope that it will be useful, 00017 but WITHOUT ANY WARRANTY; without even the implied warranty of 00018 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 00019 Lesser General Public License for more details. 00020 00021 You should have received a copy of the GNU Lesser General Public 00022 License along with this library; if not, write to the Free Software 00023 Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA 00024 */ 00025 00026 #ifndef _QORE_DATASOURCE_H 00027 00028 #define _QORE_DATASOURCE_H 00029 00030 #include <qore/QoreThreadLock.h> 00031 00032 #include <string> 00033 00034 class DBIDriver; 00035 00037 00045 class Datasource { 00046 friend class QoreSQLStatement; 00047 00048 private: 00049 struct qore_ds_private *priv; // private implementation 00050 00052 DLLLOCAL Datasource(const Datasource&); 00053 00055 DLLLOCAL Datasource& operator=(const Datasource&); 00056 00058 DLLLOCAL AbstractQoreNode * exec_internal(bool doBind, const QoreString *query_str, const QoreListNode *args, ExceptionSink *xsink); 00059 00060 protected: 00062 DLLEXPORT void freeConnectionValues(); 00063 00065 DLLEXPORT void setConnectionValues(); 00066 00068 DLLEXPORT void setTransactionStatus(bool); 00069 00071 DLLEXPORT void setPendingConnectionValues(const Datasource *other); 00072 00074 DLLEXPORT int beginImplicitTransaction(ExceptionSink *xsink); 00075 00076 public: 00078 00081 DLLEXPORT Datasource(DBIDriver *driver); 00082 00084 DLLEXPORT virtual ~Datasource(); 00085 00087 00090 DLLEXPORT bool getAutoCommit() const; 00091 00093 00096 DLLEXPORT const char *getUsername() const; 00097 00099 00102 DLLEXPORT const char *getPassword() const; 00103 00105 00108 DLLEXPORT const char *getDBName() const; 00109 00111 00114 DLLEXPORT const char *getDBEncoding() const; 00115 00117 00120 DLLEXPORT const char *getOSEncoding() const; 00121 00123 00126 DLLEXPORT const char *getHostName() const; 00127 00129 00132 DLLEXPORT int getPort() const; 00133 00135 00138 DLLEXPORT const std::string &getUsernameStr() const; 00139 00141 00144 DLLEXPORT const std::string &getPasswordStr() const; 00145 00147 00150 DLLEXPORT const std::string &getDBNameStr() const; 00151 00153 00156 DLLEXPORT const std::string &getDBEncodingStr() const; 00157 00159 00162 DLLEXPORT const std::string &getHostNameStr() const; 00163 00165 DLLEXPORT void *getPrivateData() const; 00166 00168 template <typename T> 00169 DLLLOCAL T *getPrivateData() const { 00170 return reinterpret_cast<T*>(getPrivateData()); 00171 } 00172 00174 template <typename T> 00175 DLLLOCAL T &getPrivateDataRef() const { 00176 return *getPrivateData<T>(); 00177 } 00178 00180 00183 DLLEXPORT void setPrivateData(void *data); 00184 00186 00189 DLLEXPORT void setDBEncoding(const char *name); 00190 00192 DLLEXPORT const QoreEncoding *getQoreEncoding() const; 00193 00195 00198 DLLEXPORT void setQoreEncoding(const QoreEncoding *enc); 00199 00201 00204 DLLEXPORT void setQoreEncoding(const char *name); 00205 00207 00210 DLLEXPORT void setPendingUsername(const char *u); 00211 00213 00216 DLLEXPORT void setPendingPassword(const char *p); 00217 00219 00222 DLLEXPORT void setPendingDBName(const char *d); 00223 00225 00228 DLLEXPORT void setPendingDBEncoding(const char *c); 00229 00231 00234 DLLEXPORT void setPendingHostName(const char *h); 00235 00237 00240 DLLEXPORT void setPendingPort(int port); 00241 00242 DLLEXPORT void setAutoCommit(bool ac); 00243 00245 00248 DLLEXPORT int open(ExceptionSink *xsink); 00249 00251 00256 DLLEXPORT AbstractQoreNode *select(const QoreString *query_str, const QoreListNode *args, ExceptionSink *xsink); 00257 00259 00264 DLLEXPORT AbstractQoreNode *selectRows(const QoreString *query_str, const QoreListNode *args, ExceptionSink *xsink); 00265 00267 00274 DLLEXPORT QoreHashNode *selectRow(const QoreString *query_str, const QoreListNode *args, ExceptionSink *xsink); 00275 00277 00284 DLLEXPORT AbstractQoreNode *exec(const QoreString *query_str, const QoreListNode *args, ExceptionSink *xsink); 00285 00287 00293 DLLEXPORT AbstractQoreNode *execRaw(const QoreString *query_str, ExceptionSink *xsink); 00294 00296 00300 DLLEXPORT int commit(ExceptionSink *xsink); 00301 00303 00307 DLLEXPORT int rollback(ExceptionSink *xsink); 00308 00310 DLLEXPORT int close(); 00311 00313 DLLEXPORT void reset(ExceptionSink *xsink); 00314 00316 00319 DLLEXPORT QoreListNode *getCapabilityList() const; 00320 00322 00325 DLLEXPORT int getCapabilities() const; 00326 00328 00330 DLLEXPORT QoreStringNode *getPendingUsername() const; 00331 00333 00335 DLLEXPORT QoreStringNode *getPendingPassword() const; 00336 00338 00340 DLLEXPORT QoreStringNode *getPendingDBName() const; 00341 00343 00345 DLLEXPORT QoreStringNode *getPendingDBEncoding() const; 00346 00348 00351 DLLEXPORT QoreStringNode *getPendingHostName() const; 00352 00354 00357 DLLEXPORT int getPendingPort() const; 00358 00364 DLLEXPORT int beginTransaction(ExceptionSink *xsink); 00365 00367 00370 DLLEXPORT bool isInTransaction() const; 00371 00373 00377 DLLEXPORT bool activeTransaction() const; 00378 00380 00383 DLLEXPORT bool isOpen() const; 00384 00386 00389 DLLEXPORT Datasource *copy() const; 00390 00392 DLLEXPORT const char *getDriverName() const; 00393 00395 00399 DLLEXPORT AbstractQoreNode *getServerVersion(ExceptionSink *xsink); 00400 00402 00405 DLLEXPORT AbstractQoreNode *getClientVersion(ExceptionSink *xsink) const; 00406 00408 00411 DLLEXPORT const DBIDriver *getDriver() const; 00412 00414 00418 DLLEXPORT void connectionAborted(); 00419 00421 00423 DLLEXPORT bool wasConnectionAborted() const; 00424 00426 00430 DLLEXPORT int autoCommit(ExceptionSink *xsink); 00431 }; 00432 00433 #endif // _QORE_DATASOURCE_H 00434