Results 1 to 4 of 4

Thread: Accessing sqlite3 handle causes exception

  1. #1
    Join Date
    Sep 2011
    Posts
    5
    Thanks
    1
    Qt products
    Qt3 Qt4
    Platforms
    MacOS X Windows

    Default Accessing sqlite3 handle causes exception

    I've been trying to access the sqlite3 handle and getting into an exception: "Unhandled exception at 0x778f15de in app.exe: 0xC0000005: Access violation."

    Any idea? I've been following the following thread and somehow managed to not get the exception, but really not clear as to why (I've also asked on this thread):
    http://www.qtcentre.org/threads/3613...095#post238095

    And the code that causes the error:
    Here's the code:

    Qt Code:
    1. db = QSqlDatabase::addDatabase("QSQLITE", "testsqliteptr");
    2. db.setDatabaseName("blabla.sqlite");
    3. if (!db.open()) {
    4. return -1;
    5. }
    6.  
    7. v = db.driver()->handle();
    8. sqlite3* sql3_db = *static_cast<sqlite3 **>(v.data());
    9. //<tag_error>
    10. sqlite3_exec(sql3_db, "CREATE TABLE if not exists ABC(foo,bar)", 0, 0, 0);
    To copy to clipboard, switch view to plain text mode 

    Thank you in advance.

  2. #2
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,359
    Thanks
    3
    Thanked 5,015 Times in 4,792 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: Accessing sqlite3 handle causes exception

    First of all, maybe you should first check if the returned variant is valid? Second of all, you don't need a native handle to create a table in the database.
    Your biological and technological distinctiveness will be added to our own. Resistance is futile.

    Please ask Qt related questions on the forum and not using private messages or visitor messages.


  3. #3
    Join Date
    Mar 2009
    Location
    Brisbane, Australia
    Posts
    7,729
    Thanks
    13
    Thanked 1,610 Times in 1,537 Posts
    Qt products
    Qt4 Qt5
    Platforms
    Unix/X11 Windows
    Wiki edits
    17

    Default Re: Accessing sqlite3 handle causes exception

    You could take your error checking lead from the example code in the docs:
    Qt Code:
    1. QSqlDatabase db = ...;
    2. QVariant v = db.driver()->handle();
    3. if (v.isValid() && qstrcmp(v.typeName(), "sqlite3*") == 0) {
    4. // v.data() returns a pointer to the handle
    5. sqlite3 *handle = *static_cast<sqlite3 **>(v.data());
    6. if (handle != 0) { // check that it is not NULL
    7. ...
    8. }
    9. }
    To copy to clipboard, switch view to plain text mode 

    You may also come to grief because the Sqlite version the plugin is built against (maybe internal, maybe system supplied), and the version your application is built against are incompatible.

  4. #4
    Join Date
    Sep 2011
    Posts
    5
    Thanks
    1
    Qt products
    Qt3 Qt4
    Platforms
    MacOS X Windows

    Default Re: Accessing sqlite3 handle causes exception

    Quote Originally Posted by wysota View Post
    First of all, maybe you should first check if the returned variant is valid? Second of all, you don't need a native handle to create a table in the database.
    Sorry for my poor description and code. The values returned are valid. And I know this because the above code works when I first do sqlite3_backup_init() as suggested in this thread (http://www.qtcentre.org/threads/3613...558#post207558). I unfortunately need the native handle to work with an existing library/functions. Any help would be appreciated.


    Added after 6 minutes:


    Quote Originally Posted by ChrisW67 View Post
    You could take your error checking lead from the example code in the docs:
    Qt Code:
    1. QSqlDatabase db = ...;
    2. QVariant v = db.driver()->handle();
    3. if (v.isValid() && qstrcmp(v.typeName(), "sqlite3*") == 0) {
    4. // v.data() returns a pointer to the handle
    5. sqlite3 *handle = *static_cast<sqlite3 **>(v.data());
    6. if (handle != 0) { // check that it is not NULL
    7. ...
    8. }
    9. }
    To copy to clipboard, switch view to plain text mode 

    You may also come to grief because the Sqlite version the plugin is built against (maybe internal, maybe system supplied), and the version your application is built against are incompatible.
    I should really tidy the code before asking here, but the values returned are valid. The code works without exception when I first call sqlite3_backup_init() as suggested in this thread (http://www.qtcentre.org/threads/3613...558#post207558). I am linking against the sqlite3.c file located in e.g. C:\Qt\4.8.4.sqlite\vs2008\src\3rdparty\sqlite. I presume the QtSql.dll (which is statically linked to the sqlite3 driver with vs2008) is compiled against the same splite3.c file. Feeling lost...
    Last edited by paulanon; 6th February 2013 at 04:21.

Similar Threads

  1. Replies: 6
    Last Post: 20th June 2012, 13:21
  2. Replies: 0
    Last Post: 19th April 2012, 15:52
  3. Replies: 4
    Last Post: 1st May 2010, 14:02
  4. Exception (crash) when accessing QImage pixel
    By TheJim01 in forum Newbie
    Replies: 2
    Last Post: 19th February 2010, 21:53
  5. handle exception in Qt
    By Qt Coder in forum Qt Programming
    Replies: 4
    Last Post: 6th April 2009, 06:05

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.