Ferenc Deak
Ferenc Deak

Reputation: 35408

Qt and sqlite error 26

I try to open an Sqlite database with Qt to execute the following query:

select name from sqlite_master where type = 'table'; 

And the database gets opened successfully, but when I execute the query, I get error 26: file is encrypted or is not a database. When I open the same database with the sqlite command line, however it works fine. Qt version is 4.8.1, the sqlite file starts with ** This file contains an SQLite 2.1 database ** operating system is Linux, sqlite version installed is 2.8.17.

Any idea what is wrong with this?

Thanks, f.

Edit: Opening it like:

QSqlDatabase dbo = QSqlDatabase::addDatabase("QSQLITE", "connName");
dbo.setDatabaseName("/home/myself/test.sqlite");
dbo.open();
if(!dbo.isOpen())
{
    qDebug() << dbo.lastError();
    return;
}
QSqlQuery query(dbo);
bool ok = query.exec("select name from sqlite_master where type = 'table';");
if(!ok)
{ 
  //get error code, etc...
}

and it is Not OK :(

Edit2: I have tried with a different sqlite file, one which starts with: SQLite format 3 and it works nicely. Seems out of the box Qt support for Sqlite 2 is not working as expected.

Upvotes: 1

Views: 1188

Answers (1)

CL.
CL.

Reputation: 180060

SQLite 3.x (as included in Qt) cannot open SQLite 2 files.

SQLite 2 has been obsolete for many years. You should upgrade your databse:

sqlite2 old-db.sqlite .dump > backupfile
sqlite3 new-db.sqlite < backupfile

Upvotes: 2

Related Questions