Isis Developer Reference
Database.h
Go to the documentation of this file.
1 #ifndef Database_h
2 #define Database_h
3 
10 /* SPDX-License-Identifier: CC0-1.0 */
11 
12 #include <string>
13 #include <vector>
14 #include <iostream>
15 #include "DbProfile.h"
16 #include "IException.h"
17 #include <QSqlDatabase>
18 
19 namespace Isis {
20 
70  class Database : public QSqlDatabase {
71  public:
73  typedef enum {
76  } Access;
77 
78  Database();
79  Database(Access dbConn);
80  Database(const QString &connName, const QString &driverType);
81  Database(const QString &name, Access dbConn = Connect);
82  Database(const DbProfile &profile, Access dbConn = Connect);
83  virtual ~Database();
84 
90  QString Name() const {
91  return (_name);
92  }
93 
94  void makePersistant();
95  bool isPersistant() const;
96  void setAsDefault();
97  Database clone(const QString &name) const;
98  QStringList getTables() const;
99  QStringList getViews() const;
101 
102  static void remove(const QString &name);
103 
104  static bool addAccessConfig(const QString &confFile);
105  static DbProfile getProfile(const QString &name);
106 
107  protected:
108  Database(const QSqlDatabase &other, const QString &name);
109  QSqlDatabase init(const DbProfile &profile, Access dbConn = Connect);
110  QSqlDatabase init(const QString &name = "",
111  const QString &driverType = "");
112  void configureAccess(QSqlDatabase &db, const DbProfile &profile);
113 
114  private:
115  static QString _actualConnectionName;
118  QString _name;
119 
120  void tossDbError(const QString &message, const char *f, int l) const;
121  };
122 
123 }
124 #endif
Isis::Database::isPersistant
bool isPersistant() const
Checks persistancy state of a database instantiation.
Definition: Database.cpp:207
Isis::DatabaseFactory::create
QSqlDatabase create(const QString &driver, const QString &dbname)
Create a database using the named driver.
Definition: DatabaseFactory.cpp:358
Isis::DbProfile::Name
QString Name() const
Returns the name of this property.
Definition: DbProfile.h:104
Isis::DatabaseFactory::setDefault
void setDefault(const QString &name)
Sets the default name of the database.
Definition: DatabaseFactory.h:258
Isis::DbProfile::exists
bool exists(const QString &key) const
Checks for the existance of a keyword.
Definition: DbProfile.h:115
QSqlDatabase
Isis::Database::Connect
@ Connect
Connect to database immediately.
Definition: Database.h:74
Isis::Database::getProfile
static DbProfile getProfile(const QString &name)
Retrieves the named database access profile.
Definition: Database.cpp:312
Isis::Database::remove
static void remove(const QString &name)
Removes the named database from pool.
Definition: Database.cpp:254
Database.h
Isis::DatabaseFactory::getProfile
DbProfile getProfile(const QString &name="") const
Get the specified database access profile.
Definition: DatabaseFactory.cpp:235
Isis::DatabaseFactory::remove
void remove(const QString &dbname)
Removes the database from the connection pool.
Definition: DatabaseFactory.cpp:450
DatabaseFactory.h
Isis::Database::init
QSqlDatabase init(const DbProfile &profile, Access dbConn=Connect)
Create and initialize a new database connection from a DbProfile.
Definition: Database.cpp:403
Isis::DatabaseFactory::isPersistant
bool isPersistant(const QString &name) const
Checks if the database resource is persistant.
Definition: DatabaseFactory.cpp:335
QStringList
Isis::DatabaseFactory::destroy
void destroy(const QString &dbname)
Removes the database from the connection pool and destroys it.
Definition: DatabaseFactory.cpp:435
IString.h
Isis::Database::getViews
QStringList getViews() const
Returns a vector string containing all views within the database.
Definition: Database.cpp:524
Isis::Database::addAccessConfig
static bool addAccessConfig(const QString &confFile)
Adds a user specifed access configuration file to system.
Definition: Database.cpp:275
Isis::DatabaseFactory::isAvailable
bool isAvailable(const QString &dbname="") const
Check for availablity of a database connection resource.
Definition: DatabaseFactory.cpp:297
Isis::Database::configureAccess
void configureAccess(QSqlDatabase &db, const DbProfile &profile)
Set access parameters from a database DbProfile access specification.
Definition: Database.cpp:455
Isis::Database::makePersistant
void makePersistant()
Makes this instance persistant.
Definition: Database.cpp:191
Isis::DatabaseFactory::add
void add(const QSqlDatabase &db, const QString &name, bool setAsDefault=false)
Adds the database to the connection pool making it persistant.
Definition: DatabaseFactory.cpp:415
Isis::Database::Name
QString Name() const
Return the name of this database as specifed upon creation.
Definition: Database.h:90
Isis::Database::~Database
virtual ~Database()
Database destructor.
Definition: Database.cpp:160
_FILEINFO_
#define _FILEINFO_
Macro for the filename and line number.
Definition: IException.h:24
Isis::toInt
int toInt(const QString &string)
Global function to convert from a string to an integer.
Definition: IString.cpp:93
Isis::DatabaseFactory::addAccessProfile
bool addAccessProfile(const QString &profileFile)
Establishes an access profile for subsequent database connections.
Definition: DatabaseFactory.cpp:152
Isis::DbProfile::isValid
bool isValid() const
Reports if this is a valid profile.
Definition: DbProfile.h:77
Isis::Database::clone
Database clone(const QString &name) const
Clones this database into another giving it another name.
Definition: Database.cpp:499
Isis::DbProfile
A DbProfile is a container for access parameters to a database.
Definition: DbProfile.h:51
Isis::IException
Isis exception class.
Definition: IException.h:91
Isis::Database::DoNotConnect
@ DoNotConnect
Do not connect to database.
Definition: Database.h:75
Isis::Database::setAsDefault
void setAsDefault()
Sets this database connection/profile as the default.
Definition: Database.cpp:226
Isis::DatabaseFactory
Create database interfaces using access profiles or generic drivers.
Definition: DatabaseFactory.h:244
Isis::Database::getSystemTables
QStringList getSystemTables() const
Returns vector strings of all available system tables in the database.
Definition: Database.cpp:536
Isis::DatabaseFactory::getInstance
static DatabaseFactory * getInstance()
Returns and instance of this DatabaseFactory singleton.
Definition: DatabaseFactory.cpp:124
Isis::Database::getTables
QStringList getTables() const
Returns a vector string containing all the tables in the database.
Definition: Database.cpp:511
IException.h
Isis::IException::Programmer
@ Programmer
This error is for when a programmer made an API call that was illegal.
Definition: IException.h:146
std
Namespace for the standard library.
Isis::Database
Isis database class providing generalized access to a variety of databases.
Definition: Database.h:70
DbProfile.h
Isis::DatabaseFactory::getDefault
QString getDefault() const
Returns the name of the default database.
Definition: DatabaseFactory.h:271
Isis::Database::Access
Access
Access status for database creation.
Definition: Database.h:73
Isis::Database::Database
Database()
Default database constructor.
Definition: Database.cpp:33
Isis
This is free and unencumbered software released into the public domain.
Definition: Apollo.h:16
Isis::IException::User
@ User
A type of error that could only have occurred due to a mistake on the user's part (e....
Definition: IException.h:126