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. query.bind not formatting date correctly
Forum Updated to NodeBB v4.3 + New Features

query.bind not formatting date correctly

Scheduled Pinned Locked Moved Unsolved General and Desktop
7 Posts 3 Posters 715 Views 2 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.
  • ocgltdO Offline
    ocgltdO Offline
    ocgltd
    wrote on last edited by
    #1

    I am recompiling some old code to run under Qt 5.15.2. My MySQL insert now fails due to incorrect date formate (I am inserting into a datetime column). My bind command is:

    query.bind(":timestamp",myQDateTime);

    and the error is:
    Incorrect datetime value: '2023-08-15T15:07:41Z' for column...

    and as you can see the date time string bound to the timestamp field is not valid. This used to work under older Qt version. Is this a bug/regression? Or am I supposed to modify my INSERT statement to use STR_TO_DATE on the bound value?

    Strange that this used to work.

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

      Hi,

      Are you sure you were using that format ?
      What does your database expect ?

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

      ocgltdO 1 Reply Last reply
      0
      • SGaistS SGaist

        Hi,

        Are you sure you were using that format ?
        What does your database expect ?

        ocgltdO Offline
        ocgltdO Offline
        ocgltd
        wrote on last edited by ocgltd
        #3

        @SGaist I'm not sure what you mean by that format. My variable myQDateTime is a QDateTime type, and the error message above is as returned my the last error function. So somehow the QDateTime is being incorrectly formatted by the bindValue function. The dash dividers and Z and T in the string aren't acceptable to MySQL...but the bindValue function is putting them there.

        This used to work (under Qt 5.9)...can't figure out why it no longer works.

        Should the above work?

        Christian EhrlicherC 1 Reply Last reply
        0
        • ocgltdO ocgltd

          @SGaist I'm not sure what you mean by that format. My variable myQDateTime is a QDateTime type, and the error message above is as returned my the last error function. So somehow the QDateTime is being incorrectly formatted by the bindValue function. The dash dividers and Z and T in the string aren't acceptable to MySQL...but the bindValue function is putting them there.

          This used to work (under Qt 5.9)...can't figure out why it no longer works.

          Should the above work?

          Christian EhrlicherC Offline
          Christian EhrlicherC Offline
          Christian Ehrlicher
          Lifetime Qt Champion
          wrote on last edited by
          #4

          Please provide a minimal, compilable example of your problem. Since a bound value is not passed as a string (but as MYSQL_TIME struct) it's for sure not some kind of QDateTime formatting.

          Qt Online Installer direct download: https://download.qt.io/official_releases/online_installers/
          Visit the Qt Academy at https://academy.qt.io/catalog

          ocgltdO 1 Reply Last reply
          1
          • Christian EhrlicherC Christian Ehrlicher

            Please provide a minimal, compilable example of your problem. Since a bound value is not passed as a string (but as MYSQL_TIME struct) it's for sure not some kind of QDateTime formatting.

            ocgltdO Offline
            ocgltdO Offline
            ocgltd
            wrote on last edited by ocgltd
            #5

            @Christian-Ehrlicher If I format the QDateTime variable into a MySQL formatted string and then bind it, my code works fine. So for sure something is fishy here...I won't bother create a MRE at this point, as a workaround is good enough for now. (But I'll try to create one once my project is done)

            ...but maybe someone at Qt could check into this. I can open a ticket if that helps...

            Christian EhrlicherC 1 Reply Last reply
            0
            • ocgltdO ocgltd

              @Christian-Ehrlicher If I format the QDateTime variable into a MySQL formatted string and then bind it, my code works fine. So for sure something is fishy here...I won't bother create a MRE at this point, as a workaround is good enough for now. (But I'll try to create one once my project is done)

              ...but maybe someone at Qt could check into this. I can open a ticket if that helps...

              Christian EhrlicherC Offline
              Christian EhrlicherC Offline
              Christian Ehrlicher
              Lifetime Qt Champion
              wrote on last edited by
              #6

              @ocgltd said in query.bind not formatting date correctly:

              ...but maybe someone at Qt could check into this. I can open a ticket if that helps...

              The unittests with MySQL working fine for me so I would ask for a mre and some more there or here - whatever you want.
              It's also important to know the used mysql libs (or mariadb) and the server version.

              --> we need a minimal, compilable example of this here.

              Qt Online Installer direct download: https://download.qt.io/official_releases/online_installers/
              Visit the Qt Academy at https://academy.qt.io/catalog

              ocgltdO 1 Reply Last reply
              1
              • Christian EhrlicherC Christian Ehrlicher

                @ocgltd said in query.bind not formatting date correctly:

                ...but maybe someone at Qt could check into this. I can open a ticket if that helps...

                The unittests with MySQL working fine for me so I would ask for a mre and some more there or here - whatever you want.
                It's also important to know the used mysql libs (or mariadb) and the server version.

                --> we need a minimal, compilable example of this here.

                ocgltdO Offline
                ocgltdO Offline
                ocgltd
                wrote on last edited by ocgltd
                #7

                @Christian-Ehrlicher Ok - I'll leave this thread open for now. Once I'm done this current program I'll create an MRE and provide addition info.

                Development system info:

                Qt 5.15.2
                Alma Linux release 9.2
                MariaDB 15.1 Distrib 10.5.16
                mariadb-connector-c-devel 3.2.6-1.el9
                mariadb-devel 10.5.12-3.el9
                

                Host running SQL server:

                Alma Linux release 9.2
                MariaDB server 10.5.1 Distrib 10.5.16
                
                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