util: Implement SQLiteDatabase::execute()

This method relies on sqlite3_exec(), but currently doesn't allow to
retrieve data.
This commit is contained in:
Oleg Shparber 2017-04-20 23:00:44 -04:00
parent a994817308
commit b3fc62e2ae
2 changed files with 24 additions and 0 deletions

View File

@ -124,6 +124,28 @@ bool SQLiteDatabase::next()
return false; 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 QVariant SQLiteDatabase::value(int index) const
{ {
Q_ASSERT(index >= 0); Q_ASSERT(index >= 0);

View File

@ -44,6 +44,8 @@ public:
bool prepare(const QString &sql); bool prepare(const QString &sql);
bool next(); bool next();
bool execute(const QString &sql);
QVariant value(int index) const; QVariant value(int index) const;
QString lastError() const; QString lastError() const;