signon  8.42
SignonDaemonNS::SqlDatabase Class Reference

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

#include <credentialsdb_p.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 86 of file credentialsdb_p.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 124 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 138 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 220 of file credentialsdb_p.h.

bool SignonDaemonNS::SqlDatabase::connect ( )

Creates the database connection.

Returns
true if successful, false otherwise.

Definition at line 178 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 128 of file credentialsdb_p.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 157 of file credentialsdb_p.h.

References m_database.

void SignonDaemonNS::SqlDatabase::disconnect ( )

Destroys the database connection.

Definition at line 188 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 289 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 226 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 205 of file credentialsdb_p.h.

References m_database.

Referenced by init().

bool SignonDaemonNS::SqlDatabase::init ( )

Connects to the DB and if necessary creates the tables.

Definition at line 144 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 270 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 167 of file credentialsdb_p.h.

References m_database.

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

Definition at line 325 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 134 of file credentialsdb_p.h.

References m_database.

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

Definition at line 275 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 150 of file credentialsdb_p.h.

References m_database.

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

Sets the username for the database connection.

Parameters
username

Definition at line 142 of file credentialsdb_p.h.

References m_database.

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

Definition at line 212 of file credentialsdb_p.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 240 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 171 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 162 of file credentialsdb_p.h.

References m_database.

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

Friends And Related Function Documentation

friend class ::TestDatabase
friend

Definition at line 88 of file credentialsdb_p.h.

friend class CredentialsDB
friend

Definition at line 243 of file credentialsdb_p.h.

Member Data Documentation

int SignonDaemonNS::SqlDatabase::m_version
protected

Definition at line 240 of file credentialsdb_p.h.

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


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