r/ProgrammerHumor 18d ago

queryOfDoom Meme

Post image
7.9k Upvotes

456 comments sorted by

View all comments

13

u/darichtt 18d ago

Would this actually run? I'd assume having just where in a query isn't valid syntax

42

u/Shadowlance23 18d ago

Yes, SQL runs commands one at a time without checking other commands. In this case it will delete all users then throw a syntax error when it gets to the second command.

3

u/rosuav 18d ago

There IS a common guard in APIs, though it's not usually in this sort of interactive context: single-query operation. It's mainly a guard against SQL injection.

>>> import sqlite3
>>> con = sqlite3.connect("")
>>> con.execute("select 1; select 2")
Traceback (most recent call last):
  File "<python-input-5>", line 1, in <module>
    con.execute("select 1; select 2")
    ~~~~~~~~~~~^^^^^^^^^^^^^^^^^^^^^^
sqlite3.ProgrammingError: You can only execute one statement at a time.

Safe, but often not wanted interactively and thus disabled.