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

QSqlTableModel ORDER BY doesn't quote table name [with spaces]

    XMLWordPrintable

Details

    • Bug
    • Resolution: Done
    • P4: Low
    • 5.15.3, 5.15.5, 6.1.1, 6.2.0 Alpha
    • 6.0.2, 6.0.3
    • SQL Support
    • None
    • Win 10, Ubuntu 20.04
      Python 3.8.5, Python 3.9.2
    • Linux/X11, Windows
    • 21b3b54193b9d90ee377fdfa306e21d2fdfe2837 (qt/qtbase/dev) a76017b56513ee125cd60cb981c974faffc3df7f (qt/qtbase/6.1) 79edc48c0dcd03a33abeb36c4b5b512a61339113 (qt/tqtc-qtbase/5.15)

    Description

      On SQLite DB

       

      ...
      model = QSqlTableModel()
      model.setTable('temp')
      ...
      table_view= QTableView(self.centralwidget)
      table_view.setModel(model)
      ...

      Both

      model.setSort(1, Qt.DescendingOrder)
      model.select()
      print(model.selectStatement())
      ...
      table_view.sortByColumn(1, Qt.AscendingOrder)
      print(model.selectStatement())
      

      return

      SELECT "id", "full_name" FROM "temp" ORDER BY temp."full_name" ASC
      

      Table name not quoted {ORDER BY temp."full_name" ASC} and that why

      model.select()
      

      return False

       

      UPD:

      on Ubuntu 20.04 table name not quoted too.

      But with nonspace tablename select() return True (and fields).

      With spaced names (like "full name") still not work.

      print(model.selectStatement())
      
      >>>SELECT "id", "full_name" FROM "spaced table name" ORDER BY spaced table name."full_name" ASC
      

      Attachments

        Issue Links

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

          Activity

            People

              kleint Friedemann Kleint
              zdr3 Alex Zdr
              Votes:
              0 Vote for this issue
              Watchers:
              2 Start watching this issue

              Dates

                Created:
                Updated:
                Resolved:

                Gerrit Reviews

                  There are no open Gerrit changes