[QtSql]QIBASE]add support for prepared queries in numRowsAffected

Prepared queries need to be handled as procedures.

Change-Id: I4b4d7743fe45c416ca83ceb942aa48d79731f2f8
Reviewed-by: Mark Brand <mabrand@mabrand.nl>
This commit is contained in:
Israel Lins Albuquerque 2014-03-26 12:45:41 -03:00 committed by The Qt Project
parent d432091622
commit 075c876f9a
2 changed files with 24 additions and 2 deletions

View File

@ -1313,6 +1313,7 @@ int QIBaseResult::numRowsAffected()
{ {
static char acCountInfo[] = {isc_info_sql_records}; static char acCountInfo[] = {isc_info_sql_records};
char cCountType; char cCountType;
bool bIsProcedure = false;
switch (d->queryType) { switch (d->queryType) {
case isc_info_sql_stmt_select: case isc_info_sql_stmt_select:
@ -1327,6 +1328,9 @@ int QIBaseResult::numRowsAffected()
case isc_info_sql_stmt_insert: case isc_info_sql_stmt_insert:
cCountType = isc_info_req_insert_count; cCountType = isc_info_req_insert_count;
break; break;
case isc_info_sql_stmt_exec_procedure:
bIsProcedure = true; // will sum all changes
break;
default: default:
qWarning() << "numRowsAffected: Unknown statement type (" << d->queryType << ")"; qWarning() << "numRowsAffected: Unknown statement type (" << d->queryType << ")";
return -1; return -1;
@ -1344,8 +1348,14 @@ int QIBaseResult::numRowsAffected()
pcBuf += 2; pcBuf += 2;
int iValue = isc_vax_integer (pcBuf, sLength); int iValue = isc_vax_integer (pcBuf, sLength);
pcBuf += sLength; pcBuf += sLength;
if (bIsProcedure) {
if (cType == cCountType) { 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; iResult = iValue;
break; break;
} }

View File

@ -1069,6 +1069,18 @@ void tst_QSqlQuery::numRowsAffected()
QCOMPARE( q.numRowsAffected(), i ); QCOMPARE( q.numRowsAffected(), i );
QCOMPARE( q.numRowsAffected(), i ); // yes, we check twice 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')" ) ); QVERIFY_SQL( q, exec( "insert into " + qtest + " values (42000, 'homer', 'marge')" ) );
QCOMPARE( q.numRowsAffected(), 1 ); QCOMPARE( q.numRowsAffected(), 1 );
QCOMPARE( q.numRowsAffected(), 1 ); // yes, we check twice QCOMPARE( q.numRowsAffected(), 1 ); // yes, we check twice