signon  8.41
SignonDaemonNS::SqlDatabase Class Reference

Will be used manage the SQL database interaction. More...

#include <credentialsdb.h>

Inheritance diagram for SignonDaemonNS::SqlDatabase:

Public Member Functions

 SqlDatabase (const QString &hostname, const QString &connectionName, int version)
 Constructs a SqlDatabase object using the given hostname.
virtual ~SqlDatabase ()
 Destroys the SqlDatabase object, closing the database connection.
bool init ()
 Connects to the DB and if necessary creates the tables.
virtual bool createTables ()=0
virtual bool clear ()=0
virtual bool updateDB (int version)
bool connect ()
 Creates the database connection.
void disconnect ()
 Destroys the database connection.
bool startTransaction ()
bool commit ()
void rollback ()
bool connected ()
void setDatabaseName (const QString &databaseName)
 Sets the database name.
void setUsername (const QString &username)
 Sets the username for the database connection.
void setPassword (const QString &password)
 Sets the password for the database connection.
QString databaseName () const
QString username () const
QString password () const
QSqlQuery newQuery () const
QSqlQuery exec (const QString &query)
 Executes a specific database query.
QSqlQuery exec (QSqlQuery &query)
 Executes a specific database query.
bool transactionalExec (const QStringList &queryList)
 Executes a specific database set of queryes (INSERTs, UPDATEs, DELETEs) in a transaction context (No nested transactions supported - sqlite reasons).
bool hasTables () const
SignOn::CredentialsDBError lastError () const
bool errorOccurred () const
void clearError ()
QString connectionName () const

Static Public Member Functions

static QStringList supportedDrivers ()
static QString errorInfo (const QSqlError &error)
 Serializes a SQL error into a string.

Protected Member Functions

QStringList queryList (const QString &query_str)
QStringList queryList (QSqlQuery &query)
void setLastError (const QSqlError &sqlError)

Protected Attributes

int m_version
QSqlDatabase m_database

Friends

class ::TestDatabase
class CredentialsDB

Detailed Description

Will be used manage the SQL database interaction.

Definition at line 63 of file credentialsdb.h.

Constructor & Destructor Documentation

SignonDaemonNS::SqlDatabase::SqlDatabase ( const QString &  hostname,
const QString &  connectionName,
int  version 
)

Constructs a SqlDatabase object using the given hostname.

Parameters
hostname

Definition at line 41 of file credentialsdb.cpp.

References m_database, supportedDrivers(), and TRACE.

SignonDaemonNS::SqlDatabase::~SqlDatabase ( )
virtual

Destroys the SqlDatabase object, closing the database connection.

Definition at line 55 of file credentialsdb.cpp.

References m_database.

Member Function Documentation

virtual bool SignonDaemonNS::SqlDatabase::clear ( )
pure virtual
void SignonDaemonNS::SqlDatabase::clearError ( )
inline

Definition at line 197 of file credentialsdb.h.

bool SignonDaemonNS::SqlDatabase::connect ( )

Creates the database connection.

Returns
true if successful, false otherwise.

Definition at line 95 of file credentialsdb.cpp.

References m_database, setLastError(), and TRACE.

Referenced by init(), and SignonDaemonNS::MetaDataDB::updateDB().

bool SignonDaemonNS::SqlDatabase::connected ( )
inline
Returns
true if database connection is opened, false otherwise.

Definition at line 105 of file credentialsdb.h.

References m_database.

QString SignonDaemonNS::SqlDatabase::connectionName ( ) const
inline
virtual bool SignonDaemonNS::SqlDatabase::createTables ( )
pure virtual

Implemented in SignonDaemonNS::MetaDataDB, and SignonDaemonNS::SecretsDB.

Referenced by init().

QString SignonDaemonNS::SqlDatabase::databaseName ( ) const
inline
Returns
the database name.

Definition at line 134 of file credentialsdb.h.

References m_database.

void SignonDaemonNS::SqlDatabase::disconnect ( )

Destroys the database connection.

Definition at line 105 of file credentialsdb.cpp.

References m_database.

QString SignonDaemonNS::SqlDatabase::errorInfo ( const QSqlError &  error)
static

Serializes a SQL error into a string.

Parameters
error,methodwill fail if an error object is passed.
Returns
the error information as string.

Definition at line 206 of file credentialsdb.cpp.

References SignonDaemonNS::NoError, and SignonDaemonNS::UnknownError.

Referenced by exec().

QSqlQuery SignonDaemonNS::SqlDatabase::exec ( QSqlQuery &  query)

Executes a specific database query.

If an error occurres the lastError() method can be used for handling decissions.

Parameters
query,thequery.
Returns
the resulting sql query, which can be process in the case of a 'SELECT' statement.

Definition at line 143 of file credentialsdb.cpp.

References errorInfo(), setLastError(), and TRACE.

bool SignonDaemonNS::SqlDatabase::hasTables ( ) const
inline
Returns
true, if the database has any tables created, false otherwise.

Definition at line 182 of file credentialsdb.h.

References m_database.

Referenced by init().

bool SignonDaemonNS::SqlDatabase::init ( )

Connects to the DB and if necessary creates the tables.

Definition at line 61 of file credentialsdb.cpp.

References BLAME, connect(), createTables(), exec(), hasTables(), m_version, S, TRACE, and updateDB().

Referenced by SignonDaemonNS::CredentialsDB::init(), and SignonDaemonNS::DefaultSecretsStorage::initialize().

SignOn::CredentialsDBError SignonDaemonNS::SqlDatabase::lastError ( ) const
Returns
the last occurred error if any. If not error occurred on the last performed operation the error object is invalid.

Definition at line 187 of file credentialsdb.cpp.

Referenced by SignonDaemonNS::SecretsDB::createTables(), SignonDaemonNS::MetaDataDB::createTables(), errorOccurred(), SignonDaemonNS::DefaultSecretsStorage::initialize(), and SignonDaemonNS::MetaDataDB::updateDB().

QString SignonDaemonNS::SqlDatabase::password ( ) const
inline
Returns
the password for the database connection.

Definition at line 144 of file credentialsdb.h.

References m_database.

QStringList SignonDaemonNS::SqlDatabase::queryList ( const QString &  query_str)
protected
QStringList SignonDaemonNS::SqlDatabase::queryList ( QSqlQuery &  query)
protected

Definition at line 242 of file credentialsdb.cpp.

References errorOccurred(), and exec().

void SignonDaemonNS::SqlDatabase::setDatabaseName ( const QString &  databaseName)
inline

Sets the database name.

Parameters
databseName

Definition at line 111 of file credentialsdb.h.

References m_database.

void SignonDaemonNS::SqlDatabase::setLastError ( const QSqlError &  sqlError)
protected

Definition at line 192 of file credentialsdb.cpp.

Referenced by connect(), exec(), and transactionalExec().

void SignonDaemonNS::SqlDatabase::setPassword ( const QString &  password)
inline

Sets the password for the database connection.

Parameters
password

Definition at line 127 of file credentialsdb.h.

References m_database.

void SignonDaemonNS::SqlDatabase::setUsername ( const QString &  username)
inline

Sets the username for the database connection.

Parameters
username

Definition at line 119 of file credentialsdb.h.

References m_database.

static QStringList SignonDaemonNS::SqlDatabase::supportedDrivers ( )
inlinestatic
Returns
a list of the supported drivers on the specific OS.

Definition at line 189 of file credentialsdb.h.

Referenced by SqlDatabase().

bool SignonDaemonNS::SqlDatabase::transactionalExec ( const QStringList &  queryList)

Executes a specific database set of queryes (INSERTs, UPDATEs, DELETEs) in a transaction context (No nested transactions supported - sqlite reasons).

If an error occurres the lastError() method can be used for handling decissions.

Parameters
queryList,thequery list to be executed.
Returns
true if the transaction commits successfully, false otherwise.

Definition at line 157 of file credentialsdb.cpp.

References commit(), errorOccurred(), exec(), m_database, rollback(), setLastError(), startTransaction(), and TRACE.

Referenced by SignonDaemonNS::SecretsDB::clear(), SignonDaemonNS::MetaDataDB::clear(), SignonDaemonNS::SecretsDB::removeCredentials(), and SignonDaemonNS::MetaDataDB::removeIdentity().

bool SignonDaemonNS::SqlDatabase::updateDB ( int  version)
virtual

Reimplemented in SignonDaemonNS::MetaDataDB.

Definition at line 88 of file credentialsdb.cpp.

References exec(), m_version, and TRACE.

Referenced by init().

QString SignonDaemonNS::SqlDatabase::username ( ) const
inline
Returns
the username for the database connection.

Definition at line 139 of file credentialsdb.h.

References m_database.

Referenced by SignonDaemonNS::MetaDataDB::identity().

Friends And Related Function Documentation

friend class ::TestDatabase
friend

Definition at line 65 of file credentialsdb.h.

friend class CredentialsDB
friend

Definition at line 220 of file credentialsdb.h.

Member Data Documentation

int SignonDaemonNS::SqlDatabase::m_version
protected

Definition at line 217 of file credentialsdb.h.

Referenced by init(), updateDB(), and SignonDaemonNS::MetaDataDB::updateDB().


The documentation for this class was generated from the following files: