From b28d0f63ec07880b191e83e12385a2befaac5620 Mon Sep 17 00:00:00 2001 From: Martin Kleusberg Date: Fri, 10 Aug 2018 19:09:12 +0200 Subject: [PATCH] Show SQLite and SQLCipher version in About dialog when using SQLCipher See issue #1474. --- src/AboutDialog.cpp | 15 +++++++++------ src/sqlitedb.cpp | 26 ++++++++++++++++++++++++++ src/sqlitedb.h | 3 +++ 3 files changed, 38 insertions(+), 6 deletions(-) diff --git a/src/AboutDialog.cpp b/src/AboutDialog.cpp index 12fe718d..b3907ddf 100644 --- a/src/AboutDialog.cpp +++ b/src/AboutDialog.cpp @@ -1,6 +1,6 @@ #include "AboutDialog.h" #include "ui_AboutDialog.h" -#include "sqlite.h" +#include "sqlitedb.h" #include "Application.h" AboutDialog::AboutDialog(QWidget *parent) : @@ -11,13 +11,16 @@ AboutDialog::AboutDialog(QWidget *parent) : this->setFixedSize(this->width(), this->height()); this->setWindowFlags(this->windowFlags() & ~Qt::WindowContextHelpButtonHint); + QString sqlite_version, sqlcipher_version; + DBBrowserDB::getSqliteVersion(sqlite_version, sqlcipher_version); + if(sqlcipher_version.isNull()) + sqlite_version = tr("SQLite Version ") + sqlite_version; + else + sqlite_version = tr("SQLCipher Version ") + sqlcipher_version + tr(" (based on SQLite %1)").arg(sqlite_version); + ui->label_version->setText(tr("Version ") + Application::versionString() + "\n\n" + tr("Qt Version ") + QT_VERSION_STR + "\n\n" + -#ifdef ENABLE_SQLCIPHER - tr("SQLCipher based on SQLite Version ") + SQLITE_VERSION -#else - tr("SQLite Version ") + SQLITE_VERSION -#endif + sqlite_version ); } diff --git a/src/sqlitedb.cpp b/src/sqlitedb.cpp index ee5bd744..c9e3b353 100644 --- a/src/sqlitedb.cpp +++ b/src/sqlitedb.cpp @@ -375,6 +375,32 @@ bool DBBrowserDB::tryEncryptionSettings(const QString& filePath, bool* encrypted } } +void DBBrowserDB::getSqliteVersion(QString& sqlite, QString& sqlcipher) +{ + sqlite = QString(SQLITE_VERSION); + + // The SQLCipher version must be queried via a pragma and for a pragma we need a database connection. + // Because we want to be able to query the SQLCipher version without opening a database file first, we + // open a separate connection to an in-memory database here. + sqlcipher = QString(); +#ifdef ENABLE_SQLCIPHER + sqlite3* dummy; + if(sqlite3_open(":memory:", &dummy) == SQLITE_OK) + { + sqlite3_stmt* stmt; + if(sqlite3_prepare_v2(dummy, "PRAGMA cipher_version", -1, &stmt, nullptr) == SQLITE_OK) + { + if(sqlite3_step(stmt) == SQLITE_ROW) + sqlcipher = QByteArray(static_cast(sqlite3_column_blob(stmt, 0)), sqlite3_column_bytes(stmt, 0)); + + sqlite3_finalize(stmt); + } + + sqlite3_close(dummy); + } +#endif +} + bool DBBrowserDB::setSavepoint(const QString& pointname) { if(!isOpen()) diff --git a/src/sqlitedb.h b/src/sqlitedb.h index 573b1917..641530b6 100644 --- a/src/sqlitedb.h +++ b/src/sqlitedb.h @@ -61,6 +61,9 @@ public: bool create ( const QString & db); bool close(); + // This returns the SQLite version as well as the SQLCipher if DB4S is compiled with encryption support + static void getSqliteVersion(QString& sqlite, QString& sqlcipher); + typedef std::unique_ptr db_pointer_type; /**