Results 1 to 6 of 6

Thread: QSqlQuery crash in destructor

  1. #1
    Join Date
    Dec 2008
    Posts
    29
    Thanked 1 Time in 1 Post
    Qt products
    Qt4
    Platforms
    Unix/X11

    Default QSqlQuery crash in destructor

    Hello friends,
    I was testing QtSql with ODBC driver, ODBC manager unixODBC and Easysoft ODBC->MSSQL driver and got some really strange behavior with this example:

    {
    QSqlQuery query;
    query.prepare("{call proc03test(?);}");
    // proc03test is mssql stored procedure having 1 output integer parameter
    query.bindValue(0, 1, QSql::Out);
    bool result = query.exec();
    qDebug() << "ID = " << query.boundValue(0).toInt();
    }

    Qt 4.6.0 & 4.6.1: execution was OK, ID was printed out, but at the end of the block program crashed in QSqlQuery destructor somewhere in libqsqlodbc.so when the array of QVariant* was deleted.

    Qt 4.5.3: program crashed in query.exec() -> QODBCResult::exec() -> ->QVector<QVariant>::realloc(int,int) -> QVariant::QVariant(QVariant const &)

    Do you have any explanation for this thing?

  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: QSqlQuery crash in destructor

    We'd have to see the bigger picture. Is your application multithreaded?
    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
    Dec 2008
    Posts
    29
    Thanked 1 Time in 1 Post
    Qt products
    Qt4
    Platforms
    Unix/X11

    Default

    The code can be simplified with the same results to
    Qt Code:
    1. int main( int argc, char *argv[] )
    2. {
    3. QApplication app( argc, argv, FALSE );
    4.  
    5. QSqlDatabase db = QSqlDatabase::addDatabase( DB_DRIVER );
    6. db.setDatabaseName( DB_DBNAME );
    7. db.setUserName( DB_USER );
    8. db.setPassword( DB_PASSWD );
    9. db.setHostName( DB_HOST );
    10.  
    11. if (db.open())
    12. {
    13. QSqlQuery query;
    14. query.prepare("{call dbo.proc03test(?);}");
    15. query.bindValue(0, 1, QSql::Out);
    16. qDebug() << query.exec(); // Qt 4.5.3-r2, Qt 4.5.3
    17. qDebug() << "Output ID = " << query.boundValue(0).toInt();
    18. } // Qt 4.6 crash
    19. }
    To copy to clipboard, switch view to plain text mode 

    I've tried different Qt versions, different linux systems (gentoo - stable/unstable system libraries) with the same results.
    There is no problem if only input parameters are used, or if the results are retrieved via query without any preparation.

    The code can be rewritten in following way, but it comes me as closing eyes, I would like to know why it is falling down
    and be sure, that all components are all right and the error will not appear later in different cases..

    Qt Code:
    1. QSqlQuery query;
    2. query.prepare(
    3. "DECLARE @return_value int, @id int; \n"
    4. "EXEC @return_value = [dbo].[proc03test] @id = @id OUTPUT; \n"
    5. "SELECT @id, @return_value;"
    6. );
    7. qDebug() << query.exec();
    8. QSqlRecord rec = query.record();
    9.  
    10. qDebug() << "Columns: " << rec.count();
    11. while (query.next())
    12. qDebug() << query.value(0).toInt()
    13. << query.value(1).toInt();
    To copy to clipboard, switch view to plain text mode 

    Note: tests were made on Gentoo Linux x86_64
    Last edited by wysota; 22nd January 2010 at 13:40.

  4. #4
    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: QSqlQuery crash in destructor

    What about calling query.next() first before accessing the value? By the way, your "1" is ignored if you set the type of binding to "Out".
    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.


  5. #5
    Join Date
    Dec 2008
    Posts
    29
    Thanked 1 Time in 1 Post
    Qt products
    Qt4
    Platforms
    Unix/X11

    Default Re: QSqlQuery crash in destructor

    Shame on me!! MSSQL via ODBC needs setForwardOnly(true) also for stored procedures..
    Qt Code:
    1. ...
    2. QSqlQuery query;
    3. query.setForwardOnly(true);
    4. query.prepare("{? = call dbo.proc03test(?);}");
    5. ...
    To copy to clipboard, switch view to plain text mode 

  6. #6
    Join Date
    Sep 2009
    Posts
    36
    Thanks
    4
    Thanked 5 Times in 5 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11

    Default Re: QSqlQuery crash in destructor

    +1 to waysotas post, see doc

Similar Threads

  1. QTemporaryFile and his destructor
    By SABROG in forum Qt Programming
    Replies: 3
    Last Post: 19th May 2009, 19:55
  2. QTableWidget Crash in Destructor
    By mclark in forum Qt Programming
    Replies: 19
    Last Post: 25th July 2008, 14:44
  3. Destructor in QT
    By hgedek in forum Newbie
    Replies: 1
    Last Post: 18th September 2007, 10:54
  4. Crash on QString Destructor
    By ToddAtWSU in forum Qt Programming
    Replies: 1
    Last Post: 14th June 2007, 14:28
  5. QList crash in destructor
    By mclark in forum Newbie
    Replies: 7
    Last Post: 6th December 2006, 15:27

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.