Isis 3 Developer Reference
Database.h
Go to the documentation of this file.
1 #ifndef Database_h
2 #define Database_h
3 
26 #include <string>
27 #include <vector>
28 #include <iostream>
29 #include "DbProfile.h"
30 #include "IException.h"
31 #include <QSqlDatabase>
32 
33 namespace Isis {
34 
84  class Database : public QSqlDatabase {
85  public:
87  typedef enum {
90  } Access;
91 
92  Database();
93  Database(Access dbConn);
94  Database(const QString &connName, const QString &driverType);
95  Database(const QString &name, Access dbConn = Connect);
96  Database(const DbProfile &profile, Access dbConn = Connect);
97  virtual ~Database();
98 
104  QString Name() const {
105  return (_name);
106  }
107 
108  void makePersistant();
109  bool isPersistant() const;
110  void setAsDefault();
111  Database clone(const QString &name) const;
112  QStringList getTables() const;
113  QStringList getViews() const;
115 
116  static void remove(const QString &name);
117 
118  static bool addAccessConfig(const QString &confFile);
119  static DbProfile getProfile(const QString &name);
120 
121  protected:
122  Database(const QSqlDatabase &other, const QString &name);
123  QSqlDatabase init(const DbProfile &profile, Access dbConn = Connect);
124  QSqlDatabase init(const QString &name = "",
125  const QString &driverType = "");
126  void configureAccess(QSqlDatabase &db, const DbProfile &profile);
127 
128  private:
129  static QString _actualConnectionName;
132  QString _name;
133 
134  void tossDbError(const QString &message, const char *f, int l) const;
135  };
136 
137 }
138 #endif
bool isPersistant() const
Checks persistancy state of a database instantiation.
Definition: Database.cpp:220
Do not connect to database.
Definition: Database.h:89
Connect to database immediately.
Definition: Database.h:88
Database clone(const QString &name) const
Clones this database into another giving it another name.
Definition: Database.cpp:512
A DbProfile is a container for access parameters to a database.
Definition: DbProfile.h:65
static DbProfile getProfile(const QString &name)
Retrieves the named database access profile.
Definition: Database.cpp:325
void setAsDefault()
Sets this database connection/profile as the default.
Definition: Database.cpp:239
Access
Access status for database creation.
Definition: Database.h:87
QSqlDatabase init(const DbProfile &profile, Access dbConn=Connect)
Create and initialize a new database connection from a DbProfile.
Definition: Database.cpp:416
QStringList getViews() const
Returns a vector string containing all views within the database.
Definition: Database.cpp:537
QStringList getSystemTables() const
Returns vector strings of all available system tables in the database.
Definition: Database.cpp:549
QString Name() const
Return the name of this database as specifed upon creation.
Definition: Database.h:104
virtual ~Database()
Database destructor.
Definition: Database.cpp:173
QStringList getTables() const
Returns a vector string containing all the tables in the database.
Definition: Database.cpp:524
Isis database class providing generalized access to a variety of databases.
Definition: Database.h:84
void configureAccess(QSqlDatabase &db, const DbProfile &profile)
Set access parameters from a database DbProfile access specification.
Definition: Database.cpp:468
void makePersistant()
Makes this instance persistant.
Definition: Database.cpp:204
Namespace for ISIS/Bullet specific routines.
Definition: Apollo.h:31
static bool addAccessConfig(const QString &confFile)
Adds a user specifed access configuration file to system.
Definition: Database.cpp:288
Database()
Default database constructor.
Definition: Database.cpp:46