From b3fc62e2ae865901906ec1e89f32f0040545bdd9 Mon Sep 17 00:00:00 2001 From: Oleg Shparber Date: Thu, 20 Apr 2017 23:00:44 -0400 Subject: [PATCH] util: Implement SQLiteDatabase::execute() This method relies on sqlite3_exec(), but currently doesn't allow to retrieve data. --- src/libs/util/sqlitedatabase.cpp | 22 ++++++++++++++++++++++ src/libs/util/sqlitedatabase.h | 2 ++ 2 files changed, 24 insertions(+) diff --git a/src/libs/util/sqlitedatabase.cpp b/src/libs/util/sqlitedatabase.cpp index c2399e1..223c0de 100644 --- a/src/libs/util/sqlitedatabase.cpp +++ b/src/libs/util/sqlitedatabase.cpp @@ -124,6 +124,28 @@ bool SQLiteDatabase::next() return false; } +bool SQLiteDatabase::execute(const QString &sql) +{ + if (m_db == nullptr) { + return false; + } + + m_lastError.clear(); + + char *errmsg = nullptr; + const int rc = sqlite3_exec(m_db, sql.toUtf8(), nullptr, nullptr, &errmsg); + + if (rc != SQLITE_OK) { + if (errmsg) { + m_lastError = QString::fromUtf8(errmsg); + sqlite3_free(errmsg); + } + return false; + } + + return true; +} + QVariant SQLiteDatabase::value(int index) const { Q_ASSERT(index >= 0); diff --git a/src/libs/util/sqlitedatabase.h b/src/libs/util/sqlitedatabase.h index fdf668d..e867343 100644 --- a/src/libs/util/sqlitedatabase.h +++ b/src/libs/util/sqlitedatabase.h @@ -44,6 +44,8 @@ public: bool prepare(const QString &sql); bool next(); + bool execute(const QString &sql); + QVariant value(int index) const; QString lastError() const;