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

QSqlRelationDelegate does not work with field between quotation marks

    XMLWordPrintable

Details

    • Bug
    • Resolution: Done
    • P2: Important
    • 5.9.0
    • 5.6.2
    • SQL Support
    • None
    • PySide 1.1.2 for Python 2.6 on Windows XP
    • 87f9a44ef04ac12d0180bb556cab7f3528ba036a

    Description

      I use a PostgreSql database, whose table and field names contain uppercase and lowercase letters.
      To refer to these fields it is necessary to place them between quotation marks (example : QSqlRelation("\"TableName\"", "\"FieldName1\"", "\"FieldName2\""))
      The standard QSqlRelationDelegate does not work correctly in that case (the fields are not updated in the database).
      To make it work I had to subclass QSqlRelationDelegate and add .replace("\"", "") in the setModelData() function :

      def setModelData(self, editor, model, index):		
          if editor.metaObject().className() == "QComboBox":			
               if model.relationModel(index.column()) is not None:
                      currentItem = editor.currentIndex()
      		childModel = model.relationModel(index.column())
      
      		childColIndex = childModel.fieldIndex(model.relation(index.column()).displayColumn().replace("\"", ""))
      		childEditIndex = childModel.fieldIndex(model.relation(index.column()).indexColumn().replace("\"", ""))
      
      		model.setData(index, childModel.data(childModel.index(currentItem, childColIndex), Qt.DisplayRole), Qt.DisplayRole)
      		model.setData(index, childModel.data(childModel.index(currentItem, childEditIndex), Qt.EditRole), Qt.EditRole)
      								
      		return
      		
          QItemDelegate.setModelData(self, editor, model, index)
      

      Attachments

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

        Activity

          People

            jefernan Jesus Fernandez
            octaroct LE BIHAN
            Votes:
            0 Vote for this issue
            Watchers:
            2 Start watching this issue

            Dates

              Created:
              Updated:
              Resolved:

              Gerrit Reviews

                There are no open Gerrit changes