Error when inserting a record in MySQL
Hello. I'm trying to insert a QSqlRecord in a MySQL database table. The field "isPtzOnvif" is defined as:
isPtzOnvif BOOL NOT NULL DEFAULT FALSE
but I get the following error:
Failed to submit. Column 'isPtzOnvif' cannot be null QMYSQL3: Unable to execute statement
I'm migrating this code to Qt4.8 and MySql 5.5.52, coming from Qt 4.5.4. This used to work ok in the older version.
The code gets a record from the table mode, update some fields (not isPtzOnvif) and then inserts the new record, failing in that moment. If I print the contents of the record just before trying to insert it I get:
QSqlRecord( 27 ) " 0:" QSqlField("id", uint, length: 10, precision: 0, required: yes, generated: yes, typeID: 3) "-1" " 1:" QSqlField("host", QString, length: 150, precision: 0, required: no, generated: yes, typeID: 253) "" " 2:" QSqlField("port", uint, length: 10, precision: 0, required: no, generated: yes, typeID: 3) "0" ... " 7:" QSqlField("isPtzOnvif", int, length: 1, precision: 0, required: yes, generated: yes, typeID: 1) "0" ...
The only "strange" thing there is that the default bool value for that field is "0" instead of "false", but this is "normal" in MySQL. On the other hand, if I explicitly set isPtzOnvif to "false" then everything works fine. The original code used to work in Qt 4.5, do you know if there has been any change about this?
I would really appreciate any hint!
Thanks in advance,
Hi and welcome to devnet,
The best way to check that is to take a look at the history of the sql driver in Qt's sources.
Since you are migrating to Qt 4.8 you should consider moving to Qt 5. Qt 4 has seen its last release with 4.8.7 and won't have any other update unless theres a critical security issue found.