• Can I use some of sqlite APIs like sqlite3_create_function from qt ??

    And If I can't do that I have another question,
    Can I link SQlite library in my qt project and use the same database handle in the library and qt sqlite calls ??

    Thanks in advance

  • Great topic :) Have you tried the solution for using "same database handler for QSqlDatabase and sqlite3_create_function proposed at this thread from stackoverflow.com":http://stackoverflow.com/questions/6289623/using-sqlite-custom-functions-with-qt ?

  • Yes I use the same code their but it crash when I call sqlite3_create_function.
    I think it crashes in this line

    sqlite3_mutex_enter(db->mutex); in "sqlite3_create_function_v2" function sqlite3.c file
    when entering mutex

    and I checked the sqlite3* values in debug mode it seems to be rubbish data or wrong casting

    Hint : I used the same checks in the example and they all passed fine !!!!

  • [quote author="ahmedalaa" date="1363796613"]
    Hint : I used the same checks in the example and they all passed fine !!!![/quote]

    Btw on what platform and OS do you run your code?

  • I am on windows 7 x64 and building a 64 bit application on VS 2012 using Qt 4.8.4

    First I tried to use qt sqlite driver to link to these functions it gave me linking error
    then I compiled the sqlite 3.7 as a library and linked in my application it linked successfully

    and when I open the database with the sqlite APIs and don't use the qt handle of database it works fine
    but when I use the qt handle of the database it crashes as I told you before

    Question here can I link to those function using qt sqlite driver only? OR even can I use the qt database handle in call of another sqlite library?

    Thanks in advance :)

  • I have succeeded to make it link using qt sqlite driver by rebuilding the driver and redefining SQLITE_API by Q_SQL_EXPORT to export sqlite APIs

    But it still crashes in the call of sqlite3_create_function

    @QVariant v = db.driver()->handle();
    // Create a handler and attach functions.
    sqlite3* handler = static_cast<sqlite3*>(v.data()); @

    I think this casting is done wrongly since I have checked its member values and it has undefined data inside mutex object and other members

  • [quote author="ahmedalaa" date="1363863748"]
    But it still crashes in the call of sqlite3_create_function

    Check the described solution for a "similar issue atNokia Developer":http://bit.ly/YqFHeY

    bq. 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

  • Thanks for your reply,
    but it worked with me with a different approach.
    all the queries I want to do with the custom function I just did it using the sqlite3 APIs instead of QSqlDatabase

    and about the redifinition of the Q_SQL_EXPORT to export sqlite APIs it doesn't work as I said before
    I was linking the sqlite3 lib also with me (My mistake :( ) However it link successfully when I build the qt sqlite driver as static library and link it with me in the application.

    I will try the other solution and inform you if it works with me or not.
    Thank you for your help again :)

  • It also doesn't work, I think the crash comes from calling uninitialized function pointer "sqlite3GlobalConfig.mutex.xMutexEnter" however it is supposed to be initialized cause I have build the sqlite driver with SQLITE_THREADSAFE macro

Log in to reply

Looks like your connection to Qt Forum was lost, please wait while we try to reconnect.