From bc1c0c3c6de127fab954366f143009a7f60ea669 Mon Sep 17 00:00:00 2001 From: Jonas Kvinge Date: Tue, 9 Nov 2021 19:23:14 +0100 Subject: [PATCH] SqlQuery: Add more BindValue methods --- src/core/sqlquery.cpp | 51 ++++++++++++++++++++++++++++++++++++++++++- src/core/sqlquery.h | 9 ++++++++ 2 files changed, 59 insertions(+), 1 deletion(-) diff --git a/src/core/sqlquery.cpp b/src/core/sqlquery.cpp index 96e42b405..56ceadd37 100644 --- a/src/core/sqlquery.cpp +++ b/src/core/sqlquery.cpp @@ -22,8 +22,9 @@ #include #include #include -#include #include +#include +#include #include "sqlquery.h" @@ -37,6 +38,54 @@ void SqlQuery::BindValue(const QString &placeholder, const QVariant &value) { } +void SqlQuery::BindStringValue(const QString &placeholder, const QString &value) { + + BindValue(placeholder, value.isNull() ? "" : value); + +} + +void SqlQuery::BindUrlValue(const QString &placeholder, const QUrl &value) { + + BindValue(placeholder, value.isValid() ? value.toString(QUrl::FullyEncoded) : ""); + +} + +void SqlQuery::BindIntValue(const QString &placeholder, const int value) { + + BindValue(placeholder, value <= 0 ? -1 : value); + +} + +void SqlQuery::BindLongLongValue(const QString &placeholder, const qint64 value) { + + BindValue(placeholder, value <= 0 ? -1 : value); + +} + +void SqlQuery::BindFloatValue(const QString &placeholder, const float value) { + + BindValue(placeholder, value <= 0 ? -1 : value); + +} + +void SqlQuery::BindBoolValue(const QString &placeholder, const bool value) { + + BindValue(placeholder, value ? 1 : 0); + +} + +void SqlQuery::BindNotNullIntValue(const QString &placeholder, const int value) { + + BindValue(placeholder, value == -1 ? QVariant() : value); + +} + +void SqlQuery::BindNotNullLongLongValue(const QString &placeholder, const qint64 value) { + + BindValue(placeholder, value == -1 ? QVariant() : value); + +} + bool SqlQuery::Exec() { bool success = exec(); diff --git a/src/core/sqlquery.h b/src/core/sqlquery.h index 7ea34529e..8ef285fdc 100644 --- a/src/core/sqlquery.h +++ b/src/core/sqlquery.h @@ -34,6 +34,15 @@ class SqlQuery : public QSqlQuery { explicit SqlQuery(const QSqlDatabase &db) : QSqlQuery(db) {} void BindValue(const QString &placeholder, const QVariant &value); + void BindStringValue(const QString &placeholder, const QString &value); + void BindUrlValue(const QString &placeholder, const QUrl &value); + void BindIntValue(const QString &placeholder, const int value); + void BindLongLongValue(const QString &placeholder, const qint64 value); + void BindFloatValue(const QString &placeholder, const float value); + void BindBoolValue(const QString &placeholder, const bool value); + void BindNotNullIntValue(const QString &placeholder, const int value); + void BindNotNullLongLongValue(const QString &placeholder, const qint64 value); + bool Exec(); QString LastQuery() const;