Results 1 to 2 of 2

Thread: QODBC, QSqlQuery, out parameters of stored procedures

  1. #1
    Join Date
    Sep 2009
    Posts
    2
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default QODBC, QSqlQuery, out parameters of stored procedures

    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:
    Qt Code:
    1. alter procedure [dbo].[fp_test]
    2. ( @Name varchar(50),
    3. @Value varchar(50) out,
    4. @Number int out
    5. )
    6. as
    7. set nocount on
    8. Select @Value='test', @Number=123
    To copy to clipboard, switch view to plain text mode 

    Qt Code:
    1. QSqlQuery query;
    2. //query.setForwardOnly(true);
    3. query.prepare("{CALL fp_test(?,?,?)}");
    4. query.addBindValue(strName);
    5. query.addBindValue(strValue,QSql::Out);
    6. query.addBindValue(n,QSql::Out);
    7. if (!query.exec())
    8. { QMessageBox::information(0, QObject::tr("Error"), "Error");
    9. return 1;
    10. }
    11.  
    12. strValue = query.boundValue(1).toString(); // "" :confused: - must be "test"
    13. n = query.boundValue(2).toInt();; // 123 - ok
    To copy to clipboard, switch view to plain text mode 

  2. #2
    Join Date
    Apr 2010
    Location
    United States
    Posts
    16
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: QODBC, QSqlQuery, out parameters of stored procedures

    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.

Similar Threads

  1. Replies: 14
    Last Post: 16th January 2009, 08:11
  2. QSqlQuery and Oracle stored function
    By sawerset in forum Qt Programming
    Replies: 0
    Last Post: 22nd December 2008, 18:48
  3. QODBC and stored procedures
    By xgoan in forum Qt Programming
    Replies: 6
    Last Post: 18th November 2008, 17:43
  4. MySql Stored Procedures Woes
    By stevey in forum Qt Programming
    Replies: 9
    Last Post: 19th October 2006, 12:58
  5. Qt4: How to use Stored Procedures?
    By pinktroll in forum Qt Programming
    Replies: 6
    Last Post: 28th August 2006, 13:46

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
  •  
Qt is a trademark of The Qt Company.