diff options
author | Thiago A. Correa <thiago.correa@gmail.com> | 2012-07-13 14:28:18 -0300 |
---|---|---|
committer | Qt by Nokia <qt-info@nokia.com> | 2012-07-16 23:48:10 +0200 |
commit | b8b79a0f37ec74fd5b4ad829e522a384ba3622ae (patch) | |
tree | 030a88e4b3a780e54967b73fa95f7d216af59ac2 /tests/auto/sql | |
parent | 5762da38b989e65dedd3d04e258615a9558e4bf1 (diff) |
Fix error when inserting to tables with datetime fields with QODBC
SQL Server 10 introduced stricter rules for TIMESTAMP validation,
making it necessary to specify the decimal digits.
Other databases might do the same as well, so this patch introduces
a check for the TIMESTAMP column size and adjusts the decimal digits
parameter as needed.
Task-number: QTBUG-2192
Change-Id: If6d798c6c928ebda75bc474e49a07fbbfbe5816c
Reviewed-by: Mark Brand <mabrand@mabrand.nl>
Diffstat (limited to 'tests/auto/sql')
-rw-r--r-- | tests/auto/sql/kernel/qsqlquery/tst_qsqlquery.cpp | 28 |
1 files changed, 27 insertions, 1 deletions
diff --git a/tests/auto/sql/kernel/qsqlquery/tst_qsqlquery.cpp b/tests/auto/sql/kernel/qsqlquery/tst_qsqlquery.cpp index b5fb36a62b..d39934d10a 100644 --- a/tests/auto/sql/kernel/qsqlquery/tst_qsqlquery.cpp +++ b/tests/auto/sql/kernel/qsqlquery/tst_qsqlquery.cpp @@ -219,6 +219,8 @@ private slots: void QTBUG_16967(); //clean close void QTBUG_23895_data() { generic_data("QSQLITE"); } void QTBUG_23895(); //sqlite boolean type + void QTBUG_2192_data() { generic_data(); } + void QTBUG_2192(); void sqlite_constraint_data() { generic_data("QSQLITE"); } void sqlite_constraint(); @@ -341,7 +343,8 @@ void tst_QSqlQuery::dropTestTables( QSqlDatabase db ) << qTableName( "task_250026", __FILE__ ) << qTableName( "task_234422", __FILE__ ) << qTableName("test141895", __FILE__) - << qTableName("qtest_oraOCINumber", __FILE__); + << qTableName("qtest_oraOCINumber", __FILE__) + << qTableName( "bug2192", __FILE__); if ( db.driverName().startsWith("QPSQL") ) tablenames << qTableName("task_233829", __FILE__); @@ -3357,6 +3360,29 @@ void tst_QSqlQuery::QTBUG_23895() QVERIFY(!q.next()); } +void tst_QSqlQuery::QTBUG_2192() +{ + QFETCH( QString, dbName ); + QSqlDatabase db = QSqlDatabase::database( dbName ); + CHECK_DATABASE( db ); + { + const QString tableName(qTableName("bug2192", __FILE__)); + tst_Databases::safeDropTable( db, tableName ); + + QSqlQuery q(db); + QVERIFY_SQL(q, exec("CREATE TABLE " + tableName + " (dt DATETIME)")); + + QVERIFY_SQL(q, prepare("INSERT INTO " + tableName + " (dt) VALUES (?)")); + q.bindValue(0, QVariant(QDateTime(QDate(2012, 7, 4), QTime(23, 59, 59, 999)))); + QVERIFY_SQL(q, exec()); + + // Check if value was stored with at least second precision. + QVERIFY_SQL(q, exec("SELECT dt FROM " + tableName)); + QVERIFY_SQL(q, next()); + QVERIFY(q.value(0).toDateTime().msecsTo(QDateTime(QDate(2012, 7, 4), QTime(23, 59, 59, 999))) < 1000 ); + } +} + void tst_QSqlQuery::oraOCINumber() { QFETCH( QString, dbName ); |