[Python-Dev] Bug in the DELETE statement in sqlite3 module
python-dev at masklinn.net
Wed Jun 15 11:34:31 EDT 2016
> On 2016-06-15, at 08:40 , ninostephen mathew <ninosm12 at gmail.com> wrote:
> Respected Developer(s),
> while writing a database module for one of my applications in python I encountered something interesting. I had a username and password field in my table and only one entry which was "Admin" and "password". While debugging I purposefully deleted that record. Then I ran the same statement again. To my surprise, it got execute. Then I ran the statement to delete the user "admin" (lowercase 'a') which does not exist in the table. Surprisingly again is got executed even though the table was empty. What I expected was an error popping up. But nothing happened. I hope this error gets fixed soon. The code snippet is given below.
> self.cursor.execute(''' DELETE FROM Users WHERE username = ?''',(self.username,))
Despite Python bundling sqlite, the Python mailing list is not
responsible for developing SQLite (only for the SQLite bindings
themselves) so this is the wrong mailing list.
That being said, the DELETE statement deletes whichever records in the
table match the provided predicate. If no record matches the predicate,
it will simply delete no record, that is not an error, it is the exact
expected and documented behaviour for the statement in SQL in general
and SQLite in particular.
See https://www.sqlite.org/lang_delete.html for the documentation of the
DELETE statement in SQLite.
While you should feel free to report your expectations to the SQLite
project or to the JTC1/SC32 technical committee (which is responsible
for SQL itself) I fear that's what you will get told there, and that you
are about 30 years too late to try influence such a core statement of
Not that it would have worked I'd think, I'm reasonably sure the
behaviour of the DELETE statement is a natural consequence of SQL's set-
theoretic foundations: DELETE applies to a set of records, regardless of
the set's cardinality.
More information about the Python-Dev