Isis 3.0 Developer's Reference (API) |
Home |
00001 #if !defined(Database_h) 00002 #define Database_h 00003 00026 #include <string> 00027 #include <vector> 00028 #include <iostream> 00029 #include "DbProfile.h" 00030 #include "iException.h" 00031 #include <QSqlDatabase> 00032 00033 namespace Isis { 00034 00084 class Database : public QSqlDatabase { 00085 public: 00087 typedef enum { 00088 Connect, 00089 DoNotConnect 00090 } Access; 00091 00092 Database(); 00093 Database(Access dbConn); 00094 Database(const std::string &connName, const std::string &driverType); 00095 Database(const std::string &name, Access dbConn = Connect); 00096 Database(const DbProfile &profile, Access dbConn = Connect); 00097 virtual ~Database(); 00098 00104 std::string Name() const { 00105 return (_name); 00106 } 00107 00108 void makePersistant(); 00109 bool isPersistant() const; 00110 void setAsDefault(); 00111 Database clone(const std::string &name) const; 00112 std::vector<std::string> getTables() const; 00113 std::vector<std::string> getViews() const; 00114 std::vector<std::string> getSystemTables() const; 00115 00116 static void remove(const std::string &name); 00117 00118 static bool addAccessConfig(const std::string &confFile); 00119 static DbProfile getProfile(const std::string &name); 00120 00121 protected: 00122 Database(const QSqlDatabase &other, const std::string &name); 00123 QSqlDatabase init(const DbProfile &profile, Access dbConn = Connect); 00124 QSqlDatabase init(const std::string &name = "", 00125 const std::string &driverType = ""); 00126 void configureAccess(QSqlDatabase &db, const DbProfile &profile); 00127 00128 private: 00129 static std::string _actualConnectionName; 00132 std::string _name; 00133 00134 void tossDbError(const std::string &message, const char *f, int l) const 00135 throw(iException &); 00136 }; 00137 00138 } 00139 #endif