signon  8.58
SignonDaemonNS::SqlDatabase Class Referenceabstract

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. More...
 
virtual ~SqlDatabase ()
 Destroys the SqlDatabase object, closing the database connection. More...
 
bool init ()
 Connects to the DB and if necessary creates the tables. More...
 
virtual bool createTables ()=0
 
virtual bool clear ()=0
 
virtual bool updateDB (int version)
 
bool connect ()
 Creates the database connection. More...
 
void disconnect ()
 Destroys the database connection. More...
 
bool startTransaction ()
 
bool commit ()
 
void rollback ()
 
bool connected ()
 
void setDatabaseName (const QString &databaseName)
 Sets the database name. More...
 
void setUsername (const QString &username)
 Sets the username for the database connection. More...
 
void setPassword (const QString &password)
 Sets the password for the database connection. More...
 
QString databaseName () const
 
QString username () const
 
QString password () const
 
QSqlQuery newQuery () const
 
QSqlQuery exec (const QString &query)
 Executes a specific database query. More...
 
QSqlQuery exec (QSqlQuery &query)
 Executes a specific database query. More...
 
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). More...
 
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. More...
 

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 125 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 139 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.

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

bool SignonDaemonNS::SqlDatabase::connect ( )

Creates the database connection.

Returns
true if successful, false otherwise.

Definition at line 179 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.

QString SignonDaemonNS::SqlDatabase::connectionName ( ) const
inline
virtual bool SignonDaemonNS::SqlDatabase::createTables ( )
pure virtual
QString SignonDaemonNS::SqlDatabase::databaseName ( ) const
inline
Returns
the database name.

Definition at line 157 of file credentialsdb_p.h.

void SignonDaemonNS::SqlDatabase::disconnect ( )

Destroys the database connection.

Definition at line 189 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 290 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 227 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.

Referenced by init().

bool SignonDaemonNS::SqlDatabase::init ( )

Connects to the DB and if necessary creates the tables.

Definition at line 145 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 271 of file credentialsdb.cpp.

Referenced by SignonDaemonNS::SecretsDB::createTables(), SignonDaemonNS::MetaDataDB::createTables(), 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.

Referenced by SignonDaemonNS::SecretsDB::SecretsDB().

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

Definition at line 326 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.

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

Definition at line 276 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.

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.

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 241 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 172 of file credentialsdb.cpp.

References exec(), m_version, and TRACE.

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

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

Definition at line 162 of file credentialsdb_p.h.

Referenced by SignonDaemonNS::MetaDataDB::identity(), and SignonDaemonNS::SecretsDB::SecretsDB().

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

QSqlDatabase SignonDaemonNS::SqlDatabase::m_database
protected
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: