×

Discussion Board

Results 1 to 7 of 7
  1. #1
    Registered User
    Join Date
    Mar 2009
    Location
    Italy
    Posts
    153

    QSqlDatabase("QSQLITE") and sqlite3_create_function

    Hello,
    i'm using QSql to open a sqlite3 db...however i must create my own custom function using sqlite3_create_function().

    I used a snippet of code from Qt help to get sqlite3 handle, like below:
    QSqlDatabase db = ...;
    QVariant v = db.driver()->handle();
    if (v.isValid() && qstrcmp(v.typeName(), "sqlite3*")==0) {
    // v.data() returns a pointer to the handle
    sqlite3 *handle = *static_cast<sqlite3 **>(v.data());
    if (handle != 0) { // check that it is not NULL
    ...
    }
    }

    that returns a valid sqlite3 handle, but when I use it with sqlite3_create_function() i get a segmentation fault;
    if i open a database with native sqlite3 API (sqlite3_open), sqlite3_create_function works very well (both on simulator and on a device).
    How I can resolve it?
    Thanks
    Gianni
    Merry Christmas Tombola! available on OVI Store!
    SuperDaddy available on OVI Store!

    QT VirtualKeyboard: http://qt-apps.org/content/show.php/VirtualKeyboard?content=107388
    Crack Generator: http://qt-apps.org/content/show.php/MosaicCrack?content=121832

  2. #2
    Super Contributor
    Join Date
    Nov 2009
    Location
    Minnesota, USA
    Posts
    3,209

    Re: QSqlDatabase("QSQLITE") and sqlite3_create_function

    I've never tried the custom function feature on the phone (or anywhere else, for that matter). I can't say with any certainty that it works on Symbian.

    Also, it's possible that the Symbian drivers for Sqlite are different and you can't get access to the handle the same way.

    It might be worth a try to print out the hex value of the handle to see if it looks like a valid address. And then dereference it (cast to byte* and fetch a byte) to see if it's at least allocated/accessible storage.

    Can you run the phone app through the debugger and get a clue as to where it's blowing up?

  3. #3
    Registered User
    Join Date
    Mar 2009
    Location
    Italy
    Posts
    153

    Re: QSqlDatabase("QSQLITE") and sqlite3_create_function

    Quote Originally Posted by danhicksbyron View Post
    I've never tried the custom function feature on the phone (or anywhere else, for that matter). I can't say with any certainty that it works on Symbian.

    Also, it's possible that the Symbian drivers for Sqlite are different and you can't get access to the handle the same way.

    It might be worth a try to print out the hex value of the handle to see if it looks like a valid address. And then dereference it (cast to byte* and fetch a byte) to see if it's at least allocated/accessible storage.

    Can you run the phone app through the debugger and get a clue as to where it's blowing up?
    I've accessed throuth a simulator and, as qt help tells, it returns a null pointer if it isn't valid (my pointer seems a valid address). I've tested it on simulator and on a device (with native sqlite3 api).
    Merry Christmas Tombola! available on OVI Store!
    SuperDaddy available on OVI Store!

    QT VirtualKeyboard: http://qt-apps.org/content/show.php/VirtualKeyboard?content=107388
    Crack Generator: http://qt-apps.org/content/show.php/MosaicCrack?content=121832

  4. #4
    Registered User
    Join Date
    Mar 2009
    Location
    Italy
    Posts
    153

    Re: QSqlDatabase("QSQLITE") and sqlite3_create_function

    Ok i've resolved it!
    Simply the snippet code works well if embedded into code before sqlite3_create_function()...it doesn't work if it is wrapped into a function like below:
    sqlite * getDriver()
    {
    QT help code
    return (handle);
    }
    returned value is not null, but doesn't work
    Merry Christmas Tombola! available on OVI Store!
    SuperDaddy available on OVI Store!

    QT VirtualKeyboard: http://qt-apps.org/content/show.php/VirtualKeyboard?content=107388
    Crack Generator: http://qt-apps.org/content/show.php/MosaicCrack?content=121832

  5. #5
    Super Contributor
    Join Date
    Nov 2009
    Location
    Minnesota, USA
    Posts
    3,209

    Re: QSqlDatabase("QSQLITE") and sqlite3_create_function

    If you had the "QSqlDatabase db = ...;" in a subroutine, yeah, that's a problem. That's an "automatic" object, and it passes out of scope when the subroutine exits -- basically it gets destroyed. If it worked on any platform it would be accidental.

    The rest of the code should be OK in a subroutine, though.

  6. #6
    Registered User
    Join Date
    Mar 2009
    Location
    Italy
    Posts
    153

    Re: QSqlDatabase("QSQLITE") and sqlite3_create_function

    Quote Originally Posted by danhicksbyron View Post
    If you had the "QSqlDatabase db = ...;" in a subroutine, yeah, that's a problem. That's an "automatic" object, and it passes out of scope when the subroutine exits -- basically it gets destroyed. If it worked on any platform it would be accidental.

    The rest of the code should be OK in a subroutine, though.
    Sorry i've copied it, but no, my code has QSqlDatabase variable with class scope!
    Merry Christmas Tombola! available on OVI Store!
    SuperDaddy available on OVI Store!

    QT VirtualKeyboard: http://qt-apps.org/content/show.php/VirtualKeyboard?content=107388
    Crack Generator: http://qt-apps.org/content/show.php/MosaicCrack?content=121832

  7. #7
    Registered User
    Join Date
    Mar 2009
    Location
    Italy
    Posts
    153

    Re: QSqlDatabase("QSQLITE") and sqlite3_create_function

    Hi,
    i've a problem under Qt Simulator:
    i'm using QSqlDatabase & co. for operate on db, but, due to custom function, i'm also using sqlte3_create_function getting sqlite3 * from QSqlDriver.
    Because of i link for native API a recent sqlite3.dll, there is a conflict version between the handle returned by QSqlDriver and the dll used by native API, i think.

    How can i link (and get) the same version used by Simulator?
    Merry Christmas Tombola! available on OVI Store!
    SuperDaddy available on OVI Store!

    QT VirtualKeyboard: http://qt-apps.org/content/show.php/VirtualKeyboard?content=107388
    Crack Generator: http://qt-apps.org/content/show.php/MosaicCrack?content=121832

Similar Threads

  1. Is there a way to "edit" and "save" the "texts" of received SMS messages?
    By pamir_yasti in forum General Development Questions
    Replies: 1
    Last Post: 2010-07-16, 10:15
  2. Replies: 3
    Last Post: 2009-06-18, 21:42
  3. "The instruction at "0x0043c30e" referenced memory at "0x00000044".
    By viswanadhr in forum Symbian Tools & SDKs
    Replies: 1
    Last Post: 2002-11-08, 07:51

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
×