Qt6 compatibility

This commit is contained in:
silverqx
2021-06-09 21:32:02 +02:00
parent f82c09d099
commit 5f5002fc30
7 changed files with 46 additions and 6 deletions

View File

@@ -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 \

View File

@@ -214,7 +214,7 @@ namespace Orm
const std::optional<qint64> 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<qint64> 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);

View File

@@ -4,6 +4,8 @@
#include <QString>
#include <QVariant>
#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. */

View File

@@ -0,0 +1,29 @@
#ifndef BOUNDVALUES_HPP
#define BOUNDVALUES_HPP
#if QT_VERSION >= QT_VERSION_CHECK(6, 0, 0)
#include <QList>
#else
#include <QMap>
#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<QVariant>;
#else
using BoundValues = QMap<QString, QVariant>;
#endif
} // namespace Orm::Types
#ifdef TINYORM_COMMON_NAMESPACE
} // namespace TINYORM_COMMON_NAMESPACE
#endif
#endif // BOUNDVALUES_HPP

View File

@@ -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<QString, QVariant> 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. */

View File

@@ -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});

View File

@@ -46,7 +46,7 @@ QString parseExecutedQuery(const QSqlQuery &query)
}
QString parseExecutedQueryForPretend(QString query,
const QVariantMap &bindings)
const Orm::Types::BoundValues &bindings)
{
QString boundValue;