Details
-
Bug
-
Resolution: Done
-
P2: Important
-
4.7.0
-
None
-
Probably all.
-
0f15ab4e750690bdb2b649332d5c3276bf24c440
Description
When generating UPDATE and INSERT statements, QSqlDriver::sqlStatement omits fields where the QVariant value is invalid, i.e., has type QVariant::Invalid.
This seems wrong for the following reasons:
- The documented behavior is that the "generated" property of QSqlField determines whether to include the field in the generated statement.
- It is not necessary or even reasonable to assume that values in the record passed to sqlStatement() will contain valid values.
- A plausible source for a record is QSqlDatabase::record ( const QString & tablename ). Such records contains invalid values.
- This behavior is especially troublesome when using parametrized queries. The programmer is likely to construct value lists that match the fields in the record, but such value lists might not match the generated statement, causing errors at runtime.
For parameterized queries, the value has no consequence anyway since a placeholder is used. For non-parameterized queries, invalid values should probably be rendered as NULL.
The attached code illustrates this behavior.
Proposed fix here:
http://qt.gitorious.org/qt/qt/merge_requests/789