30 #include <QStringList> 37 QString Database::_actualConnectionName =
"";
67 _name = _actualConnectionName;
68 if((dbConn ==
Connect) && isValid()) {
70 QString mess =
"Failed to open database default database [" +
_name;
90 _name = _actualConnectionName;
91 if((dbConn ==
Connect) && isValid()) {
93 QString mess =
"Failed to open database specified as " +
_name;
118 QSqlDatabase(init(connName, driverType)), _name(connName) {
119 _name = _actualConnectionName;
139 _name(profile.Name()) {
140 _name = _actualConnectionName;
141 if((dbConn ==
Connect) && isValid()) {
143 QString mess =
"Failed to open database with profile " +
_name;
357 const QString &driverType) {
359 _actualConnectionName = connName;
365 if(connName.isEmpty() && driverType.isEmpty()) {
367 _actualConnectionName = factory->
getDefault();
368 return (factory->
create(_actualConnectionName));
379 if((!connName.isEmpty()) && (driverType.isEmpty())) {
381 _actualConnectionName = connName;
382 return (factory->
create(connName));
393 return (factory->
create(driverType, connName));
419 mess <<
"Database/profile [" << profile.
Name() <<
"] is not valid!" << ends;
423 _actualConnectionName = profile.
Name();
432 _actualConnectionName = profile(
"Name");
438 QString mess =
"Failed to connect to database using profile " +
446 QString mess =
"Unable to create database from " + profile.
Name();
450 QString mess =
"Unknown exception while creating database from profile " 469 if(profile.
exists(
"Host")) {
470 db.setHostName(profile(
"Host"));
473 if(profile.
exists(
"DbName")) {
474 db.setDatabaseName(profile(
"DbName"));
477 if(profile.
exists(
"User")) {
478 db.setUserName(profile(
"User"));
481 if(profile.
exists(
"Password")) {
482 db.setPassword(profile(
"Password"));
485 if(profile.
exists(
"Port")) {
487 db.setPort(profile(
"Port").
toInt(&ok));
490 mess <<
"Invalid port number [" << profile(
"Port") <<
"] in profile " 491 << profile(
"Name") << ends;
496 if(profile.
exists(
"Options")) {
497 db.setConnectOptions(profile(
"Options"));
525 return (tables(QSql::Tables));
538 return (tables(QSql::Views));
550 return (tables(QSql::SystemTables));
564 QString errmess = message +
" - DatabaseError = " +
bool isPersistant() const
Checks persistancy state of a database instantiation.
QString getDefault() const
Returns the name of the default database.
void setDefault(const QString &name)
Sets the default name of the database.
int toInt(const QString &string)
Global function to convert from a string to an integer.
DbProfile getProfile(const QString &name="") const
Get the specified database access profile.
Namespace for the standard library.
Do not connect to database.
static DatabaseFactory * getInstance()
Returns and instance of this DatabaseFactory singleton.
bool exists(const QString &key) const
Checks for the existance of a keyword.
Connect to database immediately.
Database clone(const QString &name) const
Clones this database into another giving it another name.
This error is for when a programmer made an API call that was illegal.
Create database interfaces using access profiles or generic drivers.
A DbProfile is a container for access parameters to a database.
static DbProfile getProfile(const QString &name)
Retrieves the named database access profile.
bool addAccessProfile(const QString &profileFile)
Establishes an access profile for subsequent database connections.
void setAsDefault()
Sets this database connection/profile as the default.
Access
Access status for database creation.
QSqlDatabase init(const DbProfile &profile, Access dbConn=Connect)
Create and initialize a new database connection from a DbProfile.
#define _FILEINFO_
Macro for the filename and line number.
A type of error that could only have occurred due to a mistake on the user's part (e...
QStringList getViews() const
Returns a vector string containing all views within the database.
bool isAvailable(const QString &dbname="") const
Check for availablity of a database connection resource.
QString _name
Needed due to peculiar issues with Database construction techniques.
QStringList getSystemTables() const
Returns vector strings of all available system tables in the database.
virtual ~Database()
Database destructor.
QStringList getTables() const
Returns a vector string containing all the tables in the database.
void add(const QSqlDatabase &db, const QString &name, bool setAsDefault=false)
Adds the database to the connection pool making it persistant.
Isis database class providing generalized access to a variety of databases.
void remove(const QString &dbname)
Removes the database from the connection pool.
void configureAccess(QSqlDatabase &db, const DbProfile &profile)
Set access parameters from a database DbProfile access specification.
void tossDbError(const QString &message, const char *f, int l) const
Generic exception tosser.
void makePersistant()
Makes this instance persistant.
Namespace for ISIS/Bullet specific routines.
bool isValid() const
Reports if this is a valid profile.
static void remove(const QString &name)
Removes the named database from pool.
static bool addAccessConfig(const QString &confFile)
Adds a user specifed access configuration file to system.
QString Name() const
Returns the name of this property.
Database()
Default database constructor.
void destroy(const QString &dbname)
Removes the database from the connection pool and destroys it.
bool isPersistant(const QString &name) const
Checks if the database resource is persistant.
QSqlDatabase create(const QString &driver, const QString &dbname)
Create a database using the named driver.