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

QSqlTableModel::selectRow() malfunction when key and foreign key use same name

    XMLWordPrintable

Details

    • Bug
    • Resolution: Done
    • P2: Important
    • 5.6.1
    • 5.3.2
    • SQL Support
    • None
    • 34472e946a11bf6e06ba9ed7b72f938ea6eede02

    Description

      I'm using a MySql DB with some QSqlRelationalTableModel models. All my tables use 'id' name as primary key, and there are some relational tables. All worked fine in Qt 4.8 until I migrated the program to Qt 5.3.2, whe I realized that insertRecord() function returns 'false' in many cases. After investigating this issue, I have concluded the problem is because of QSqlTableModel::selectRow() function.

      I think this is because the internal SQL query made in this function is wrong when the key and the foreign key use the same name, like in the following example:

      CREATE TABLE cw_building_typology {
          id smallint unsigned not null auto_increment,
          name varchar(125) null default 'Undefined',
          PRIMARY KEY(id)
      } ENGINE=InnoDB
      
      CREATE TABLE cw_building {
          id int unsigned not null auto_increment,
          b_type smallint unsigned not null default 1,
          address text null default null,
          remarks text null default null,
          PRIMARY KEY(id),
          KEY b_type (b_type),
          FOREIGN KEY (b_type) REFERENCES cw_building_typology (id) ON DELETE RESTRICT ON UPDATE CASCADE
      } ENGINE=InnoDB
      

      In Qt4 all works fine, but in Qt5 I must change the primary key name in the second table.

      Thanks in advance.

      Attachments

        Issue Links

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

          Activity

            People

              SG House Vyacheslav Grigoryev
              alazar Jorge Vigil
              Votes:
              1 Vote for this issue
              Watchers:
              3 Start watching this issue

              Dates

                Created:
                Updated:
                Resolved:

                Gerrit Reviews

                  There are no open Gerrit changes