query.bind not formatting date correctly
-
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.
-
Hi,
Are you sure you were using that format ?
What does your database expect ? -
@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?
-
@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?
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.
-
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.
@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-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...
@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.
-
@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.
@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.el9Host running SQL server:
Alma Linux release 9.2 MariaDB server 10.5.1 Distrib 10.5.16