QtCipherSqlitePlugin icon indicating copy to clipboard operation
QtCipherSqlitePlugin copied to clipboard

Password update is not working!

Open isocollection opened this issue 8 years ago • 2 comments

  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?

isocollection avatar Apr 24 '17 06:04 isocollection

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

DisableAsync avatar Oct 16 '17 09:10 DisableAsync

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();

devbean avatar Oct 17 '17 05:10 devbean