Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. Error when inserting a record in MySQL
Forum Updated to NodeBB v4.3 + New Features

Error when inserting a record in MySQL

Scheduled Pinned Locked Moved Unsolved General and Desktop
2 Posts 2 Posters 509 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • F Offline
    F Offline
    Federico Milano
    wrote on last edited by
    #1

    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,

    Federico

    1 Reply Last reply
    0
    • SGaistS Offline
      SGaistS Offline
      SGaist
      Lifetime Qt Champion
      wrote on last edited by
      #2

      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.

      Interested in AI ? www.idiap.ch
      Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

      1 Reply Last reply
      0

      • Login

      • Login or register to search.
      • First post
        Last post
      0
      • Categories
      • Recent
      • Tags
      • Popular
      • Users
      • Groups
      • Search
      • Get Qt Extensions
      • Unsolved