Binds that comes from QML leads to trailing null missing from STR bind value in Oracle

75 Views Asked by At

I Have a code in QML that sends some strings to a Qt code that at last are used as bind values from a query in Oracle

The QML calls a method from a class in Qt through Q_INVOKABLE macro. The method has some parameters that are used as bind's

The error "ORA-01480 trailing null missing from STR bind value" happens just when it is compiled for 32 bits .

The code is compiled using Visual Studio 2019 and Qt version 5.15.1 The code is something like that

    Q_INVOKABLE void setFields(QVariantList fields) {m_fields = fields;}
    Q_INVOKABLE void setValues(QVariantList values) {m_values = values;}
        Q_INVOKABLE bool save()
        {
        for(int i = 0; i < m_fields.count(); i++) {

          QSqlQuery q;
          q.prepare("UPDATE TABLE SET VALUE = :VALUE WHERE KEY = :KEY");
          q.bindValue(":KEY", m_fields.at(i));
          q.bindValue(":VALUE", m_values.at(i));
          q.exec();
        }
         }

The error does not happens always. Some times it happens some times not and some times the exec() return without error but the result is wrong as if the value passed to the bind was not as expected.

Some times, but not always, the value passed from qml to qt comes from a string property. If its value is a literal string like "property string myValue: "abc" " than the error happens but if it is wrapped by the builtin function qsTr("abc") of the qml than there is no error.

I haved debug the code trying to see inside the QString that result from m_values.at(i).toString() but I did not find anything useful.

If I do a kind of copy to other QString using a code like

QString tmp;
for(int j = 0; j < m_values.at(i).toString().size();j++)
   tmp += m_values.at(i).toString().at(j);
....
 q.bind(":VALUE", tmp);

The error is removed. but the simple copy QString tmp = m_values.at(i).toString(); does not work.

0

There are 0 best solutions below