From 1d6be599f5c12e9ce23bbdf081a103aa62618e15 Mon Sep 17 00:00:00 2001 From: Bill King Date: Fri, 4 Dec 2009 10:48:37 +1000 Subject: Fixes: QOCI setForwardOnly(true) accumulating values. readPiecewise() is assuming an empty valueCache when reading a new row. setForwardOnly(true) means that only one row is used/re-used. The value cache wasn't being cleared out when moving to a new row, so the above assumption was invalid. Task-number: QTBUG-6421 Reviewed-by: Justin McPherson --- src/sql/kernel/qsqlcachedresult.cpp | 5 +++++ tests/auto/qsqlquery/tst_qsqlquery.cpp | 28 +++++++++++++++++++++++++++- 2 files changed, 32 insertions(+), 1 deletion(-) diff --git a/src/sql/kernel/qsqlcachedresult.cpp b/src/sql/kernel/qsqlcachedresult.cpp index b4a9241..2e4d19e 100644 --- a/src/sql/kernel/qsqlcachedresult.cpp +++ b/src/sql/kernel/qsqlcachedresult.cpp @@ -278,6 +278,11 @@ bool QSqlCachedResult::cacheNext() if (d->atEnd) return false; + if(isForwardOnly()) { + d->cache.clear(); + d->cache.resize(d->colCount); + } + if (!gotoNext(d->cache, d->nextIndex())) { d->revertLast(); d->atEnd = true; diff --git a/tests/auto/qsqlquery/tst_qsqlquery.cpp b/tests/auto/qsqlquery/tst_qsqlquery.cpp index 4264a70..a8908fd 100644 --- a/tests/auto/qsqlquery/tst_qsqlquery.cpp +++ b/tests/auto/qsqlquery/tst_qsqlquery.cpp @@ -199,6 +199,8 @@ private slots: void QTBUG_5251_data() { generic_data("QPSQL"); } void QTBUG_5251(); + void QTBUG_6421_data() { generic_data("QOCI"); } + void QTBUG_6421(); private: // returns all database connections @@ -302,7 +304,8 @@ void tst_QSqlQuery::dropTestTables( QSqlDatabase db ) << qTableName( "more_results" ) << qTableName( "blobstest" ) << qTableName( "oraRowId" ) - << qTableName( "qtest_batch" ); + << qTableName( "qtest_batch" ) + << qTableName(QLatin1String("bug6421")).toUpper(); if ( db.driverName().startsWith("QPSQL") ) tablenames << qTableName("task_233829"); @@ -2935,5 +2938,28 @@ void tst_QSqlQuery::QTBUG_5251() } +void tst_QSqlQuery::QTBUG_6421() +{ + QFETCH( QString, dbName ); + QSqlDatabase db = QSqlDatabase::database( dbName ); + CHECK_DATABASE( db ); + + QSqlQuery q(db); + QString tableName=qTableName(QLatin1String("bug6421")).toUpper(); + + QVERIFY_SQL(q, exec("create table "+tableName+"(COL1 char(10), COL2 char(10), COL3 char(10))")); + QVERIFY_SQL(q, exec("create index INDEX1 on "+tableName+" (COL1 desc)")); + QVERIFY_SQL(q, exec("create index INDEX2 on "+tableName+" (COL2 desc)")); + QVERIFY_SQL(q, exec("create index INDEX3 on "+tableName+" (COL3 desc)")); + q.setForwardOnly(true); + QVERIFY_SQL(q, exec("select COLUMN_EXPRESSION from ALL_IND_EXPRESSIONS where TABLE_NAME='"+tableName+"'")); + QVERIFY_SQL(q, next()); + QCOMPARE(q.value(0).toString(), QLatin1String("\"COL1\"")); + QVERIFY_SQL(q, next()); + QCOMPARE(q.value(0).toString(), QLatin1String("\"COL2\"")); + QVERIFY_SQL(q, next()); + QCOMPARE(q.value(0).toString(), QLatin1String("\"COL3\"")); +} + QTEST_MAIN( tst_QSqlQuery ) #include "tst_qsqlquery.moc" -- cgit v0.12