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

Wrong order of values with positional binding in a QSqlQuery

    XMLWordPrintable

Details

    • Bug
    • Resolution: Done
    • P3: Somewhat important
    • 5.3.0 Beta1
    • 4.6.3, 5.3.0 Alpha
    • SQL Support
    • None

    Description

      The position of the bound values is decided by their key in the used QMap. The key is generated by qFieldSerial(int i) in qsqlresult.cpp. This will only work for cases where the number of bindings is less than 16, since after that the new :fab value will be sorted by the QMap right after the first :f value.

      Code reproducing the problem
      #include <QtGui>
      #include <QtSql>
      
      int main(int argc, char *argv[])
      {
          QApplication app(argc, argv);
      
          QSqlDatabase db = QSqlDatabase::addDatabase("QSQLITE");
          db.setDatabaseName(":memory:");
      
          QSqlQuery query;
          query.prepare("INSERT INTO person (col1, col2, col3, col4, col5, col6, col7, col8, col9, col10, col11, col12, col13, col14, col15, col16, col17, col18) "
                        "VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?. ?, ?)");
          for(int i = 0; i < 18; ++i)                  
              query.bindValue(i, i);
          
          QMapIterator<QString, QVariant> i(query.boundValues());
          while (i.hasNext()) {
              i.next();
              qDebug() << i.key().toAscii().data() << ": "
                      << i.value().toString().toAscii().data();
          }
      
          return 0;
      }
      

      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:
            3 Vote for this issue
            Watchers:
            6 Start watching this issue

            Dates

              Created:
              Updated:
              Resolved:

              Gerrit Reviews

                There are no open Gerrit changes