Intermediate
Judge a generated SQL string
Write check_sql(sql, allowed) that returns "ok" or "rejected: <reason>". Never run anything: only inspect the text.
Rules, checked in this order: the text (after removing one trailing ;) must not contain ; (reason more than one statement); its first word, in lower case, must be select (reason only SELECT); the word after every from or join must be in allowed (reason table not allowed: <name>). Words are lower-case runs of letters, digits and underscores.
What Check tests
- A plain SELECT on an allowed table is ok
- A trailing semicolon is fine
- Other statements are rejected
- Two statements are rejected first
- Tables are checked after FROM and JOIN
Stuck? One hint at a time
The solution unlocks after your first Check. Try first: that is where the learning happens.
main.py
Sign in to run your code.
Output
Press Run to see what your program prints.