00001 /* 00002 Datasource.h 00003 00004 Qore Programming Language 00005 00006 Copyright 2003 - 2009 David Nichols 00007 00008 The Datasource class provides the low-level interface to Qore DBI drivers. 00009 00010 This library is free software; you can redistribute it and/or 00011 modify it under the terms of the GNU Lesser General Public 00012 License as published by the Free Software Foundation; either 00013 version 2.1 of the License, or (at your option) any later version. 00014 00015 This library is distributed in the hope that it will be useful, 00016 but WITHOUT ANY WARRANTY; without even the implied warranty of 00017 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 00018 Lesser General Public License for more details. 00019 00020 You should have received a copy of the GNU Lesser General Public 00021 License along with this library; if not, write to the Free Software 00022 Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA 00023 */ 00024 00025 #ifndef _QORE_DATASOURCE_H 00026 00027 #define _QORE_DATASOURCE_H 00028 00029 #include <qore/QoreThreadLock.h> 00030 00031 #include <string> 00032 00033 class DBIDriver; 00034 00036 00044 class Datasource { 00045 private: 00046 struct qore_ds_private *priv; // private implementation 00047 00049 DLLLOCAL Datasource(const Datasource&); 00050 00052 DLLLOCAL Datasource& operator=(const Datasource&); 00053 00054 protected: 00056 DLLEXPORT void freeConnectionValues(); 00057 00059 DLLEXPORT void setConnectionValues(); 00060 00062 DLLEXPORT void setTransactionStatus(bool); 00063 00065 DLLEXPORT void setPendingConnectionValues(const Datasource *other); 00066 00068 DLLEXPORT int beginImplicitTransaction(ExceptionSink *xsink); 00069 00070 public: 00072 00075 DLLEXPORT Datasource(DBIDriver *driver); 00076 00078 DLLEXPORT virtual ~Datasource(); 00079 00081 00084 DLLEXPORT bool getAutoCommit() const; 00085 00087 00090 DLLEXPORT const char *getUsername() const; 00091 00093 00096 DLLEXPORT const char *getPassword() const; 00097 00099 00102 DLLEXPORT const char *getDBName() const; 00103 00105 00108 DLLEXPORT const char *getDBEncoding() const; 00109 00111 00114 DLLEXPORT const char *getOSEncoding() const; 00115 00117 00120 DLLEXPORT const char *getHostName() const; 00121 00123 00126 DLLEXPORT int getPort() const; 00127 00129 00132 DLLEXPORT const std::string &getUsernameStr() const; 00133 00135 00138 DLLEXPORT const std::string &getPasswordStr() const; 00139 00141 00144 DLLEXPORT const std::string &getDBNameStr() const; 00145 00147 00150 DLLEXPORT const std::string &getDBEncodingStr() const; 00151 00153 00156 DLLEXPORT const std::string &getHostNameStr() const; 00157 00159 DLLEXPORT void *getPrivateData() const; 00160 00162 00165 DLLEXPORT void setPrivateData(void *data); 00166 00168 00171 DLLEXPORT void setDBEncoding(const char *name); 00172 00174 DLLEXPORT const QoreEncoding *getQoreEncoding() const; 00175 00177 00180 DLLEXPORT void setQoreEncoding(const QoreEncoding *enc); 00181 00183 00186 DLLEXPORT void setQoreEncoding(const char *name); 00187 00189 00192 DLLEXPORT void setPendingUsername(const char *u); 00193 00195 00198 DLLEXPORT void setPendingPassword(const char *p); 00199 00201 00204 DLLEXPORT void setPendingDBName(const char *d); 00205 00207 00210 DLLEXPORT void setPendingDBEncoding(const char *c); 00211 00213 00216 DLLEXPORT void setPendingHostName(const char *h); 00217 00219 00222 DLLEXPORT void setPendingPort(int port); 00223 00224 DLLEXPORT void setAutoCommit(bool ac); 00225 00227 00230 DLLEXPORT int open(ExceptionSink *xsink); 00231 00233 00238 DLLEXPORT AbstractQoreNode *select(const QoreString *query_str, const QoreListNode *args, ExceptionSink *xsink); 00239 00241 00246 DLLEXPORT AbstractQoreNode *selectRows(const QoreString *query_str, const QoreListNode *args, ExceptionSink *xsink); 00247 00249 00256 DLLEXPORT AbstractQoreNode *exec(const QoreString *query_str, const QoreListNode *args, ExceptionSink *xsink); 00257 00259 00263 DLLEXPORT int commit(ExceptionSink *xsink); 00264 00266 00270 DLLEXPORT int rollback(ExceptionSink *xsink); 00271 00273 DLLEXPORT int close(); 00274 00276 DLLEXPORT void reset(ExceptionSink *xsink); 00277 00279 00282 DLLEXPORT QoreListNode *getCapabilityList() const; 00283 00285 00288 DLLEXPORT int getCapabilities() const; 00289 00291 00293 DLLEXPORT QoreStringNode *getPendingUsername() const; 00294 00296 00298 DLLEXPORT QoreStringNode *getPendingPassword() const; 00299 00301 00303 DLLEXPORT QoreStringNode *getPendingDBName() const; 00304 00306 00308 DLLEXPORT QoreStringNode *getPendingDBEncoding() const; 00309 00311 00314 DLLEXPORT QoreStringNode *getPendingHostName() const; 00315 00317 00320 DLLEXPORT int getPendingPort() const; 00321 00327 DLLEXPORT int beginTransaction(ExceptionSink *xsink); 00328 00330 00333 DLLEXPORT bool isInTransaction() const; 00334 00336 00339 DLLEXPORT bool isOpen() const; 00340 00342 00345 DLLEXPORT Datasource *copy() const; 00346 00348 DLLEXPORT const char *getDriverName() const; 00349 00351 00355 DLLEXPORT AbstractQoreNode *getServerVersion(ExceptionSink *xsink); 00356 00358 00361 DLLEXPORT AbstractQoreNode *getClientVersion(ExceptionSink *xsink) const; 00362 00364 00367 DLLEXPORT const DBIDriver *getDriver() const; 00368 00370 00374 DLLEXPORT void connectionAborted(); 00375 00377 00379 DLLEXPORT bool wasConnectionAborted() const; 00380 }; 00381 00382 #endif // _QORE_DATASOURCE_H 00383