PDA

View Full Version : QSqlDatabase cannot open database



nowrep
22nd October 2011, 22:14
Hello,
I have strange issue with QSqlDatabase and Mozilla Firefox places.sqlite database.
Info: http://kb.mozillazine.org/Places.sqlite
On Linux (gcc 64bit):
When I try to open database and using Qt 4.7.4 debug build (from QtSDK), I get error "file is encrypted or is not database".
When I use 4.7.2 release build in Debian Wheezy repository, all works fine. But when I use 4.7.2 build from QtSDK, I get this error again.

On Windows 7 (msvc 2008):
When I use 4.7.4 or 4.7.2 (both from QtSDK), it doesn't matter, I get the error.

In the same code, opening my SQLite database work without problems. It is only places.sqlite specific issue.
Just to make it complete, I am attaching the code (but obviously, it is not problem in my code as it is working with debian qt) to test it by yourself


#include <QObject>
#include <QSqlDatabase>
#include <QSqlQuery>
#include <QDebug>
#include <QSqlError>
#include <QVariant>

int main()
{
bool m_error = false;
QString m_errorString = "No Error";

QSqlDatabase db = QSqlDatabase::addDatabase("QSQLITE");
/***************************************
* Edit path to your places.sqlite here
***************************************/
db.setDatabaseName("/home/user/.mozilla/firefox/profile/places.sqlite");

qDebug() << "Opening database, status: " << db.open();

QSqlQuery query(db);
query.exec("SELECT title, fk FROM moz_bookmarks WHERE title != ''");
while(query.next()) {
QString title = query.value(0).toString();
int placesId = query.value(1).toInt();

QSqlQuery query2(db);
query2.exec("SELECT url FROM moz_places WHERE id=" + QString::number(placesId));

if (!query2.next())
continue;

QString url = query2.value(0).toString();

if (title.isEmpty() || url.isEmpty() || url.startsWith("place:"))
continue;

qDebug() << title << url;
}

if (query.lastError().isValid()) {
m_error = true;
m_errorString = query.lastError().text();
}

qDebug() << "error: " << m_error;
qDebug() << "error string: " << m_errorString;

return 0;
}

The error is fired at first QSqlQuery, QSqlDatabase :: open() returns true ...

Thanks in advance

slaxZ
22nd November 2011, 08:51
Hi had similar issue, solved copying sqldrivers folder in deploy directory.

sqldrivers contains:
libqsqlite4.a,libqsqlited4.a,qsqlite4.dll,qsqlited 4.dll.

Reason:" Most probably, the qtsqlite.dll itself depends on original SQLite DLL's which you probably need to copy as well."

On XP it is working without supplying also sqldrivers folder.

nowrep
9th December 2011, 22:21
Hi, thanks for reply.
I am shipping all necessary drivers within Windows installer, so unfortunately missing qsqlite4.dll is not the problem.
I have no problems opening and editing other databases, just the firefox one is not working.
And I cannot ship qsql drivers for Linux distributions.