function TPDO.query_delete (const DeletionMethod: TDeletionMethod; const tablename: Ansistring; const condition: Ansistring = ''; const limit: longword = 0; const order: Ansistring = ''): int64;
TPDO.query_delete internally assembles a single table SQL delete statement based on the database driver in use. This function is particularly helpful when the application can be connected to multiple databases, so the program should have to be written to specific drivers.
DeletionMethod: enumeration of DELETE_PARTIAL, DELETE_ALL, TRUNCATE tablename: name of table with optional alias condition: the conditions normally found in the WHERE clause limit: the maximum number of rows to be deleted that meet the conditions order by: only used with limit, it orders the rows before limiting the number deleted.
TPDO.query_delete returns the number of rows deleted by the operation
If the DeletionMethod equals TRUNCATE or DELETE_ALL, the condition, limit, and order by components are ignored. IF the database doesn't support TRUNCATE, the DELETE_ALL method will be used, which is equivalent to DELETE_PARTIAL without any condition.
Limiting deletes is generally considered bad form, and most databases don't support it directly, although MySQL does and recently Firebird 2.0 adds a ROWS keyword. For maximum portability, consider not using LIMIT and ORDER BY for deletions.
This applies to single tables only. Some database support multi-table deletions, so this is covered by another command.
procedure example; var rows_deleted: integer; Begin rows_deleted := db.query_delete(DELETE_PARTIAL, 'nfl_teams', 'nfl_team > 40', 2, 'nfl_team DESC'); writeln ('deleted ' + inttostr(rows_deleted) + ' teams.'); end;
The above example may output:
deleted 2 teams.