From 18c0fec3afba909faa341c766f31d679892021db Mon Sep 17 00:00:00 2001 From: Bill King Date: Thu, 17 Sep 2009 13:15:40 +1000 Subject: Fixes issue of forward only datasets failing when not set so. Previously you had to set forward only on non-scrollable datasets explicitly. This queries ODBC, to determine if it's a scrollable dataset, and sets forwardOnly to false if it isn't. Task-number: QT-353 Reviewed-by: Justin McPherson --- src/sql/drivers/odbc/qsql_odbc.cpp | 10 +++++++++ tests/auto/qsqlquery/tst_qsqlquery.cpp | 38 ++++++++++++++++++++++++++++++++++ 2 files changed, 48 insertions(+) diff --git a/src/sql/drivers/odbc/qsql_odbc.cpp b/src/sql/drivers/odbc/qsql_odbc.cpp index a5c713d..6a33d1e 100644 --- a/src/sql/drivers/odbc/qsql_odbc.cpp +++ b/src/sql/drivers/odbc/qsql_odbc.cpp @@ -781,6 +781,11 @@ bool QODBCResult::reset (const QString& query) return false; } + SQLINTEGER isScrollable, bufferLength; + r = SQLGetStmtAttr(d->hStmt, SQL_ATTR_CURSOR_SCROLLABLE, &isScrollable, SQL_IS_INTEGER, &bufferLength); + if(r == SQL_SUCCESS || r == SQL_SUCCESS_WITH_INFO) + setForwardOnly(isScrollable==SQL_NONSCROLLABLE); + SQLSMALLINT count; SQLNumResultCols(d->hStmt, &count); if (count) { @@ -1407,6 +1412,11 @@ bool QODBCResult::exec() return false; } + SQLINTEGER isScrollable, bufferLength; + r = SQLGetStmtAttr(d->hStmt, SQL_ATTR_CURSOR_SCROLLABLE, &isScrollable, SQL_IS_INTEGER, &bufferLength); + if(r == SQL_SUCCESS || r == SQL_SUCCESS_WITH_INFO) + setForwardOnly(isScrollable==SQL_NONSCROLLABLE); + SQLSMALLINT count; SQLNumResultCols(d->hStmt, &count); if (count) { diff --git a/tests/auto/qsqlquery/tst_qsqlquery.cpp b/tests/auto/qsqlquery/tst_qsqlquery.cpp index 1595f33..3463153 100644 --- a/tests/auto/qsqlquery/tst_qsqlquery.cpp +++ b/tests/auto/qsqlquery/tst_qsqlquery.cpp @@ -191,6 +191,9 @@ private slots: void task_233829_data() { generic_data("QPSQL"); } void task_233829(); + void sqlServerReturn0_data() { generic_data(); } + void sqlServerReturn0(); + private: // returns all database connections @@ -310,6 +313,13 @@ void tst_QSqlQuery::dropTestTables( QSqlDatabase db ) tablenames << qTableName( "task_250026" ); + if (tst_Databases::isSqlServer( db )) { + QSqlQuery q( db ); + q.exec("DROP PROCEDURE " + qTableName("test141895_proc")); + } + + tablenames << qTableName("test141895"); + tst_Databases::safeDropTables( db, tablenames ); } @@ -2842,5 +2852,33 @@ void tst_QSqlQuery::task_233829() QVERIFY_SQL(q,exec()); } +void tst_QSqlQuery::sqlServerReturn0() +{ + QFETCH( QString, dbName ); + QSqlDatabase db = QSqlDatabase::database( dbName ); + CHECK_DATABASE( db ); + if (!tst_Databases::isSqlServer( db )) + QSKIP("SQL Server specific test", SkipSingle); + + QString tableName(qTableName("test141895")), procName(qTableName("test141895_proc")); + QSqlQuery q( db ); + q.exec("DROP TABLE " + tableName); + q.exec("DROP PROCEDURE " + procName); + QVERIFY_SQL(q, exec("CREATE TABLE "+tableName+" (id integer)")); + QVERIFY_SQL(q, exec("INSERT INTO "+tableName+" (id) VALUES (1)")); + QVERIFY_SQL(q, exec("INSERT INTO "+tableName+" (id) VALUES (2)")); + QVERIFY_SQL(q, exec("INSERT INTO "+tableName+" (id) VALUES (2)")); + QVERIFY_SQL(q, exec("INSERT INTO "+tableName+" (id) VALUES (3)")); + QVERIFY_SQL(q, exec("INSERT INTO "+tableName+" (id) VALUES (1)")); + QVERIFY_SQL(q, exec("CREATE PROCEDURE "+procName+ + " AS " + "SELECT * FROM "+tableName+" WHERE ID = 2 " + "RETURN 0")); + + QVERIFY_SQL(q, exec("{CALL "+procName+"}")); + + QVERIFY_SQL(q, next()); +} + QTEST_MAIN( tst_QSqlQuery ) #include "tst_qsqlquery.moc" -- cgit v0.12