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

QSqlRelationalTableModel can't submitAll() changes if primaryKey is consist of two fields

    XMLWordPrintable

Details

    • Bug
    • Resolution: Incomplete
    • Not Evaluated
    • None
    • 5.12.6
    • SQL Support
    • None
    • windows 10, pyside2, python 3.7.5 32 bit
    • Windows

    Description

      I use QSqlRelationalTableModel to works with table which have two primary fields:

      pddate and contracts_id - they both correctly(look like) detected as primary - self.primaryKey() shows:

      <PySide2.QtSql.QSqlIndex(2)
       0: QSqlField("pddate", QDate, tableName: "(not specified)", length: 10, precision: 0, required: yes, generated: yes, typeID: 9, autoValue: false, readOnly: false) "" 
       1: QSqlField("contracts_id", int, tableName: "(not specified)", length: 10, precision: 0, required: yes, generated: yes, typeID: 4, autoValue: false, readOnly: false) "0" at 0x06143850>
      

       

      but if i change some row in table and use submitAll() - it fail to update sql table. 

      (self.lastError().text() - is empty after submitAll() )

      (self.setEditStrategy(QSqlTableModel.OnManualSubmit) - is used)

       

      I check self.primaryValues(dirty_row) before submitAll() and it shows:

      <PySide2.QtSql.QSqlRecord(2)
       0: QSqlField("pddate", QDate, tableName: "(not specified)", length: 10, precision: 0, required: yes, generated: yes, typeID: 9, autoValue: false, readOnly: false) "2019-06-01" 
       1: QSqlField("contracts_id", int, tableName: "(not specified)", length: 10, precision: 0, required: yes, generated: yes, typeID: 4, autoValue: false, readOnly: false) *"" at 0x0613AAA8*>
      

      but self.record(dirty_row) before submitAll() shows:

      <PySide2.QtSql.QSqlRecord(20)
       0: QSqlField("pddate", QDate, tableName: "add_info\u0000???\u0007\u0000\u0007", length: 10, required: yes, generated: no, typeID: 9, autoValue: false, readOnly: false) "2001-06-01" 
       1: QSqlField("contracts", QString, tableName: "contracts\u0000??\u0007\u0000\u0007\u0000??", length: 45, required: no, generated: no, autoValue: false, readOnly: false) *"2"*
      
      <....>
      

       
      and i think there is the problem:

      field contracts_id HAVE correct int value, but self.primaryValues(dirty_row) return EMPTY string!

      self.selectStatement() of my table 
      
      SELECT add_info.`pddate`,relTblAl_1.contracts,add_info.`predv_money`,add_info.`curFIO`,add_info.`psp`,add_info.`address`,add_info.`sdd`,add_info.`sdd_date`,add_info.`perc`,add_info.`not_standart_contract`,add_info.`not_standart_act`,add_info.`prim`,add_info.`create`,add_info.`ts`,relTblAl_14.cr_by,relTblAl_15.upd_by,add_info.`repr_FIO`,add_info.`repr_addr`,add_info.`repr_psp`,add_info.`work_livemin` FROM add_info LEFT JOIN contracts relTblAl_1 ON add_info.`contracts_id`=relTblAl_1.id LEFT JOIN cr_by relTblAl_14 ON add_info.`cr_by`=relTblAl_14.id LEFT JOIN upd_by relTblAl_15 ON add_info.`upd_by`=relTblAl_15.id WHERE (add_info.contracts_id = 2 or add_info.contracts_id = 0 or False)
      
       

      UDPATE:

      if I don't set relation for primary column contrats_idsubmitAll() works!

      self.primaryValues(dirty_row) before submitAll():

      <PySide2.QtSql.QSqlRecord(2)
       0: QSqlField("pddate", QDate, tableName: "(not specified)", length: 10, precision: 0, required: yes, generated: yes, typeID: 9, autoValue: false, readOnly: false) "2019-06-01" 
       1: QSqlField("contracts_id", int, tableName: "(not specified)", length: 10, precision: 0, required: yes, generated: yes, typeID: 4, autoValue: false, readOnly: false) "2" at 0x08839440>
      

       

      Attachments

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

        Activity

          People

            sorvig Morten Sørvig
            alexqwesa alex savin
            Votes:
            0 Vote for this issue
            Watchers:
            3 Start watching this issue

            Dates

              Created:
              Updated:
              Resolved:

              Gerrit Reviews

                There are no open Gerrit changes