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

QODBC: Reading Time fails when using ODBC Driver 17 for Sql Server

    XMLWordPrintable

Details

    • Bug
    • Resolution: Fixed
    • P2: Important
    • 6.4.3, 6.5.0, 6.6.0
    • 5.15.7, 6.0
    • SQL Support
    • None
    • MSSQL / ODBC Driver 17 for Sql Server
    • Windows
    • 7ebac2081 (dev), ff2cdec54 (6.5), 1988f3c68 (6.4)

    Description

      Reading of a Time-Value from a MSSQL-Server does not work if a newer ODBC-Driver (e.g. ODBC Driver 17 for Sql Server) is used.
      As a result one gets an invalid QTime():

      QSqlDatabase db = QSqlDatabase::addDatabase("QODBC");
      db.setDatabaseName("Driver={ODBC Driver 17 for SQL Server};Server=xxx;Uid=sa;Pwd=xxx");
      if (db.open())
      {
         QSqlQuery q = db.exec("SELECT CAST('12:30:00' AS TIME)");
         q.first();
         auto val = q.value(0).toTime();
         qDebug() << val;
         db.close();
      }
      

      The same code works if *

      {SQL Server}

      * is used.

      I found out that the old Driver (SQL Server) returns a Time-Value as String (SQL_VARCHAR), while the newer drivers (ODBC Driver xx for Sql Server) return binary data and the type identifier SQL_SS_TIME2; which is NOT handled in the Qt-ODBC-Wrapper:

      qsql_odbc.cpp:
      
      static QMetaType qDecodeODBCType(SQLSMALLINT sqltype, bool isSigned = true)
      {
      ...
      ...
          case SQL_DATE:
          case SQL_TYPE_DATE:
              type = QMetaType::QDate;
              break;
          case SQL_TIME:
          case SQL_TYPE_TIME:
              type = QMetaType::QTime;
              break;
          case SQL_TIMESTAMP:
          case SQL_TYPE_TIMESTAMP:
              type = QMetaType::QDateTime;
      ...
      ...
          default:
              type = QMetaType::QByteArray;
              break;
          }
          return QMetaType(type);
      }

      Because of that, the Time-Data will be treated as QByteArray and cannot be converted into QTime.

       

      Attachments

        Issue Links

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

          Activity

            People

              chehrlic Christian Ehrlicher
              chrislo1976 Christian Lorenz
              Votes:
              0 Vote for this issue
              Watchers:
              3 Start watching this issue

              Dates

                Created:
                Updated:
                Resolved:

                Gerrit Reviews

                  There are 2 open Gerrit changes