14#include "DatabaseFactory.h" 
   24  QString Database::_actualConnectionName = 
"";
 
   54    _name = _actualConnectionName;
 
   55    if((dbConn == 
Connect) && isValid()) {
 
   57        QString mess = 
"Failed to open database default database [" + 
_name;
 
 
   77    _name = _actualConnectionName;
 
   78    if((dbConn == 
Connect) && isValid()) {
 
   80        QString mess = 
"Failed to open database specified as " + 
_name;
 
 
  105    QSqlDatabase(init(connName, driverType)), _name(connName) {
 
  106    _name = _actualConnectionName;
 
 
  126    _name(profile.Name()) {
 
  127    _name = _actualConnectionName;
 
  128    if((dbConn == 
Connect) && isValid()) {
 
  130        QString mess = 
"Failed to open database with profile " + 
_name;
 
 
  162    if(!factory->isPersistant(
_name)) {
 
  166      factory->remove(
_name);
 
 
  193    if(!factory->isPersistant(
_name)) {
 
  194      factory->add(*
this, 
_name);
 
 
  209    return (factory->isPersistant(
_name));
 
 
  228    if(!factory->isPersistant(
_name)) {
 
  229      factory->add(*
this, 
_name);
 
  231    factory->setDefault(
_name);
 
 
  256    factory->destroy(name);
 
 
  277    return (factory->addAccessProfile(confFile));
 
 
  314    return (factory->getProfile(name));
 
 
  344                              const QString &driverType) {
 
  346    _actualConnectionName = connName;
 
  352    if(connName.isEmpty() && driverType.isEmpty()) {
 
  353      if(factory->isAvailable(factory->getDefault())) {
 
  354        _actualConnectionName = factory->getDefault();
 
  355        return (factory->create(_actualConnectionName));
 
  359      DbProfile profile =  factory->getProfile();
 
  366    if((!connName.isEmpty()) && (driverType.isEmpty())) {
 
  367      if(factory->isAvailable(connName)) {
 
  368        _actualConnectionName = connName;
 
  369        return (factory->create(connName));
 
  373        DbProfile profile = factory->getProfile(connName);
 
  380    return (factory->create(driverType, connName));
 
 
  406      mess << 
"Database/profile [" << profile.
Name() << 
"] is not valid!" << ends;
 
  410    _actualConnectionName = profile.
Name();
 
  418      QSqlDatabase db = factory->create(profile(
"Type"), profile(
"Name"));
 
  419      _actualConnectionName = profile(
"Name");
 
  425          QString mess = 
"Failed to connect to database using profile " +
 
  433      QString mess = 
"Unable to create database from " + profile.
Name();
 
  437      QString mess = 
"Unknown exception while creating database from profile " 
 
  456    if(profile.
exists(
"Host")) {
 
  457      db.setHostName(profile(
"Host"));
 
  460    if(profile.
exists(
"DbName")) {
 
  461      db.setDatabaseName(profile(
"DbName"));
 
  464    if(profile.
exists(
"User")) {
 
  465      db.setUserName(profile(
"User"));
 
  468    if(profile.
exists(
"Password")) {
 
  469      db.setPassword(profile(
"Password"));
 
  472    if(profile.
exists(
"Port")) {
 
  474      db.setPort(profile(
"Port").
toInt(&ok));
 
  477        mess << 
"Invalid port number [" << profile(
"Port") << 
"] in profile " 
  478             << profile(
"Name") << ends;
 
  483    if(profile.
exists(
"Options")) {
 
  484      db.setConnectOptions(profile(
"Options"));
 
 
  512    return (tables(QSql::Tables));
 
 
  525    return (tables(QSql::Views));
 
 
  537    return (tables(QSql::SystemTables));
 
 
  551    QString errmess = message + 
" - DatabaseError = " +
 
 
Create database interfaces using access profiles or generic drivers.
static DatabaseFactory * getInstance()
Returns and instance of this DatabaseFactory singleton.
Isis database class providing generalized access to a variety of databases.
Database clone(const QString &name) const
Clones this database into another giving it another name.
virtual ~Database()
Database destructor.
bool isPersistant() const
Checks persistancy state of a database instantiation.
static void remove(const QString &name)
Removes the named database from pool.
QStringList getSystemTables() const
Returns vector strings of all available system tables in the database.
Access
Access status for database creation.
@ Connect
Connect to database immediately.
@ DoNotConnect
Do not connect to database.
void tossDbError(const QString &message, const char *f, int l) const
Generic exception tosser.
QStringList getTables() const
Returns a vector string containing all the tables in the database.
static bool addAccessConfig(const QString &confFile)
Adds a user specifed access configuration file to system.
Database()
Default database constructor.
static DbProfile getProfile(const QString &name)
Retrieves the named database access profile.
void configureAccess(QSqlDatabase &db, const DbProfile &profile)
Set access parameters from a database DbProfile access specification.
QString _name
Needed due to peculiar issues with Database construction techniques.
void setAsDefault()
Sets this database connection/profile as the default.
QStringList getViews() const
Returns a vector string containing all views within the database.
QSqlDatabase init(const DbProfile &profile, Access dbConn=Connect)
Create and initialize a new database connection from a DbProfile.
void makePersistant()
Makes this instance persistant.
A DbProfile is a container for access parameters to a database.
bool isValid() const
Reports if this is a valid profile.
bool exists(const QString &key) const
Checks for the existance of a keyword.
QString Name() const
Returns the name of this property.
@ User
A type of error that could only have occurred due to a mistake on the user's part (e....
@ Programmer
This error is for when a programmer made an API call that was illegal.
This is free and unencumbered software released into the public domain.
int toInt(const QString &string)
Global function to convert from a string to an integer.
Namespace for the standard library.