Valentin H
Valentin H

Reputation: 7448

How to know that QSqlQuery::bindValue call was correct

Is there any possibility to know QSqlQuery::bindValue call is ok?

The functions returns void and I wonder why? At least the absence of the required place-holder should be reported (ihmo) as an error.

Maybe there is another possibility to check, that binding is correct?

Upvotes: 2

Views: 413

Answers (1)

AngryDuck
AngryDuck

Reputation: 4607

use bindValue() and pass the placeholder name or the position and it will return the value that has been bound, so you will be able to check if values have bound correctly. Alternatively use boundValues() which will return a map of all the keys and values:

Sample from Qt Docs for boundValues()

QMapIterator<QString, QVariant> i(query.boundValues());
while (i.hasNext()) {
    i.next();
    cout << i.key().toUtf8().data() << ": "
         << i.value().toString().toUtf8().data() << endl;
}    

Upvotes: 2

Related Questions