PDA

View Full Version : QODBC, QSqlQuery, out parameters of stored procedures



rusvid
10th September 2009, 05:00
I use the driver QODBC to connect to the database MS SQL Server. I execute a stored procedure. The stored procedure returns values through parameters. stored procedure always returns the empty string for parameters of type QString.
For example:


alter procedure [dbo].[fp_test]
( @Name varchar(50),
@Value varchar(50) out,
@Number int out
)
as
set nocount on
Select @Value='test', @Number=123




QSqlQuery query;
//query.setForwardOnly(true);
query.prepare("{CALL fp_test(?,?,?)}");
query.addBindValue(strName);
query.addBindValue(strValue,QSql::Out);
query.addBindValue(n,QSql::Out);
if (!query.exec())
{ QMessageBox::information(0, QObject::tr("Error"), "Error");
return 1;
}

strValue = query.boundValue(1).toString(); // "" :confused: - must be "test"
n = query.boundValue(2).toInt();; // 123 - ok

ajg85
7th April 2010, 19:30
It's not just stored procedures I am having the same problem with string based select queries using QSqlQuery ... it appears numeric fields types are fine but I have not been able to get anything but empty strings back from char(10), varchar(50), nvarchar(50), text, or ntext field types!

I believe it might be a collation issue with QODBC but I haven't found a solution yet. Selecting numeric values seems to work, inserting and updating strings seems to work, just can't select strings. I am using freeTDS version 8.0 ODBC on Ubuntu to connect to SQL Express 2005 on Windows 7. I think it's platform and SQL agnostic though as many different people have reported this problem on other OS and other versions of SQL when using QODBC.