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. QDate vs MySql: null date
Forum Updated to NodeBB v4.3 + New Features

QDate vs MySql: null date

Scheduled Pinned Locked Moved Solved General and Desktop
3 Posts 3 Posters 628 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.
  • T Offline
    T Offline
    TheCipo76
    wrote on 26 Nov 2018, 15:54 last edited by
    #1

    Hi,
    i've to store some date in mysql database table

    importing external txt file i saw that some date can be null and others can be valid date
    how can i manage null date in order to store it to the database?

    QDate do not allow to set it to null (only valid or not valid date)
    mysql allow null date

    i had tried to load the date as text and all works
    but i can't order them and can't do any comparison between them

    any ideas?

    K 1 Reply Last reply 26 Nov 2018, 16:27
    0
    • T TheCipo76
      26 Nov 2018, 15:54

      Hi,
      i've to store some date in mysql database table

      importing external txt file i saw that some date can be null and others can be valid date
      how can i manage null date in order to store it to the database?

      QDate do not allow to set it to null (only valid or not valid date)
      mysql allow null date

      i had tried to load the date as text and all works
      but i can't order them and can't do any comparison between them

      any ideas?

      K Offline
      K Offline
      koahnig
      wrote on 26 Nov 2018, 16:27 last edited by
      #2

      @TheCipo76

      Isn't "null" a value not assigned at all?
      In my recent trials with MySql I saw "null" for not assigned values. Therefore IMHO "null" is equivalent to a null pointer to QDate in your case.

      Vote the answer(s) that helped you to solve your issue(s)

      1 Reply Last reply
      1
      • V Offline
        V Offline
        VRonin
        wrote on 26 Nov 2018, 16:31 last edited by
        #3

        how can i manage null date in order to store it to the database?

        from http://doc.qt.io/qt-5/qsqlquery.html#addBindValue

        To bind a NULL value, use a null QVariant; for example, use QVariant(QVariant::String) if you are binding a string.

        "La mort n'est rien, mais vivre vaincu et sans gloire, c'est mourir tous les jours"
        ~Napoleon Bonaparte

        On a crusade to banish setIndexWidget() from the holy land of Qt

        1 Reply Last reply
        5

        1/3

        26 Nov 2018, 15:54

        • Login

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