From 5f5002fc30c0048013a2ae5b0d824f42003c223f Mon Sep 17 00:00:00 2001 From: silverqx Date: Wed, 9 Jun 2021 21:32:02 +0200 Subject: [PATCH] Qt6 compatibility --- include/include.pri | 1 + include/orm/databaseconnection.hpp | 6 +++++- include/orm/logquery.hpp | 5 ++++- include/orm/types/boundvalues.hpp | 29 +++++++++++++++++++++++++++++ include/orm/types/log.hpp | 6 ++++-- src/orm/databaseconnection.cpp | 3 ++- src/orm/logquery.cpp | 2 +- 7 files changed, 46 insertions(+), 6 deletions(-) create mode 100644 include/orm/types/boundvalues.hpp diff --git a/include/include.pri b/include/include.pri index 316aa168c..ec7564f16 100644 --- a/include/include.pri +++ b/include/include.pri @@ -67,6 +67,7 @@ HEADERS += \ $$PWD/orm/tiny/relations/pivot.hpp \ $$PWD/orm/tiny/relations/relation.hpp \ $$PWD/orm/tiny/tinybuilder.hpp \ + $$PWD/orm/types/boundvalues.hpp \ $$PWD/orm/types/log.hpp \ $$PWD/orm/types/statementscounter.hpp \ $$PWD/orm/utils/attribute.hpp \ diff --git a/include/orm/databaseconnection.hpp b/include/orm/databaseconnection.hpp index fa07fe293..a82d3d447 100644 --- a/include/orm/databaseconnection.hpp +++ b/include/orm/databaseconnection.hpp @@ -214,7 +214,7 @@ namespace Orm const std::optional elapsed) const; /*! Log a query into the connection's query log in the pretending mode. */ void logQueryForPretend(const QString &query, - const QVariantMap &bindings) const; + const Types::BoundValues &bindings) const; /*! Log a transaction query into the connection's query log. */ void logTransactionQuery(const QString &query, const std::optional elapsed) const; @@ -506,7 +506,11 @@ namespace Orm to run and then log the query, bindings, and execution time. We'll log time in milliseconds. */ if (m_pretending) +#if QT_VERSION >= QT_VERSION_CHECK(6, 0, 0) + logQueryForPretend(queryString, bindings); +#else logQueryForPretend(queryString, convertPositionalToNamedBindings(bindings)); +#endif else logQuery(result, elapsed); diff --git a/include/orm/logquery.hpp b/include/orm/logquery.hpp index a79de85bc..8e24b67ca 100644 --- a/include/orm/logquery.hpp +++ b/include/orm/logquery.hpp @@ -4,6 +4,8 @@ #include #include +#include "orm/types/boundvalues.hpp" + class QSqlQuery; #ifdef TINYORM_COMMON_NAMESPACE @@ -14,7 +16,8 @@ namespace TINYORM_COMMON_NAMESPACE /*! Get the last executed query with replaced placeholders ( ideal for logging ). */ QString parseExecutedQuery(const QSqlQuery &query); /*! Get pretended query with replaced placeholders ( ideal for logging ). */ -QString parseExecutedQueryForPretend(QString query, const QVariantMap &bindings); +QString parseExecutedQueryForPretend(QString query, + const Orm::Types::BoundValues &bindings); #ifdef QT_DEBUG /*! Log the last executed query to the debug output. */ diff --git a/include/orm/types/boundvalues.hpp b/include/orm/types/boundvalues.hpp new file mode 100644 index 000000000..332d181f1 --- /dev/null +++ b/include/orm/types/boundvalues.hpp @@ -0,0 +1,29 @@ +#ifndef BOUNDVALUES_HPP +#define BOUNDVALUES_HPP + +#if QT_VERSION >= QT_VERSION_CHECK(6, 0, 0) +#include +#else +#include +#endif + +#ifdef TINYORM_COMMON_NAMESPACE +namespace TINYORM_COMMON_NAMESPACE +{ +#endif +namespace Orm::Types +{ + +#if QT_VERSION >= QT_VERSION_CHECK(6, 0, 0) + using BoundValues = QList; +#else + using BoundValues = QMap; +#endif + +} // namespace Orm::Types +#ifdef TINYORM_COMMON_NAMESPACE +} // namespace TINYORM_COMMON_NAMESPACE +#endif + + +#endif // BOUNDVALUES_HPP diff --git a/include/orm/types/log.hpp b/include/orm/types/log.hpp index b300d7486..942877b65 100644 --- a/include/orm/types/log.hpp +++ b/include/orm/types/log.hpp @@ -1,6 +1,8 @@ #ifndef LOG_HPP #define LOG_HPP +#include "orm/types/boundvalues.hpp" + #ifdef TINYORM_COMMON_NAMESPACE namespace TINYORM_COMMON_NAMESPACE { @@ -24,9 +26,9 @@ namespace Types /*! Executed query. */ QString query; /*! Map of bound values. */ - QMap boundValues {}; + BoundValues boundValues {}; /*! Type of the query in log record. */ - const Type type = Type::UNDEFINED; + Type type = Type::UNDEFINED; /*! Order of the query log record. */ std::size_t order = 0; /*! Query execution time. */ diff --git a/src/orm/databaseconnection.cpp b/src/orm/databaseconnection.cpp index a0e2a1b95..f194b8cf2 100644 --- a/src/orm/databaseconnection.cpp +++ b/src/orm/databaseconnection.cpp @@ -809,7 +809,8 @@ void DatabaseConnection::logQuery( } void DatabaseConnection::logQueryForPretend( - const QString &query, const QVariantMap &bindings) const + const QString &query, + const Types::BoundValues &bindings) const { if (m_loggingQueries && m_queryLog) m_queryLog->append({query, bindings, Log::Type::NORMAL, ++m_queryLogId}); diff --git a/src/orm/logquery.cpp b/src/orm/logquery.cpp index 5036f4356..50eecce75 100644 --- a/src/orm/logquery.cpp +++ b/src/orm/logquery.cpp @@ -46,7 +46,7 @@ QString parseExecutedQuery(const QSqlQuery &query) } QString parseExecutedQueryForPretend(QString query, - const QVariantMap &bindings) + const Orm::Types::BoundValues &bindings) { QString boundValue;