00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027 #ifndef __SIMPLEDB_DATABASE_H_
00028 #define __SIMPLEDB_DATABASE_H_ 1
00029
00030 #include <string>
00031 #include <sql.h>
00032 #include <sqlext.h>
00033 #include <iostream>
00034 #include "Query.h"
00035 #include "Exception.h"
00036
00037 namespace SimpleDB {
00038
00045 class Database {
00046
00047 public:
00048
00052 class Exception : public SimpleDB::Exception {
00053 public:
00054 Exception(const std::string& message) : SimpleDB::Exception(message) {};
00055 };
00056
00060 class NoDataException : public Exception {
00061 public:
00062
00066 NoDataException() : Exception("No data returned.") {
00067 }
00068 };
00069
00074 Database(std::string dsn);
00075
00080 Query newQuery() const;
00081
00086 void voidQuery (const std::string& query) const;
00087
00098 long intQuery (const std::string& query) const;
00099
00105 std::string strQuery (const std::string& query, long bufSize = 1000) const;
00106
00113 static const std::string escapeString(const std::string& input);
00114
00119 static const std::string boolToStr (const bool in);
00120
00125 const SQLHDBC getConnectionHandle() const;
00126
00130 virtual ~Database() ;
00131 protected:
00132
00135 SQLHDBC connectionHandle;
00136
00141 SQLHENV odbc_environment_handle;
00142 };
00143
00144 }
00145
00146 inline
00147 std::ostream& operator<<(std::ostream& strm, const std::exception &e) {
00148 strm << "Database::Exception: " << e.what();
00149 return strm;
00150 }
00151
00152 #endif