Skip to content

Commit b28d0f6

Browse files
committed
Show SQLite and SQLCipher version in About dialog when using SQLCipher
See issue #1474.
1 parent a1c982c commit b28d0f6

3 files changed

Lines changed: 38 additions & 6 deletions

File tree

src/AboutDialog.cpp

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
#include "AboutDialog.h"
22
#include "ui_AboutDialog.h"
3-
#include "sqlite.h"
3+
#include "sqlitedb.h"
44
#include "Application.h"
55

66
AboutDialog::AboutDialog(QWidget *parent) :
@@ -11,13 +11,16 @@ AboutDialog::AboutDialog(QWidget *parent) :
1111
this->setFixedSize(this->width(), this->height());
1212
this->setWindowFlags(this->windowFlags() & ~Qt::WindowContextHelpButtonHint);
1313

14+
QString sqlite_version, sqlcipher_version;
15+
DBBrowserDB::getSqliteVersion(sqlite_version, sqlcipher_version);
16+
if(sqlcipher_version.isNull())
17+
sqlite_version = tr("SQLite Version ") + sqlite_version;
18+
else
19+
sqlite_version = tr("SQLCipher Version ") + sqlcipher_version + tr(" (based on SQLite %1)").arg(sqlite_version);
20+
1421
ui->label_version->setText(tr("Version ") + Application::versionString() + "\n\n" +
1522
tr("Qt Version ") + QT_VERSION_STR + "\n\n" +
16-
#ifdef ENABLE_SQLCIPHER
17-
tr("SQLCipher based on SQLite Version ") + SQLITE_VERSION
18-
#else
19-
tr("SQLite Version ") + SQLITE_VERSION
20-
#endif
23+
sqlite_version
2124
);
2225
}
2326

src/sqlitedb.cpp

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -375,6 +375,32 @@ bool DBBrowserDB::tryEncryptionSettings(const QString& filePath, bool* encrypted
375375
}
376376
}
377377

378+
void DBBrowserDB::getSqliteVersion(QString& sqlite, QString& sqlcipher)
379+
{
380+
sqlite = QString(SQLITE_VERSION);
381+
382+
// The SQLCipher version must be queried via a pragma and for a pragma we need a database connection.
383+
// Because we want to be able to query the SQLCipher version without opening a database file first, we
384+
// open a separate connection to an in-memory database here.
385+
sqlcipher = QString();
386+
#ifdef ENABLE_SQLCIPHER
387+
sqlite3* dummy;
388+
if(sqlite3_open(":memory:", &dummy) == SQLITE_OK)
389+
{
390+
sqlite3_stmt* stmt;
391+
if(sqlite3_prepare_v2(dummy, "PRAGMA cipher_version", -1, &stmt, nullptr) == SQLITE_OK)
392+
{
393+
if(sqlite3_step(stmt) == SQLITE_ROW)
394+
sqlcipher = QByteArray(static_cast<const char*>(sqlite3_column_blob(stmt, 0)), sqlite3_column_bytes(stmt, 0));
395+
396+
sqlite3_finalize(stmt);
397+
}
398+
399+
sqlite3_close(dummy);
400+
}
401+
#endif
402+
}
403+
378404
bool DBBrowserDB::setSavepoint(const QString& pointname)
379405
{
380406
if(!isOpen())

src/sqlitedb.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,9 @@ class DBBrowserDB : public QObject
6161
bool create ( const QString & db);
6262
bool close();
6363

64+
// This returns the SQLite version as well as the SQLCipher if DB4S is compiled with encryption support
65+
static void getSqliteVersion(QString& sqlite, QString& sqlcipher);
66+
6467
typedef std::unique_ptr<sqlite3, DatabaseReleaser> db_pointer_type;
6568

6669
/**

0 commit comments

Comments
 (0)