sqlcsqlitesql-delete

Returning Deleted Rows in SQLite


For performance reasons, I want to run an SQLite query that deletes rows AND returns the deleted rows so I don't have to run two separate queries when I want to know what is being deleted. PostOgreSQL allows this using something like "RETURNING *" at the end, but I can't find anything in the documentation for SQLite. How do I do this?

This is what I have currently. The "%s" parts are replaced with inputs, of course (and I sanitize the inputs):

"DELETE FROM '%s' WHERE ( username1 = '%s' OR username2 = '%s' ) AND uid = '%s'"

In case it matters, I'm programming in C, using the SQLite code from sqlite.com.


Solution

  • Try the OLD alias. This should get you the results you are needing.