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;
 
 
  106    _name = _actualConnectionName;
 
 
  127    _name = _actualConnectionName;
 
  128    if((dbConn == 
Connect) && isValid()) {
 
  130        QString mess = 
"Failed to open database with profile " + 
_name;
 
 
  344                              const QString &driverType) {
 
  346    _actualConnectionName = connName;
 
  352    if(connName.isEmpty() && driverType.isEmpty()) {
 
  354        _actualConnectionName = factory->
getDefault();
 
  355        return (factory->
create(_actualConnectionName));
 
  366    if((!connName.isEmpty()) && (driverType.isEmpty())) {
 
  368        _actualConnectionName = connName;
 
  369        return (factory->
create(connName));
 
  380    return (factory->
create(driverType, connName));
 
 
  406      mess << 
"Database/profile [" << profile.
Name() << 
"] is not valid!" << ends;
 
  410    _actualConnectionName = 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.
 
QSqlDatabase create(const QString &driver, const QString &dbname)
Create a database using the named driver.
 
static DatabaseFactory * getInstance()
Returns and instance of this DatabaseFactory singleton.
 
void destroy(const QString &dbname)
Removes the database from the connection pool and destroys it.
 
void remove(const QString &dbname)
Removes the database from the connection pool.
 
DbProfile getProfile(const QString &name="") const
Get the specified database access profile.
 
void add(const QSqlDatabase &db, const QString &name, bool setAsDefault=false)
Adds the database to the connection pool making it persistant.
 
bool isPersistant(const QString &name) const
Checks if the database resource is persistant.
 
bool addAccessProfile(const QString &profileFile)
Establishes an access profile for subsequent database connections.
 
bool isAvailable(const QString &dbname="") const
Check for availablity of a database connection resource.
 
QString getDefault() const
Returns the name of the default database.
 
void setDefault(const QString &name)
Sets the default name of the database.
 
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.
 
QString Name() const
Return the name of this database as specifed upon creation.
 
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.