Heart 1.3.848.aa44c26
Heart is base back end library for your c++ Qt projects.
|
The SqlDBWriter class. This class write and read objects from database (hard level). Before working with database you need to initialize it. The SqlDBWriter support a any sql databases, For list of supported drivers see the Qt Docummentation https://doc.qt.io/qt-5/sql-driver.html For initialize a custom database driver you need to set an own params see the SqlDBWriter::initDb metthod. This class work only on own thread. For change working thread use the Qt method moveToThread. More...
#include <sqldbwriter.h>
Public Member Functions | |
SqlDBWriter (QThread *thread, QObject *ptr=nullptr) | |
virtual bool | initDb (const QString &initDbParams=DEFAULT_DB_PATH) |
initDb This method is wraper of the initDb(const QVariantMap ¶ms) method. This implementation read a initDbParams file and get all params from json. | |
virtual bool | initDb (const QVariantMap ¶ms) |
initDb This method initialize a database params and create a new database if the old database not exists. | |
virtual bool | isValid () const |
isValid This method return true if database is successful inited and working correctly. | |
bool | getAllObjects (const PKG::DBObject &templateObject, QList< QSharedPointer< PKG::DBObject > > &result) override |
getAllObjects This method execute a select method of the templateObject and return list of all selected from databaes or cache objects | |
bool | updateObject (const QSharedPointer< PKG::DBObject > &ptr, bool wait=false) override |
updateObject This method execute a update method of the saveObject and save all changes into database. | |
bool | deleteObject (const QSharedPointer< PKG::DBObject > &ptr, bool wait=false) override |
deleteObject This method execute a delete method of obj and remove current object from database. | |
bool | insertObject (const QSharedPointer< PKG::DBObject > &ptr, bool wait=false, const QWeakPointer< unsigned int > &autoincrementIdResult={}) override |
insertObject This method execute a insert method of the saveObject and insert it into database. | |
bool | replaceObject (const QSharedPointer< PKG::DBObject > &ptr, bool wait=false) override |
replaceObject This method execute a replace method of the saveObject and insert or save if not exists, all changes into database. | |
void | setSQLSources (const QStringList &list) override |
setSQLSources This method set sql sources for deployed database. | |
bool | doQuery (const QString &query, const QVariantMap &bindValues={}, bool wait=false, QSqlQuery *result=nullptr) const override |
doQuery This method execute a query in this database. | |
bool | doSql (const QString &sqlFile, bool wait) const override |
doSql This method execute a query in this database. | |
QString | databaseLocation () const |
databaseLocation This method return location of database. If it is sqlite then return path to db file else return database name. | |
virtual | ~SqlDBWriter () override |
virtual bool | updateQuery (const QSharedPointer< QH::PKG::DBObject > &ptr) const |
updateQuery This method execute update query of object. For more Information see DBObject::prepareUpdateQuery. | |
virtual bool | selectQuery (const QH::PKG::DBObject &requestObject, QList< QSharedPointer< QH::PKG::DBObject > > &result) |
selectQuery generate select query to database from parameters. | |
virtual bool | deleteQuery (const QSharedPointer< QH::PKG::DBObject > &deleteObject) const |
deleteQuery This method prepare the delete object query. | |
virtual bool | insertQuery (const QSharedPointer< QH::PKG::DBObject > &insertObject, const QWeakPointer< unsigned int > &autoIncrementID={}) const |
insertQuery This method prepare the insert object query. | |
virtual bool | replaceQuery (const QSharedPointer< QH::PKG::DBObject > &insertObject) const |
replaceQuery This method prepare the replce object query. | |
Public Member Functions inherited from QH::Async | |
bool | asyncLauncher (const Job &job, bool await=false, bool freaze=true) const |
asyncLauncher This method invoke a job on the thread (using the asyncHandler method) of this object. | |
Public Member Functions inherited from QH::iObjectProvider | |
template<class TYPE > | |
QSharedPointer< TYPE > | getObject (const TYPE &templateVal) |
getObject this method return a strong pointer to DBObject created by select method of the template object (templateVal). | |
QSharedPointer< PKG::DBObject > | getObjectRaw (const PKG::DBObject &templateVal) |
getObjectRaw This method return object without test object type. | |
Protected Member Functions | |
bool | enableFK () |
enableFK This method enable foreign key for the sqlite database. | |
bool | disableFK () |
disableFK This method disable foreign key for the sqlite database. | |
virtual QVariantMap | getInitParams (const QString &initFile) const |
getInitPararm This method read parameters of database. | |
virtual QVariantMap | defaultInitPararm () const |
defaultInitPararm This method return default parameters of the database. | |
virtual QSqlDatabase | initSqlDataBasse (const QString &driverName, const QString &name) |
initSqlDataBasse This method create ad database connection. Without configuration. This method invoked in the initDbPrivate method. | |
QSqlDatabase * | db () |
db This method return db connection. If SqlDBWriter in not inited then return nullptr. For more information about initialization the SqlDBWriter see the SqlDBWriter::initDb method. | |
const QSqlDatabase * | db () const |
db This is constant implementation of the SqlDBWriter::db method. | |
Protected Member Functions inherited from QH::Async | |
Async (QThread *thread, QObject *ptr=nullptr) | |
Async This is default constructor of the async object. | |
~Async () | |
bool | waitFor (bool *condition, int timeout=WAIT_TIME, bool freaze=true) const |
waitFor This is base wait function. | |
bool | waitFor (const Job &condition, int timeout=WAIT_TIME, bool freaze=true) const |
waitFor This is base wait function. | |
Additional Inherited Members | |
Public Types inherited from QH::Async | |
using | Job = std::function< bool()> |
The SqlDBWriter class. This class write and read objects from database (hard level). Before working with database you need to initialize it. The SqlDBWriter support a any sql databases, For list of supported drivers see the Qt Docummentation https://doc.qt.io/qt-5/sql-driver.html For initialize a custom database driver you need to set an own params see the SqlDBWriter::initDb metthod. This class work only on own thread. For change working thread use the Qt method moveToThread.
Definition at line 35 of file sqldbwriter.h.
QH::SqlDBWriter::SqlDBWriter | ( | QThread * | thread, |
QObject * | ptr = nullptr |
||
) |
Definition at line 253 of file sqldbwriter.cpp.
|
overridevirtual |
Definition at line 348 of file sqldbwriter.cpp.
QString QH::SqlDBWriter::databaseLocation | ( | ) | const |
databaseLocation This method return location of database. If it is sqlite then return path to db file else return database name.
Definition at line 341 of file sqldbwriter.cpp.
|
protected |
db This method return db connection. If SqlDBWriter in not inited then return nullptr. For more information about initialization the SqlDBWriter see the SqlDBWriter::initDb method.
Definition at line 245 of file sqldbwriter.cpp.
|
protected |
db This is constant implementation of the SqlDBWriter::db method.
Definition at line 249 of file sqldbwriter.cpp.
|
protectedvirtual |
defaultInitPararm This method return default parameters of the database.
Support parameters of database:
Definition at line 231 of file sqldbwriter.cpp.
|
overridevirtual |
deleteObject This method execute a delete method of obj and remove current object from database.
obj | This is object for removing. |
wait | This arguments force current thread wait for the function finishing. |
Implements QH::iObjectProvider.
Definition at line 300 of file sqldbwriter.cpp.
|
virtual |
deleteQuery This method prepare the delete object query.
deleteObject | This is tempalte object for generate a delete query. |
Definition at line 483 of file sqldbwriter.cpp.
|
protected |
disableFK This method disable foreign key for the sqlite database.
Definition at line 192 of file sqldbwriter.cpp.
|
overridevirtual |
doQuery This method execute a query in this database.
query | This is query that will be executed. |
bindValues | This is values that need to bind before excute query. |
result | This is query result value. |
Implements QH::iObjectProvider.
Definition at line 408 of file sqldbwriter.cpp.
|
overridevirtual |
doSql This method execute a query in this database.
sqlFile | This is sql file that will be executed. |
Implements QH::iObjectProvider.
Definition at line 420 of file sqldbwriter.cpp.
|
protected |
enableFK This method enable foreign key for the sqlite database.
Definition at line 177 of file sqldbwriter.cpp.
|
overridevirtual |
getAllObjects This method execute a select method of the templateObject and return list of all selected from databaes or cache objects
templateObject | This is template object for prepare a select request. |
result | This is return value, list of selected objects. |
Implements QH::iObjectProvider.
Definition at line 281 of file sqldbwriter.cpp.
|
protectedvirtual |
getInitPararm This method read parameters of database.
Support parameters of database:
initFile | This is path to json file with database configuration. |
Definition at line 209 of file sqldbwriter.cpp.
|
virtual |
initDb This method is wraper of the initDb(const QVariantMap ¶ms) method. This implementation read a initDbParams file and get all params from json.
initDbParams | This is path to json configuration file with settings of database. For more information see description of the SqlDBWriter::getInitParams method. |
Definition at line 257 of file sqldbwriter.cpp.
|
virtual |
initDb This method initialize a database params and create a new database if the old database not exists.
params | This is params of initialize a database. For more information about available and supported parameters see the description SqlDBWriter::getInitParams method. For more information see description of the SqlDBWriter::getInitParams method. |
Definition at line 269 of file sqldbwriter.cpp.
|
protectedvirtual |
initSqlDataBasse This method create ad database connection. Without configuration. This method invoked in the initDbPrivate method.
driverName | This is name of sql driver for more information see about Qt Sql Drivers. |
name | This is name of path of database. |
Definition at line 238 of file sqldbwriter.cpp.
|
overridevirtual |
insertObject This method execute a insert method of the saveObject and insert it into database.
saveObject | This is object for inserting. |
wait | This arguments force current thread wait for the function finishing. |
autoincrementIdResult | is id of the insert query to the Table with autoincrement id field. |
Implements QH::iObjectProvider.
Definition at line 309 of file sqldbwriter.cpp.
|
virtual |
insertQuery This method prepare the insert object query.
insertObject | This is strong pointer of object for generate the insert query. |
autoIncrementID | Week pointer to result id of new inserteed record. |
Definition at line 362 of file sqldbwriter.cpp.
|
virtual |
isValid This method return true if database is successful inited and working correctly.
Definition at line 277 of file sqldbwriter.cpp.
|
overridevirtual |
replaceObject This method execute a replace method of the saveObject and insert or save if not exists, all changes into database.
saveObject | This is object for updating. |
wait | This arguments force current thread wait for the function finishing. |
Implements QH::iObjectProvider.
Definition at line 329 of file sqldbwriter.cpp.
|
virtual |
replaceQuery This method prepare the replce object query.
insertObject | This is strong pointer of object for generate the insert query. |
Definition at line 389 of file sqldbwriter.cpp.
|
virtual |
selectQuery generate select query to database from parameters.
requestObject | This is template object for generate select query. |
result | This is return values. |
Definition at line 430 of file sqldbwriter.cpp.
|
overridevirtual |
setSQLSources This method set sql sources for deployed database.
list | This is list of sql files with database sources. |
For more information about sql sources see the DataBaseNode::SQLSources method.
Implements QH::iObjectProvider.
Definition at line 337 of file sqldbwriter.cpp.
|
overridevirtual |
updateObject This method execute a update method of the saveObject and save all changes into database.
saveObject | This is object for updating. |
wait | This arguments force current thread wait for the function finishing. |
Implements QH::iObjectProvider.
Definition at line 291 of file sqldbwriter.cpp.
|
virtual |
updateQuery This method execute update query of object. For more Information see DBObject::prepareUpdateQuery.
ptr | This is strong pointer to object that need to update into a database. |
Definition at line 501 of file sqldbwriter.cpp.