SqlQuery: add `BindDoubleOrNullValue()` method

To facilitate serializing of the two DB fields added by the previous change.
This commit is contained in:
Roman Lebedev 2023-06-27 04:54:30 +03:00 committed by Jonas Kvinge
parent 0a4888f861
commit 73c56f038e
2 changed files with 9 additions and 0 deletions

View File

@ -72,6 +72,12 @@ void SqlQuery::BindFloatValue(const QString &placeholder, const float value) {
}
void SqlQuery::BindDoubleOrNullValue(const QString &placeholder, const std::optional<double> value) {
BindValue(placeholder, value.has_value() ? *value : QVariant());
}
void SqlQuery::BindBoolValue(const QString &placeholder, const bool value) {
BindValue(placeholder, value ? 1 : 0);

View File

@ -22,6 +22,8 @@
#include "config.h"
#include <optional>
#include <QMap>
#include <QVariant>
#include <QString>
@ -40,6 +42,7 @@ class SqlQuery : public QSqlQuery {
void BindLongLongValue(const QString &placeholder, const qint64 value);
void BindLongLongValueOrZero(const QString &placeholder, const qint64 value);
void BindFloatValue(const QString &placeholder, const float value);
void BindDoubleOrNullValue(const QString &placeholder, const std::optional<double> value);
void BindBoolValue(const QString &placeholder, const bool value);
void BindNotNullIntValue(const QString &placeholder, const int value);