mirror of
https://github.com/QuasarApp/Heart.git
synced 2025-04-28 18:54:37 +00:00
fix insert query of the setSingleValue class
This commit is contained in:
parent
ad432cf73e
commit
c99bd7763b
@ -435,19 +435,20 @@ bool DataBaseNode::upgradeDataBase() {
|
||||
return false;
|
||||
}
|
||||
|
||||
auto request = QSharedPointer<PKG::SetSingleValue>::create(
|
||||
DbAddress{"DataBaseAttributes", "name"},
|
||||
"value", currentVersion);
|
||||
|
||||
if (!_db->insertIfExistsUpdateObject(request, true)) {
|
||||
message = message.arg(currentVersion).arg(currentVersion);
|
||||
QuasarAppUtils::Params::log("Failed to update version attribute",
|
||||
QuasarAppUtils::Error);
|
||||
}
|
||||
|
||||
currentVersion++;
|
||||
}
|
||||
|
||||
|
||||
auto updateVersionRequest = QSharedPointer<PKG::SetSingleValue>::create(
|
||||
DbAddress{"DataBaseAttributes", "version"},
|
||||
"value", currentVersion, "name");
|
||||
|
||||
if (!_db->insertIfExistsUpdateObject(updateVersionRequest, true)) {
|
||||
QuasarAppUtils::Params::log("Failed to update version attribute",
|
||||
QuasarAppUtils::Error);
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
|
@ -6,7 +6,8 @@
|
||||
*/
|
||||
|
||||
#include "setsinglevalue.h"
|
||||
|
||||
#include "quasarapp.h"
|
||||
#include <QSqlError>
|
||||
#include <QSqlQuery>
|
||||
|
||||
namespace QH {
|
||||
@ -37,6 +38,8 @@ PrepareResult SetSingleValue::prepareUpdateQuery(QSqlQuery &q) const {
|
||||
|
||||
if (!q.prepare(queryString)) {
|
||||
|
||||
QuasarAppUtils::Params::log("Failed to prepare query: " + q.lastError().text(),
|
||||
QuasarAppUtils::Error);
|
||||
return PrepareResult::Fail;
|
||||
}
|
||||
|
||||
@ -46,16 +49,19 @@ PrepareResult SetSingleValue::prepareUpdateQuery(QSqlQuery &q) const {
|
||||
}
|
||||
|
||||
PrepareResult SetSingleValue::prepareInsertQuery(QSqlQuery &q) const {
|
||||
QString queryString = "INSERT INTO %0 VALUES (%1, :%1)";
|
||||
QString queryString = "INSERT INTO %0 (%1, %2) VALUES (:%1, :%2)";
|
||||
|
||||
queryString = queryString.arg(tableName(), _field);
|
||||
queryString = queryString.arg(tableName(), primaryKey(), _field, getId().toString());
|
||||
|
||||
if (!q.prepare(queryString)) {
|
||||
|
||||
QuasarAppUtils::Params::log("Failed to prepare query: " + q.lastError().text(),
|
||||
QuasarAppUtils::Error);
|
||||
return PrepareResult::Fail;
|
||||
}
|
||||
|
||||
q.bindValue(":" + _field, _value);
|
||||
q.bindValue(":" + primaryKey(), getId().toString());
|
||||
|
||||
return PrepareResult::Success;
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user