The code can be simplified with the same results to
int main( int argc, char *argv[] )
{
db.setDatabaseName( DB_DBNAME );
db.setUserName( DB_USER );
db.setPassword( DB_PASSWD );
db.setHostName( DB_HOST );
if (db.open())
{
query.prepare("{call dbo.proc03test(?);}");
query.bindValue(0, 1, QSql::Out);
qDebug() << query.exec(); // Qt 4.5.3-r2, Qt 4.5.3
qDebug() << "Output ID = " << query.boundValue(0).toInt();
} // Qt 4.6 crash
}
int main( int argc, char *argv[] )
{
QApplication app( argc, argv, FALSE );
QSqlDatabase db = QSqlDatabase::addDatabase( DB_DRIVER );
db.setDatabaseName( DB_DBNAME );
db.setUserName( DB_USER );
db.setPassword( DB_PASSWD );
db.setHostName( DB_HOST );
if (db.open())
{
QSqlQuery query;
query.prepare("{call dbo.proc03test(?);}");
query.bindValue(0, 1, QSql::Out);
qDebug() << query.exec(); // Qt 4.5.3-r2, Qt 4.5.3
qDebug() << "Output ID = " << query.boundValue(0).toInt();
} // Qt 4.6 crash
}
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..
query.prepare(
"DECLARE @return_value int, @id int; \n"
"EXEC @return_value = [dbo].[proc03test] @id = @id OUTPUT; \n"
"SELECT @id, @return_value;"
);
qDebug() << query.exec();
qDebug() << "Columns: " << rec.count();
while (query.next())
qDebug() << query.value(0).toInt()
<< query.value(1).toInt();
QSqlQuery query;
query.prepare(
"DECLARE @return_value int, @id int; \n"
"EXEC @return_value = [dbo].[proc03test] @id = @id OUTPUT; \n"
"SELECT @id, @return_value;"
);
qDebug() << query.exec();
QSqlRecord rec = query.record();
qDebug() << "Columns: " << rec.count();
while (query.next())
qDebug() << query.value(0).toInt()
<< query.value(1).toInt();
To copy to clipboard, switch view to plain text mode
Note: tests were made on Gentoo Linux x86_64
Bookmarks