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;
if (!_stmt) {
ASSERT(false);
#ifndef OWNSQL_H
#define OWNSQL_H
+#include <QLoggingCategory>
#include <QObject>
#include <QVariant>
struct sqlite3_stmt;
namespace OCC {
+OCSYNC_EXPORT Q_DECLARE_LOGGING_CATEGORY(lcSql)
class SqlQuery;
};
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;
int numRowsAffected();
void reset_and_clear_bindings();
void finish();
private:
+ void bindValueInternal(int pos, const QVariant &value);
+
SqlDatabase *_sqldb = nullptr;
sqlite3 *_db = nullptr;
sqlite3_stmt *_stmt = nullptr;
"INSERT OR REPLACE INTO flags(path, pinState) VALUES(?1, ?2);"),
_db->_db));
query.bindValue(1, path);
- query.bindValue(2, static_cast<int>(state));
+ query.bindValue(2, state);
query.exec();
}