QSqlQuery Postgres and timestamp => QDateTime(Invalid)
-
Hi,
During migration of a project from Qt 6.7.3 to 6.8 I stumbled over a wired invalid QDateTime variant. I can reproduce the bug(?) with a sample project.
The PostgreSQL 16.4 table looks like:
create table test(id serial, tm timestamptz);
I inserted a few rows with now() as timestamp, a select works fine:
testdb=# select * from test; id | tm ----+------------------------------- 1 | 2024-10-12 08:56:00.330157+02 2 | 2024-10-12 08:56:03.243138+02 3 | 2024-10-12 08:56:04.754017+02 (3 rows)
Querying this table with a QSqlQuery object under 6.7.3 shows the expected behavior:
true QVariant(int, 1) QVariant(QDateTime, QDateTime(2024-10-12 08:56:00.330 Mitteleuropõische Sommerzeit Qt::LocalTime)) QVariant(int, 2) QVariant(QDateTime, QDateTime(2024-10-12 08:56:03.243 Mitteleuropõische Sommerzeit Qt::LocalTime)) QVariant(int, 3) QVariant(QDateTime, QDateTime(2024-10-12 08:56:04.754 Mitteleuropõische Sommerzeit Qt::LocalTime))
Just recompile with Qt 6.8 and the result looks like:
true QVariant(int, 1) QVariant(QDateTime, QDateTime(Invalid)) QVariant(int, 2) QVariant(QDateTime, QDateTime(Invalid)) QVariant(int, 3) QVariant(QDateTime, QDateTime(Invalid))
So I cannot access timestamp values anymore. Date values are working fine, simple time field not tested.
Am I doing something wrong, missing to send any additional connection parameter or is it simple a bug?
BR Henning
int main(int argc, char* argv[]) { QCoreApplication a(argc, argv); auto db = QSqlDatabase::addDatabase("QPSQL"); db.setHostName("loggix"); db.setDatabaseName("testdb"); qDebug() << db.open(); auto query = QSqlQuery(db); if (!query.exec("select * from test")) { qDebug() << db.lastError().text(); return 1; } while (query.next()) { qDebug() << query.value("id") << query.value("tm"); } return 0; }
-
Possibility that QTBUG-115960 and the associated fix have something to do with this. I cannot quite see it though, and I do not have PostgreSql readily to hand. @Christian-Ehrlicher has his name in the bug commentary; perhaps we will get some further comment.
-
I'll take a look on it, thx for the report. Please create a bug report.
-
-