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

AUTOINCREMENT column is not auto-incremented when being modified by QSqlTableModel

    XMLWordPrintable

Details

    Description

      Reproducer included. Build and run with 6.6.x or 6.7.x. Actually, I am not sure if it's bug. But the behavior is kind of counter intuitive. Either a change in behavior or more detailed explanation in doc will be appreciated.

      The issue is that the PRIMARY KEY marked by AUTOINCREMENT is not auto-incremented ("id" is always 0) until submitAll by which everything is final and irrevocable. Another observation is that the other column "name" behaves as expected, i.e. it has been the correct value "Julen" even before submitAll. So when you run the reproducer, you may see something like:

      Before submit OK QVariant(int, 0) QVariant(QString, "Julen")
      Last inserted ID: 1
      After submit OK QVariant(qlonglong, 1) QVariant(QString, "Julen")
      

      You can see that "id" has not been correctly incremented until submission. Although "name" has always been correct. Also, explicitly marking "id" as "autoValue" does not help here. "id" is marked by AUTOINCREMENT at the time of table creation so I guess "setAutoValue(true)" does not make any difference here.

      Attachments

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

        Activity

          People

            andysh Andy Shaw
            luqiaochen Luqiao Chen
            Votes:
            0 Vote for this issue
            Watchers:
            3 Start watching this issue

            Dates

              Created:
              Updated:

              Gerrit Reviews

                There are no open Gerrit changes