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

PostgreSQL insert fails if the value is NaN in float type

    XMLWordPrintable

    Details

    • Commits:
       916af48cff66e0acbeb6da39997498ce3b9626ce (qtbase/5.5, 18.2.2015, 5.5.0)

      Description

      Inserting NaN value to a PostgrSQL database requires apostrophes around it. QPSQL doesn't add those and the insertion fails with

      QSqlError("42703", "QPSQL: Unable to create query", "ERROR: column "nan" does not exist
      LINE 1: EXECUTE qpsqlpstmt_1 (nan)

      This problem has been fixed for double type in https://bugreports.qt.io/browse/QTBUG-3088. Equal check in QPSQLDriver::formatValue() for float type would do the trick, which leads to another minor "problem" that QSqlField.type is QVariant::Type, which doesn't have the float type.

      Tested with following code snippet:

      QSqlDatabase db = QSqlDatabase::addDatabase("QPSQL");
      db.setDatabaseName("postgres");
      QSqlQuery query;
      query.exec("create table foo (id int primary key, "
                         "bar float)");
      query.prepare("insert into foo values(1, :fValue)");
      query.bindValue(":fValue", static_cast<float>(qQNaN()));
      qDebug() << query.lastError() << query.exec();
      

        Attachments

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

          Activity

            People

            Assignee:
            kleint Friedemann Kleint
            Reporter:
            qtcomsupport Qt Support
            Votes:
            0 Vote for this issue
            Watchers:
            2 Start watching this issue

              Dates

              Created:
              Updated:
              Resolved:

                Gerrit Reviews

                There are no open Gerrit changes