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

QSqlQuery::bindValue not escapes null character in QString parameter

    XMLWordPrintable

Details

    • Bug
    • Resolution: Done
    • P2: Important
    • None
    • 5.1.0
    • SQL Support
    • None

    Description

      Example code:

      QSqlQuery query;
      ...
      QString str = "a";
      str.append(QChar(0));
      query.bindValue(":some", str);

      query.exec() returns error, in my PostgreSQL driver - "ERROR: unterminated quoted string at or near ...". Debugging showed, that prepared statement contains zero character at that place, and database treated this string like zero-terminated with no characters after that null character, so closing quotes and other parameters are lost.

      The problem is not only in PSQL driver, because QPSQLDriver::formatValue for this QString used code from more general QSqlDriver::formatValue.

      Solutions can be:
      1) escape zero characters in string
      2) or at least warn user with qDebug() message that string contains zero characters and is not supported, so other users will not spend so much time like me. Or add some text to documentation about escaping in bindValue. In my case, that QString was read from file, and I didn't expect null characters.

      Attachments

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

        Activity

          People

            mabrand Mark Brand
            neurocod Konstantine Kozachuck
            Votes:
            0 Vote for this issue
            Watchers:
            2 Start watching this issue

            Dates

              Created:
              Updated:
              Resolved:

              Gerrit Reviews

                There are no open Gerrit changes