LeechCraft  0.6.70-15082-g543737046d
Modular cross-platform feature rich live environment.
The DB utilities

General widgets and classes for databases. More...

Classes

class  LC::Util::BackendSelector
 A common dialog to select storage backend. More...
 
class  LC::Util::DBLock
 Provides database transaction lock. More...
 

Functions

QSqlQuery LC::Util::RunTextQuery (const QSqlDatabase &db, const QString &text)
 Runs the given query text on the given db. More...
 
QString LC::Util::LoadQuery (const QString &plugin, const QString &filename)
 Loads the query text from the given resource file. More...
 
void LC::Util::RunQuery (const QSqlDatabase &db, const QString &plugin, const QString &filename)
 Loads the query from the given resource file and runs it. More...
 
template<typename T = int>
LC::Util::GetLastId (const QSqlQuery &query)
 Gets the last insert ID for the given query. More...
 
QString LC::Util::GenConnectionName (const QString &base)
 Generates an unique thread-safe connection name. More...
 

Detailed Description

General widgets and classes for databases.

Function Documentation

◆ GenConnectionName()

UTIL_DB_API QString LC::Util::GenConnectionName ( const QString &  base)

Generates an unique thread-safe connection name.

This function generates a connection name using the given base that is unique across all threads.

Parameters
[in]baseThe identifier base to be used to generate the unique connection string.
Returns
An unique connection name across all threads.

Definition at line 57 of file util.cpp.

Referenced by LC::Util::MakeDatabase(), and LC::Util::ConsistencyChecker::StartCheck().

+ Here is the caller graph for this function:

◆ GetLastId()

template<typename T = int>
T LC::Util::GetLastId ( const QSqlQuery &  query)

Gets the last insert ID for the given query.

Template Parameters
TThe type of the last ID.
Parameters
[in]queryThe query whose last insert ID should be retrieved.
Returns
The last insert ID of type T.
Exceptions
std::runtime_errorIf no last insert ID has been reported, or if the last insert ID cannot be converted to type T.

Definition at line 95 of file util.h.

◆ LoadQuery()

UTIL_DB_API QString LC::Util::LoadQuery ( const QString &  plugin,
const QString &  filename 
)

Loads the query text from the given resource file.

Loads the query text from the resources for the given plugin and exact filename in it.

The file name to be loaded is formed as :/${plugin}/resources/sql/${filename}.sql.

Parameters
[in]pluginThe name of the plugin whose resources should be used.
[in]filenameThe name of the file under ${plugin}/resources/sql.
Returns
The query text in the given file.
Exceptions
std::exceptionIf the given file cannot be opened.
See also
RunQuery()

Definition at line 36 of file util.cpp.

◆ RunQuery()

UTIL_DB_API void LC::Util::RunQuery ( const QSqlDatabase &  db,
const QString &  plugin,
const QString &  filename 
)

Loads the query from the given resource file and runs it.

Loads the query text from the resources for the given plugin and exact filename in it and executes it on the given db.

The file name to be loaded is formed as :/${plugin}/resources/sql/${filename}.sql.

Parameters
[in]dbThe database to execute the query on.
[in]pluginThe name of the plugin whose resources should be used.
[in]filenameThe name of the file under ${plugin}/resources/sql.
Exceptions
std::exceptionIf the given file cannot be opened or if the query execution failed.
See also
LoadQuery()

Definition at line 50 of file util.cpp.

Referenced by LC::Util::oral::detail::SelectWrapper< T, detail::SelectBehaviour::One >::operator()().

+ Here is the caller graph for this function:

◆ RunTextQuery()

UTIL_DB_API QSqlQuery LC::Util::RunTextQuery ( const QSqlDatabase &  db,
const QString &  text 
)

Runs the given query text on the given db.

Prepares and executes a QSqlQuery containing the given query text on the given db. If the query fails, an exception is thrown.

Parameters
[in]dbThe database to execute the query text on.
[in]textThe text of the query to be executed.
Returns
The query object, which may be used to retrieve the query results.
Exceptions
std::exceptionIf the query execution failed.

Definition at line 24 of file util.cpp.

Referenced by LC::Util::MakeDatabase().

+ Here is the caller graph for this function: