Logging: Print enum before cast in SqlQuer::bindValue

This commit is contained in:
Hannah von Reth 2020-07-17 14:01:48 +02:00 committed by Kevin Ottens
parent b9638bc778
commit 29c6f44124
No known key found for this signature in database
GPG key ID: 074BBBCB8DECC9E2
3 changed files with 20 additions and 5 deletions

View file

@ -361,10 +361,8 @@ auto SqlQuery::next() -> NextResult
return result; return result;
} }
void SqlQuery::bindValue(int pos, const QVariant &value) void SqlQuery::bindValueInternal(int pos, const QVariant &value)
{ {
qCDebug(lcSql) << "SQL bind" << pos << value;
int res = -1; int res = -1;
if (!_stmt) { if (!_stmt) {
ASSERT(false); ASSERT(false);

View file

@ -19,6 +19,7 @@
#ifndef OWNSQL_H #ifndef OWNSQL_H
#define OWNSQL_H #define OWNSQL_H
#include <QLoggingCategory>
#include <QObject> #include <QObject>
#include <QVariant> #include <QVariant>
@ -28,6 +29,7 @@ struct sqlite3;
struct sqlite3_stmt; struct sqlite3_stmt;
namespace OCC { namespace OCC {
OCSYNC_EXPORT Q_DECLARE_LOGGING_CATEGORY(lcSql)
class SqlQuery; class SqlQuery;
@ -136,13 +138,28 @@ public:
}; };
NextResult next(); NextResult next();
void bindValue(int pos, const QVariant &value); template<class T, typename std::enable_if<std::is_enum<T>::value, int>::type = 0>
void bindValue(int pos, const T &value)
{
qCDebug(lcSql) << "SQL bind" << pos << value;
bindValueInternal(pos, static_cast<int>(value));
}
template<class T, typename std::enable_if<!std::is_enum<T>::value, int>::type = 0>
void bindValue(int pos, const T &value)
{
qCDebug(lcSql) << "SQL bind" << pos << value;
bindValueInternal(pos, value);
}
QString lastQuery() const; QString lastQuery() const;
int numRowsAffected(); int numRowsAffected();
void reset_and_clear_bindings(); void reset_and_clear_bindings();
void finish(); void finish();
private: private:
void bindValueInternal(int pos, const QVariant &value);
SqlDatabase *_sqldb = nullptr; SqlDatabase *_sqldb = nullptr;
sqlite3 *_db = nullptr; sqlite3 *_db = nullptr;
sqlite3_stmt *_stmt = nullptr; sqlite3_stmt *_stmt = nullptr;

View file

@ -2272,7 +2272,7 @@ void SyncJournalDb::PinStateInterface::setForPath(const QByteArray &path, PinSta
"INSERT OR REPLACE INTO flags(path, pinState) VALUES(?1, ?2);"), "INSERT OR REPLACE INTO flags(path, pinState) VALUES(?1, ?2);"),
_db->_db)); _db->_db));
query.bindValue(1, path); query.bindValue(1, path);
query.bindValue(2, static_cast<int>(state)); query.bindValue(2, state);
query.exec(); query.exec();
} }