Results 1 to 9 of 9

Thread: Attempting to use Sqlite backup api from driver handle fails

Hybrid View

Previous Post Previous Post   Next Post Next Post
  1. #1
    Join Date
    Apr 2015
    Posts
    1
    Qt products
    Qt5
    Platforms
    MacOS X Windows

    Default Re: Attempting to use Sqlite backup api from driver handle fails

    The answer is already here, but not written explicitly. THE call that makes the difference between crash and no crash is sqlite3_open. Apparently having the sqlite3.dll plugin on one side and the sqlite3.c compiled in on the other (to be able to call any of the sqlite3 API directly messes up or misses some init. So basically what is needed is:
    1. Include sqlite code (.c and .h files) in your project
    2. Use this snippet after m_Database.open()::
    Qt Code:
    1. QVariant v = m_Database.driver()->handle();
    2. if (v.isValid() && strcmp(v.typeName(), "sqlite3*") == 0) {
    3. // v.data() returns a pointer to the handle
    4. sqlite3 *handle = *static_cast<sqlite3 **>(v.data());
    5. if (handle != 0) { // check that it is not NULL
    6. sqlite3 *p; //without this there is a crash.
    7. int result = sqlite3_open( ":memory:", &p );
    8. if (result == SQLITE_OK) {
    9. sqlite3_close(p);
    10. //call any API you need on handle.
    11. } else
    12. qDebug() << "Could not sqlite3_open p" << result;
    13. } else {
    14. qDebug() << "Could not get sqlite handle";
    15. }
    16. } else {
    17. qDebug() << "handle variant returned typename " << v.typeName();
    18. }
    To copy to clipboard, switch view to plain text mode 
    Last edited by jimmytaker; 12th June 2016 at 04:48.

  2. #2

    Default Re: Attempting to use Sqlite backup api from driver handle fails

    hello
    I still having this problem
    with throw exception at this section:

    SQLITE_PRIVATE void sqlite3WalEndReadTransaction(Wal *pWal){
    sqlite3WalEndWriteTransaction(pWal);
    if( pWal->readLock>=0 ){
    walUnlockShared(pWal, WAL_READ_LOCK(pWal->readLock));
    pWal->readLock = -1;
    }
    }


    and I attempts all your answers

    here my code

    QSqlDatabase m_db = QSqlDatabase::addDatabase("QSQLITE");

    m_db.setDatabaseName(":memory:");
    m_db.open();
    qDebug() << "create: " << m_db.driverName();

    // create a table in the memory DB
    QSqlQuery q_create = m_db.exec("CREATE TABLE qdn (id int, name varchar(50))");
    qDebug() << "create: " << q_create.lastError();

    // populate with some data
    QSqlQuery q_insert(m_db);
    q_insert.prepare("INSERT INTO qdn (id, name) VALUES (:id, :name)");
    q_insert.bindValue(":id", QVariant::fromValue(1));
    q_insert.bindValue(":name", "Volker");
    qDebug() << "insert volker: " << q_insert.exec();

    q_insert.bindValue(":id", QVariant::fromValue(2));
    q_insert.bindValue(":name", "Root");
    qDebug() << "insert root: " << q_insert.exec();

    // get the inner sqlite3 handle(as QVariant)
    QVariant v = m_db.driver()->handle();
    //// check its validity
    if (v.isValid() && strcmp(v.typeName(), "sqlite3*") == 0)
    {

    // v.data() returns a pointer to the handle
    // it is valid, so cast to sqlite3 handle
    sqlite3 *handle = *static_cast<sqlite3 **>(v.data());
    if (handle != 0)
    {

    loadOrSaveDb(handle, "d:/backupfrommemory.sqlite", 1);
    }
    else
    {
    qDebug() << "Could not get sqlite handle";
    }
    }

    else
    {
    qDebug() << "handle variant returned typename " << v.typeName();
    }
    }

    also I tried with sqliteDBMemFile as answer but also same error ... so please if I can find help
    with thanks

Similar Threads

  1. QT & SQLite - driver not loaded
    By Tomasz in forum Newbie
    Replies: 5
    Last Post: 15th June 2014, 11:59
  2. Sqlite driver not loading
    By waynew in forum Installation and Deployment
    Replies: 4
    Last Post: 23rd May 2010, 13:15
  3. Embed SQLite driver
    By NoRulez in forum Qt Programming
    Replies: 2
    Last Post: 7th October 2009, 09:41
  4. SQLite driver unavailable
    By kandalf in forum Installation and Deployment
    Replies: 5
    Last Post: 11th February 2009, 16:36
  5. SQlite driver not loaded error
    By ibergmark in forum Installation and Deployment
    Replies: 2
    Last Post: 17th March 2008, 01:09

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.