Fix attaching not encrypted databases in the SQLCipher build

Even when trying to attach a non-encrypted database in the SQLCipher
build we would try to give a passphrase - though an empty one. This
yields an invalid SQL statement, so attaching would never work. This is
fixed by this commit.

See issue #1088.
This commit is contained in:
Martin Kleusberg
2017-08-15 11:23:51 +02:00
parent c3ab20b6b5
commit 60a48ce9ec
+3 -2
View File
@@ -178,8 +178,9 @@ bool DBBrowserDB::attach(const QString& filename, QString attach_as)
// Attach database
QString key;
if(cipher) key = cipher->password();
if(!executeSQL(QString("ATTACH '%1' AS %2 KEY %3").arg(filename).arg(sqlb::escapeIdentifier(attach_as)).arg(key), false))
if(cipher && is_encrypted)
key = "KEY " + cipher->password();
if(!executeSQL(QString("ATTACH '%1' AS %2 %3").arg(filename).arg(sqlb::escapeIdentifier(attach_as)).arg(key), false))
{
QMessageBox::warning(0, qApp->applicationName(), lastErrorMessage);
return false;