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

Allow bindValue with QSqlTableModel::setFilter

    XMLWordPrintable

Details

    • Suggestion
    • Resolution: Unresolved
    • P2: Important
    • None
    • None
    • SQL Support
    • None
    • I am using Python with PyQt5.QtSql, but I believe this issue is just as relevant with C++ Qt5. The issue is OS-independent.

    • All

    Description

      Would it be possible to support bindValue() with the setFilter() method of QSqlTableModel?

      At present the QSqlTableModel::setFilter() method is useless for many applications because there is no way to guard against SQL injections in the filter string. Of course, one could try to do the required SQL value escaping by hand, but the correct way to do this might depend on the database server that is used, and in any case Qt already has the capability to escape SQL values. Or one could use QSqlQueryModel, but this model is read-only. My attempts to call "model.query().bindValue(key,value)" for QSqlTableModels have not been successful.

      Now that I am at it, it would also be very useful to have a method like QSqlTableModel::setLimit(int maxResults) that limits the number of records that can be downloaded by select(). This would make QSqlTableModel much easier to use with large tables.

      I have seen other people ask about these features on discussion forums, for example this one from 2010:
      https://www.qtcentre.org/threads/36890-Using-bindValue-with-QSqlTableModel-setFilter()

      Thanks in advance!

      Anders Buch

       

      Attachments

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

        Activity

          People

            mabrand Mark Brand
            asbuch Anders Buch
            Votes:
            0 Vote for this issue
            Watchers:
            1 Start watching this issue

            Dates

              Created:
              Updated:

              Gerrit Reviews

                There are no open Gerrit changes