Skip to content

Commit 91c0956

Browse files
author
Derick Hawcroft
committed
Fix retrieval of SQL type "TIME" information for PostgreSQL
PostgreSQL can store/retieve the millisecond part of type "TIME" , so allow it in the API level. Task-number: QTBUG-5251 Reviewed-by: Bill King
1 parent 5906504 commit 91c0956

File tree

2 files changed

+33
-1
lines changed

2 files changed

+33
-1
lines changed

src/sql/drivers/psql/qsql_psql.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1133,7 +1133,7 @@ QString QPSQLDriver::formatValue(const QSqlField &field, bool trimStrings) const
11331133
case QVariant::Time:
11341134
#ifndef QT_NO_DATESTRING
11351135
if (field.value().toTime().isValid()) {
1136-
r = QLatin1Char('\'') + field.value().toTime().toString(Qt::ISODate) + QLatin1Char('\'');
1136+
r = QLatin1Char('\'') + field.value().toTime().toString(QLatin1String("hh:mm:ss.zzz")) + QLatin1Char('\'');
11371137
} else
11381138
#endif
11391139
{

tests/auto/qsqlquery/tst_qsqlquery.cpp

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -194,6 +194,8 @@ private slots:
194194
void sqlServerReturn0_data() { generic_data(); }
195195
void sqlServerReturn0();
196196

197+
void QTBUG_5251_data() { generic_data("QPSQL"); }
198+
void QTBUG_5251();
197199

198200
private:
199201
// returns all database connections
@@ -2880,5 +2882,35 @@ void tst_QSqlQuery::sqlServerReturn0()
28802882
QVERIFY_SQL(q, next());
28812883
}
28822884

2885+
void tst_QSqlQuery::QTBUG_5251()
2886+
{
2887+
QFETCH( QString, dbName );
2888+
QSqlDatabase db = QSqlDatabase::database( dbName );
2889+
CHECK_DATABASE( db );
2890+
2891+
if (!db.driverName().startsWith( "QPSQL" )) return;
2892+
2893+
QSqlQuery q(db);
2894+
q.exec("DROP TABLE " + qTableName("timetest"));
2895+
QVERIFY_SQL(q, exec("CREATE TABLE " + qTableName("timetest") + " (t TIME)"));
2896+
QVERIFY_SQL(q, exec("INSERT INTO " + qTableName("timetest") + " VALUES ('1:2:3.666')"));
2897+
2898+
QSqlTableModel timetestModel(0,db);
2899+
timetestModel.setEditStrategy(QSqlTableModel::OnManualSubmit);
2900+
timetestModel.setTable(qTableName("timetest"));
2901+
QVERIFY_SQL(timetestModel, select());
2902+
2903+
QCOMPARE(timetestModel.record(0).field(0).value().toTime().toString("HH:mm:ss.zzz"), QString("01:02:03.666"));
2904+
QVERIFY_SQL(timetestModel,setData(timetestModel.index(0, 0), QTime(0,12,34,500)));
2905+
QCOMPARE(timetestModel.record(0).field(0).value().toTime().toString("HH:mm:ss.zzz"), QString("00:12:34.500"));
2906+
QVERIFY_SQL(timetestModel, submitAll());
2907+
QCOMPARE(timetestModel.record(0).field(0).value().toTime().toString("HH:mm:ss.zzz"), QString("00:12:34.500"));
2908+
2909+
QVERIFY_SQL(q, exec("UPDATE " + qTableName("timetest") + " SET t = '0:11:22.33'"));
2910+
QVERIFY_SQL(timetestModel, select());
2911+
QCOMPARE(timetestModel.record(0).field(0).value().toTime().toString("HH:mm:ss.zzz"), QString("00:11:22.330"));
2912+
2913+
}
2914+
28832915
QTEST_MAIN( tst_QSqlQuery )
28842916
#include "tst_qsqlquery.moc"

0 commit comments

Comments
 (0)