diff options
-rw-r--r-- | src/sql/drivers/ibase/qsql_ibase.cpp | 14 | ||||
-rw-r--r-- | tests/auto/sql/kernel/qsqlquery/tst_qsqlquery.cpp | 12 |
2 files changed, 24 insertions, 2 deletions
diff --git a/src/sql/drivers/ibase/qsql_ibase.cpp b/src/sql/drivers/ibase/qsql_ibase.cpp index d50078b5ff..cc26bfe7e8 100644 --- a/src/sql/drivers/ibase/qsql_ibase.cpp +++ b/src/sql/drivers/ibase/qsql_ibase.cpp @@ -1313,6 +1313,7 @@ int QIBaseResult::numRowsAffected() { static char acCountInfo[] = {isc_info_sql_records}; char cCountType; + bool bIsProcedure = false; switch (d->queryType) { case isc_info_sql_stmt_select: @@ -1327,6 +1328,9 @@ int QIBaseResult::numRowsAffected() case isc_info_sql_stmt_insert: cCountType = isc_info_req_insert_count; break; + case isc_info_sql_stmt_exec_procedure: + bIsProcedure = true; // will sum all changes + break; default: qWarning() << "numRowsAffected: Unknown statement type (" << d->queryType << ")"; return -1; @@ -1344,8 +1348,14 @@ int QIBaseResult::numRowsAffected() pcBuf += 2; int iValue = isc_vax_integer (pcBuf, sLength); pcBuf += sLength; - - if (cType == cCountType) { + if (bIsProcedure) { + if (cType == isc_info_req_insert_count || cType == isc_info_req_update_count + || cType == isc_info_req_delete_count) { + if (iResult == -1) + iResult = 0; + iResult += iValue; + } + } else if (cType == cCountType) { iResult = iValue; break; } diff --git a/tests/auto/sql/kernel/qsqlquery/tst_qsqlquery.cpp b/tests/auto/sql/kernel/qsqlquery/tst_qsqlquery.cpp index 5f1eb99524..a497fac79a 100644 --- a/tests/auto/sql/kernel/qsqlquery/tst_qsqlquery.cpp +++ b/tests/auto/sql/kernel/qsqlquery/tst_qsqlquery.cpp @@ -1069,6 +1069,18 @@ void tst_QSqlQuery::numRowsAffected() QCOMPARE( q.numRowsAffected(), i ); QCOMPARE( q.numRowsAffected(), i ); // yes, we check twice + QVERIFY_SQL( q, prepare( "update " + qtest + " set id = id + :newid" ) ); + q.bindValue(":newid", 100); + QVERIFY_SQL( q, exec() ); + QCOMPARE( q.numRowsAffected(), i ); + QCOMPARE( q.numRowsAffected(), i ); // yes, we check twice + + QVERIFY_SQL( q, prepare( "update " + qtest + " set id = id + :newid where NOT(1 = 1)" ) ); + q.bindValue(":newid", 100); + QVERIFY_SQL( q, exec() ); + QCOMPARE( q.numRowsAffected(), 0 ); + QCOMPARE( q.numRowsAffected(), 0 ); // yes, we check twice + QVERIFY_SQL( q, exec( "insert into " + qtest + " values (42000, 'homer', 'marge')" ) ); QCOMPARE( q.numRowsAffected(), 1 ); QCOMPARE( q.numRowsAffected(), 1 ); // yes, we check twice |