Details
-
Bug
-
Resolution: Fixed
-
P3: Somewhat important
-
5.15.3, 6.6.0 FF
-
None
-
OS: Ubuntu 22.04.2 LTS on Win;
Database: PostgreSQL 15.2 (Debian 15.2-1.pgdg110+1) on x86_64-pc-linux-gnu, compil ed by gcc (Debian 10.2.1-6) 10.2.1 20210110, 64-bit
OS Locale: pt_BR.utf8 (-3 hours from gmt)
-
-
b71f185ff (dev)
Description
I created a table using CREATE TABLE a ( data TIMESTAMP );. When inserting the curren datetime it inserts using the UTC timestamp, which means that if my local time is 12:00 the database will have 15:00 inserted.
The issue is when retriving this time it will treat it as a local time, so it assumes my local time is 15:00 when it is 12:00;
Below is a code to reproduce this issue. Note that the issue doesn't happen if the column type is TIMESTAMP WITH TIME ZONE, only when its TIMESTAMP.
int main(int argc, char **argv) { // setting database QSqlDatabase db = QSqlDatabase::database(); db = QSqlDatabase::addDatabase("QPSQL"); db.setDatabaseName("xxx"); db.setUserName("xxx"); db.setPort(32768); db.setPassword("xxx"); db.open(); // inserting auto data = QDateTime::currentDateTime(); QSqlQuery query; query.prepare("INSERT INTO a VALUES (?)"); query.addBindValue(data); query.exec(); // retriving QSqlQuery query2; query2.prepare("SELECT * FROM a"); query2.exec(); query2.next(); auto data2 = query2.value(0).toDateTime(); qDebug() << data; // QDateTime(2023-08-09 10:33:47.878 -03 Qt::LocalTime) qDebug() << data2; // QDateTime(2023-08-09 13:33:47.878 -03 Qt::LocalTime) assert(data == data2); // fails }
Attachments
Issue Links
- resulted in
-
QTBUG-129983 QSqlQuery Postgres and timestamp => QDateTime(Invalid)
- Closed
For Gerrit Dashboard: QTBUG-115960 | ||||||
---|---|---|---|---|---|---|
# | Subject | Branch | Project | Status | CR | V |
547611,3 | SQL/PostgreSQL: Make sure the server returns datetime in UTC | dev | qt/qtbase | Status: MERGED | +2 | 0 |