diff options
-rw-r--r-- | src/sql/drivers/psql/qsql_psql.cpp | 2 | ||||
-rw-r--r-- | src/sql/models/qsqltablemodel.cpp | 2 | ||||
-rw-r--r-- | tests/auto/qsqlquery/tst_qsqlquery.cpp | 32 |
3 files changed, 34 insertions, 2 deletions
diff --git a/src/sql/drivers/psql/qsql_psql.cpp b/src/sql/drivers/psql/qsql_psql.cpp index 4c78d6a23a..3e3ea06664 100644 --- a/src/sql/drivers/psql/qsql_psql.cpp +++ b/src/sql/drivers/psql/qsql_psql.cpp @@ -1133,7 +1133,7 @@ QString QPSQLDriver::formatValue(const QSqlField &field, bool trimStrings) const case QVariant::Time: #ifndef QT_NO_DATESTRING if (field.value().toTime().isValid()) { - r = QLatin1Char('\'') + field.value().toTime().toString(Qt::ISODate) + QLatin1Char('\''); + r = QLatin1Char('\'') + field.value().toTime().toString(QLatin1String("hh:mm:ss.zzz")) + QLatin1Char('\''); } else #endif { diff --git a/src/sql/models/qsqltablemodel.cpp b/src/sql/models/qsqltablemodel.cpp index a91dc9fc51..98f22c8192 100644 --- a/src/sql/models/qsqltablemodel.cpp +++ b/src/sql/models/qsqltablemodel.cpp @@ -406,7 +406,7 @@ bool QSqlTableModel::select() QSqlQuery qu(query, d->db); setQuery(qu); - if (!qu.isActive()) { + if (!qu.isActive() || lastError().isValid()) { // something went wrong - revert to non-select state d->initRecordAndPrimaryIndex(); return false; diff --git a/tests/auto/qsqlquery/tst_qsqlquery.cpp b/tests/auto/qsqlquery/tst_qsqlquery.cpp index 3463153214..87774a3250 100644 --- a/tests/auto/qsqlquery/tst_qsqlquery.cpp +++ b/tests/auto/qsqlquery/tst_qsqlquery.cpp @@ -194,6 +194,8 @@ private slots: void sqlServerReturn0_data() { generic_data(); } void sqlServerReturn0(); + void QTBUG_5251_data() { generic_data("QPSQL"); } + void QTBUG_5251(); private: // returns all database connections @@ -2880,5 +2882,35 @@ void tst_QSqlQuery::sqlServerReturn0() QVERIFY_SQL(q, next()); } +void tst_QSqlQuery::QTBUG_5251() +{ + QFETCH( QString, dbName ); + QSqlDatabase db = QSqlDatabase::database( dbName ); + CHECK_DATABASE( db ); + + if (!db.driverName().startsWith( "QPSQL" )) return; + + QSqlQuery q(db); + q.exec("DROP TABLE " + qTableName("timetest")); + QVERIFY_SQL(q, exec("CREATE TABLE " + qTableName("timetest") + " (t TIME)")); + QVERIFY_SQL(q, exec("INSERT INTO " + qTableName("timetest") + " VALUES ('1:2:3.666')")); + + QSqlTableModel timetestModel(0,db); + timetestModel.setEditStrategy(QSqlTableModel::OnManualSubmit); + timetestModel.setTable(qTableName("timetest")); + QVERIFY_SQL(timetestModel, select()); + + QCOMPARE(timetestModel.record(0).field(0).value().toTime().toString("HH:mm:ss.zzz"), QString("01:02:03.666")); + QVERIFY_SQL(timetestModel,setData(timetestModel.index(0, 0), QTime(0,12,34,500))); + QCOMPARE(timetestModel.record(0).field(0).value().toTime().toString("HH:mm:ss.zzz"), QString("00:12:34.500")); + QVERIFY_SQL(timetestModel, submitAll()); + QCOMPARE(timetestModel.record(0).field(0).value().toTime().toString("HH:mm:ss.zzz"), QString("00:12:34.500")); + + QVERIFY_SQL(q, exec("UPDATE " + qTableName("timetest") + " SET t = '0:11:22.33'")); + QVERIFY_SQL(timetestModel, select()); + QCOMPARE(timetestModel.record(0).field(0).value().toTime().toString("HH:mm:ss.zzz"), QString("00:11:22.330")); + +} + QTEST_MAIN( tst_QSqlQuery ) #include "tst_qsqlquery.moc" |