Results 1 to 3 of 3

Thread: QSqlDatabase cannot open database

  1. #1
    Join Date
    Dec 2010
    Posts
    6
    Thanked 2 Times in 1 Post
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows Symbian S60

    Exclamation QSqlDatabase cannot open database

    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

    Qt Code:
    1. #include <QObject>
    2. #include <QSqlDatabase>
    3. #include <QSqlQuery>
    4. #include <QDebug>
    5. #include <QSqlError>
    6. #include <QVariant>
    7.  
    8. int main()
    9. {
    10. bool m_error = false;
    11. QString m_errorString = "No Error";
    12.  
    13. QSqlDatabase db = QSqlDatabase::addDatabase("QSQLITE");
    14. /***************************************
    15.   * Edit path to your places.sqlite here
    16.   ***************************************/
    17. db.setDatabaseName("/home/user/.mozilla/firefox/profile/places.sqlite");
    18.  
    19. qDebug() << "Opening database, status: " << db.open();
    20.  
    21. QSqlQuery query(db);
    22. query.exec("SELECT title, fk FROM moz_bookmarks WHERE title != ''");
    23. while(query.next()) {
    24. QString title = query.value(0).toString();
    25. int placesId = query.value(1).toInt();
    26.  
    27. QSqlQuery query2(db);
    28. query2.exec("SELECT url FROM moz_places WHERE id=" + QString::number(placesId));
    29.  
    30. if (!query2.next())
    31. continue;
    32.  
    33. QString url = query2.value(0).toString();
    34.  
    35. if (title.isEmpty() || url.isEmpty() || url.startsWith("place:"))
    36. continue;
    37.  
    38. qDebug() << title << url;
    39. }
    40.  
    41. if (query.lastError().isValid()) {
    42. m_error = true;
    43. m_errorString = query.lastError().text();
    44. }
    45.  
    46. qDebug() << "error: " << m_error;
    47. qDebug() << "error string: " << m_errorString;
    48.  
    49. return 0;
    50. }
    To copy to clipboard, switch view to plain text mode 

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

    Thanks in advance
    Last edited by nowrep; 22nd October 2011 at 22:43.

  2. #2
    Join Date
    Nov 2011
    Posts
    1
    Qt products
    Qt3
    Platforms
    MacOS X

    Default Re: QSqlDatabase cannot open database

    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.

  3. #3
    Join Date
    Dec 2010
    Posts
    6
    Thanked 2 Times in 1 Post
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows Symbian S60

    Default Re: QSqlDatabase cannot open database

    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.

Similar Threads

  1. [SOLVED] database opened .. database not open
    By kapitanluffy in forum Qt Programming
    Replies: 1
    Last Post: 27th February 2011, 10:39
  2. How to detect QSqlDatabase is still open???
    By hashimov in forum Qt Programming
    Replies: 4
    Last Post: 25th January 2011, 08:17
  3. QSqlDatabase::open Segfaults
    By rich.remer in forum Qt Programming
    Replies: 3
    Last Post: 30th June 2010, 16:32
  4. How to BackUp DataBase and Restore it Use QSqlDataBase?
    By litterflybug in forum Qt Programming
    Replies: 1
    Last Post: 6th December 2009, 04:34
  5. Why QSqlDatabase::open() returns open?
    By gboelter in forum Newbie
    Replies: 7
    Last Post: 27th August 2009, 18:52

Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide.