Details
-
Bug
-
Resolution: Done
-
P2: Important
-
None
-
5.1.0
-
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.