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";
/***************************************
* Edit path to your places.sqlite here
***************************************/
db.setDatabaseName("/home/user/.mozilla/firefox/profile/places.sqlite");
qDebug() << "Opening database, status: " << db.open();
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();
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;
}
#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;
}
To copy to clipboard, switch view to plain text mode
The error is fired at first QSqlQuery, QSqlDatabase :: open() returns true ...
Thanks in advance
Bookmarks