3132:16298 -- Handling of incorrect field names

OpenRPT
omfgppc
2008-12-29
2013-03-08
  • omfgppc
    omfgppc
    2008-12-29

    idiallo wrote: Hello,

    When a field name is wrong in an OpenRPT document, two things happen:
    [1] the field is blank when the document is printed,
    [2] the renderer emits a qWarning generated by the QSqlQuery::value() method of Qt, but the warning misleadingly states \"QSqlQuery::value: not positioned on a valid record\" instead of \"incorrect field name\".

    The issue [2] could be corrected by the following patch in  XSqlQuery::value() method:

    remplacing the following code
    [code:1:d3d247148f]
    QVariant XSqlQuery::value(const QString & name) const
    {
      if (name.isEmpty())
        return QVariant();

      QSqlRecord r = record();
      if (!r.isEmpty())
        return value(r.indexOf(name));

      return QVariant();
    }[/code:1:d3d247148f]
    with
    [code:1:d3d247148f]
    QVariant XSqlQuery::value(const QString & name) const
    {
      if (name.isEmpty())
        return QVariant();

      QSqlRecord r = record();
      if (!r.isEmpty()) {
        int i = r.indexOf(name);
        if(i<0) {
            qWarning(\"Column \" + name + \" not found in record\");
            return QVariant(\"\");
        }
        return value(r.indexOf(name));
      }
    }[/code:1:d3d247148f]
    That patch should have no side effects, as it only corrects the content of the qWarning that is already emitted.
    For issue [1], i''d also like to print some error info - returning \"ERR\" for instance in the XSqlQuery::value() method - to help to diagnose the reports, but as the XSqlQuery class is also used outside of OpenRPT, it could have unwanted side effects.
    Any opinions ? -- Read more at http://www.xtuple.org/phpBB2/viewtopic.php?t=3132