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. [SOLVED] Inserting zero (0) to SQLite database
QtWS25 Last Chance

[SOLVED] Inserting zero (0) to SQLite database

Scheduled Pinned Locked Moved General and Desktop
3 Posts 1 Posters 1.1k Views
  • 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.
  • Z Offline
    Z Offline
    Zerby
    wrote on last edited by
    #1

    Hello,

    I have a problem with inserting a zero value to QSqlDatabase. So, basicly, if I:

    @this->record->setValue(index, QVariant(0));@

    And when I submit this to database later on, it inserts the value as NULL, empty column. I've tried:

    @
    QString tmp = "0";
    this->record->setValue(index, QVariant(tmp));
    @

    But it doesn't matter. I guess QVariant casts the value to NULL on it's constructor, is there any way to change this behavior?

    1 Reply Last reply
    0
    • Z Offline
      Z Offline
      Zerby
      wrote on last edited by
      #2

      Anyone? I've noticed, that if I update an existing row, it does insert 0. Pretty weird, they're called with pretty much same method on my SQL-table class..

      EDIT: I've now debugged the reason for this, and it's because of this:

      bool QSqlTableModel::setData documentation:
      Returns true if value is equal to the current value. However, the value will not be submitted to the database.

      So, when the current value is empty in the database (= when a new record is inserted), it checks NULL == 0, and doesn't insert the 0 in the database.. Is there any way to change this behavior, does anyone know? Can I somehow override this check in setData -function?

      1 Reply Last reply
      0
      • Z Offline
        Z Offline
        Zerby
        wrote on last edited by
        #3

        Ahh, this seems to have been fixed in Qt 5.1.1 :) Great! Problem solved.

        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