00001 /* -*- c++ -*- 00002 * __BEGIN_COPYRIGHT 00003 * SimpleDB: C++ ODBC database API 00004 * Copyright (C) 2006 Eminence Technology Pty Ltd 00005 * Copyright (C) 2008-2010 Russell Kliese 00006 * 00007 * This library is free software; you can redistribute it and/or 00008 * modify it under the terms of the GNU Lesser General Public 00009 * License as published by the Free Software Foundation; either 00010 * version 2.1 of the License, or (at your option) any later version. 00011 * 00012 * This library is distributed in the hope that it will be useful, 00013 * but WITHOUT ANY WARRANTY; without even the implied warranty of 00014 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 00015 * Lesser General Public License for more details. 00016 * 00017 * You should have received a copy of the GNU Lesser General Public License 00018 * along with this library; if not, write to the Free Software 00019 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA 00020 * 00021 * Russell Kliese can be contacted by email: russell [at] kliese [dot] id [dot] au 00022 * 00023 * __END_COPYRIGHT 00024 */ 00025 00026 #ifndef _SIMPLEDB_DATABASE_H_ 00027 #define _SIMPLEDB_DATABASE_H_ 00028 00029 #include <string> 00030 #include <iostream> 00031 #include "Exception.h" 00032 #include <memory> 00033 #include "Query.h" 00034 00035 namespace SimpleDB { 00036 00039 struct DatabasePimplData; 00040 00047 class Database { 00048 00049 friend class Query; 00050 friend class ScopedTransaction; 00051 00052 public: 00053 00056 enum ConnectionMethod { 00057 00060 CONNECTION_METHOD_SQLConnect = 0, 00061 00064 CONNECTION_METHOD_SQLDriverConnect 00065 }; 00066 00070 class Exception : public SimpleDB::Exception { 00071 public: 00072 Exception(const std::string& message) : SimpleDB::Exception(message) {}; 00073 }; 00074 00078 class NoDataException : public Exception { 00079 public: 00080 00084 NoDataException() : Exception("No data returned.") { 00085 } 00086 }; 00087 00093 Database(const std::string& dsn, const ConnectionMethod connectionMethod = CONNECTION_METHOD_SQLConnect); 00094 00099 DEPRECATED(Query newQuery()); 00100 00105 void voidQuery (const std::string& query); 00106 00117 long intQuery (const std::string& query); 00118 00125 std::string strQuery (const std::string& query, long bufSize = 1000); 00126 00133 static std::string escapeString(const std::string& input); 00134 00139 static std::string boolToStr (const bool in); 00140 00143 int getTransactionCount() const; 00144 00148 virtual ~Database() ; 00149 00150 protected: 00151 00154 DatabasePimplData& getPimplData(); 00155 00156 private: 00157 00158 std::auto_ptr<DatabasePimplData> pimplData; 00159 00162 Database(const Database& that); 00163 const Database& operator=(const Database& that); 00164 00165 }; 00166 00167 } 00168 00169 inline 00170 std::ostream& operator<<(std::ostream& strm, const std::exception &e) { 00171 strm << "Database::Exception: " << e.what(); 00172 return strm; 00173 } 00174 00175 00176 #endif