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

QSqlTableModel query filter fails to return any records when it should

    XMLWordPrintable

Details

    • Bug
    • Resolution: Fixed
    • P3: Somewhat important
    • None
    • 5.12.0
    • None
    • Windows 10, Qt Creator, debug
    • Windows
    • User error

    Description

      In QSqlTableModel using SQLITE 3.27.1, I set the filter to:

      filter= "[dancegroupname] = 'American Smooth' AND [dancename] = 'Waltz'"

      where dancegroupname and dancename are TEXT fields in songfiletable.

      When I setFilter(...) and select(), I get no records. There are 2 records in the database table which meet the criteria; they are not returned. This is a bug.

       

      More information: If I code the filter with "like" instead of "=" using exactly the same query values, 2 records are returned:

      filter= "[dancegroupname] like 'American Smooth' AND [dancename] like 'Waltz'"

       

      I coded a test query (in the same project) using the same database and table. When I  execute the test query (logically equivalent), the 2 records are returned:

       

      executed query: "SELECT * FROM songfiletable WHERE [dancegroupname] = :a AND [dancename] = :bb;"
      Query.prepare(sqlPre);
      Query.addBindValue(P_dancegroupname.toUtf8());
      Query.addBindValue(P_dancename.toUtf8()); 
      rc = true and records are returned.
      

       

       

      More information:

      I opened a terminal window and ran sqlite3.exe with following query. It returned 2 records (as expected). I used "like" instead of "=" because the "=" query failed to return any records.

      sqlite> select songfile_id,dancegroupname,hex(dancename),length(dancename) from songfiletable where dancegroupname like 'American Smooth' and dancename like "Waltz";
      songfile_id|dancegroupname|hex(dancename)|length(dancename)
      382|American Smooth|57616C747A|5
      393|American Smooth|57616C747A|5

      Attachments

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

        Activity

          People

            docteam Qt Documentation Team
            doug9f Douglas Forester
            Votes:
            0 Vote for this issue
            Watchers:
            2 Start watching this issue

            Dates

              Created:
              Updated:
              Resolved:

              Gerrit Reviews

                There are no open Gerrit changes