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?
Re: QSqlQuery crash in destructor
We'd have to see the bigger picture. Is your application multithreaded?
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".
Re: QSqlQuery crash in destructor
Shame on me!! MSSQL via ODBC needs setForwardOnly(true) also for stored procedures..
Code:
...
query.setForwardOnly(true);
query.prepare("{? = call dbo.proc03test(?);}");
...
Re: QSqlQuery crash in destructor
+1 to waysotas post, see doc