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

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

    XMLWordPrintable

    Details

    • Type: Bug
    • Status: Closed
    • Priority: P4: Low
    • Resolution: Done
    • Affects Version/s: 6.0.2, 6.0.3
    • Fix Version/s: 5.15.5, 6.1.1, 6.2.0 Alpha
    • Component/s: SQL Support
    • Labels:
      None
    • Environment:
      Win 10, Ubuntu 20.04
      Python 3.8.5, Python 3.9.2
    • Platform/s:
      Linux/X11, Windows
    • Commits:
      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

              Assignee:
              kleint Friedemann Kleint
              Reporter:
              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