Uploaded image for project: 'Qt'
  1. Qt
  2. QTBUG-18435

Out parameters of stored procedures return empty string

    XMLWordPrintable

Details

    • Bug
    • Resolution: Done
    • P2: Important
    • 5.0.0 Beta 1, 5.0.0
    • 4.6.3, 4.7.2
    • SQL Support
    • None
    • MSSQL 2008, Windows 7, MSVC 2008
    • f869a12c1043271b2ce8987b07a863ba3c78d6c9

    Description

      The following commit has introduced a regression to the ODBC driver:
      http://qt.gitorious.org/qt/qt/commit/c55a99965d8c08d5f924d49db4fe4aa49df80961

      Since 4.6.3 the bound value returns an empty string.

      Example reproducing the problem
      #include <QCoreApplication>
      #include <QtSql>
      
      int main(int argc, char *argv[])
      {
          QCoreApplication a(argc, argv);
      
          QSqlDatabase db = QSqlDatabase::addDatabase("QODBC");
          QString connectionStr("Driver={SQL Server Native Client 10.0};Server=.\\SqlExpress;Database=testdb;Uid=username;Pwd=password;");
          db.setDatabaseName(connectionStr);
      
          if(db.open())
          {
              QString testStr;
              testStr.reserve( 100 );
      
              QSqlQuery query;
              query.prepare("{CALL getTestString(?)}");
              query.bindValue("testStr", testStr, QSql::Out);
              if( query.exec() )
              {
                  testStr = query.boundValue("testStr").toString();
                  if( testStr.isEmpty() )
                      qDebug() << "String is empty"; //always return empty string for Qt 4.7.0
                  else
                      qDebug() << testStr;//works fine with version 4.6.1
              }
              else
              {
                  qDebug() << query.lastError().text();
              }
          }
          else
          {
              qDebug() << "Can't connect";
          }
          return 0;
      }
      
      Creating the stored procedure
      SET ANSI_NULLS ON
      GO
      SET QUOTED_IDENTIFIER ON
      GO
      CREATE PROCEDURE getTestString 
      	@key nvarchar(50) OUTPUT
      AS
      BEGIN
      	SET NOCOUNT ON;
      	SET @key = 'TEST'
      END
      GO
      

      Attachments

        No reviews matched the request. Check your Options in the drop-down menu of this sections header.

        Activity

          People

            mabrand Mark Brand
            mpejcoch Martin Pejcoch (Inactive)
            Votes:
            1 Vote for this issue
            Watchers:
            2 Start watching this issue

            Dates

              Created:
              Updated:
              Resolved:

              Gerrit Reviews

                There are no open Gerrit changes