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

QODBCDriver failing to bind values correctly

XMLWordPrintable

    • Icon: Bug Bug
    • Resolution: Done
    • Icon: P2: Important P2: Important
    • 6.1.0 Alpha
    • 5.7.0
    • SQL Support
    • None
    • Window 7, VS2015
    • b211148e4b4167483e1a78a45ae8fef97e5a4f2d (qt/qtbase/dev)

      QODBCResult::exec fails to bind many data types properly. Any QVariant::type that is not explicitly handled by the switch (which appears to be limited to the old QVariant types) falls through the default case. The default case then ignores the actual data and uses the empty QVariant in tmpStorage. This results in an empty string being sent.

      // fall through
      default:{
        QByteArray& ba = tmpStorage[i];
        if(*ind != SQL_NULL_DATA)
          *ind = ba.size();
        r = SQLBindParameter(d->hStmt,
                             i + 1,
                             qParamType[bindValueType(i) & QSql::InOut],
                             SQL_C_BINARY,
                             SQL_VARBINARY,
                             ba.length() + 1,
                             0,
                             const_cast<char*>(ba.constData()),
                             ba.length() + 1,
                             ind);
        break;
      }
      

      Quick fix is to simply add

      // fall through
      default:{
        QByteArray& ba = tmpStorage[i];
        ba = val.toByteArray();
        ...
      

      Full fix would be to explicitly handle the types which have sensible conversions i.e. QMetaType::Float -> SQL_C_FLOAT -> SQL_FLOAT etc.

      Bug was probably introduced when tmpStorage was changed to be preallocated.

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

            mabrand Mark Brand
            jeremythompson Jeremy Thompson
            Votes:
            0 Vote for this issue
            Watchers:
            1 Start watching this issue

              Created:
              Updated:
              Resolved:

                There are no open Gerrit changes