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.

Examples

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;
var
   count: Int64;
begin
  {Delete all rows from the FRUIT table }
  stmt = db.prepare_as_is('DELETE FROM fruit');
  stmt.execute;

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

The above example will output:

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