Pascal Data Objects

function IPDOStatement.getRowsAffected: Int64;

This function returns the number of rows affected by the last DELETE, INSERT, or UPDATE statement executed by the corresponding PDOStatement object.

If the last SQL statement executed by the associated PDOStatement was a SELECT statement, some databases may return the number of rows returned by that statement. However, this behaviour is not guaranteed for all databases and should not be relied on for portable applications.


Example 1. Return the number of deleted rows IPDOStatement.getRowsAffected returns the number of rows affected by a DELETE, INSERT, or UPDATE statement.

procedure example1;
   count: Int64;
  {Delete all rows from the FRUIT table }
  stmt = db.prepare_as_is('DELETE FROM fruit');

  {Return number of rows that were deleted}
  count := stmt.getRowsAffected;
  writeln ('Return number of rows that were deleted:');
  writeln (format('Deleted %d rows.', [count]);

The above example will output:

Return number of rows that were deleted:
Deleted 9 rows.