devbean / QtCipherSqlitePlugin

A Qt plugin for cipher SQLite.
http://qtciphersqliteplugin.galaxyworld.org
GNU Lesser General Public License v2.1
380 stars 155 forks source link

Password update is not working! #10

Open isocollection opened 7 years ago

isocollection commented 7 years ago
  1. How to update new password for my database?

My code is:

    checkDb = QSqlDatabase::addDatabase("SQLITECIPHER");
    checkDb.setDatabaseName("test.db");
    checkDb.setPassword("test");

    if (!checkDb.open()) {
        qDebug() << "Can not open Db!" << checkDb.lastError().driverText();
    }
    else  {
        qDebug() << "try to change password";
        QString strNew;
        checkDb.setConnectOptions("QSQLITE_UPDATE_KEY=newtest");
        qDebug() <<  checkDb.lastError().driverText();
    }
    checkDb.close();

Password update is not working. I can not change my db password. How Can I fix it?

DisableAsync commented 6 years ago

Same problem updating password. Why is this issue submitted in Apr, and now in Oct it still has no reply?

devbean commented 6 years ago

Sorry for no reply for such a long time.

I think you misunderstand connectOptions. connectOptions should be set before QSqlDatabase::open(). You could think it is the options for connecting (opening) the database. So your code will not work because you set connectOptions after opening the database. Please check the following code:

QSqlDatabase dbconn = QSqlDatabase::addDatabase("SQLITECIPHER");
dbconn.setDatabaseName("test_c.db");
dbconn.setPassword("test");
dbconn.setConnectOptions("QSQLITE_UPDATE_KEY=newtest");
if (!dbconn.open()) {
    qDebug() << "Can not open Db!" << dbconn.lastError().driverText();
} else {
    qDebug() << "Password changed";
}
dbconn.close();