From fffd69ec031b83f46680f192ba57a27f0d1f0b8a Mon Sep 17 00:00:00 2001 From: Simon Willison Date: Sun, 6 Oct 2019 10:23:58 -0700 Subject: [PATCH] Allow EXPLAIN WITH... - closes #583 --- datasette/utils/__init__.py | 2 ++ tests/test_utils.py | 4 ++++ 2 files changed, 6 insertions(+) diff --git a/datasette/utils/__init__.py b/datasette/utils/__init__.py index 115c4cbe..449217b5 100644 --- a/datasette/utils/__init__.py +++ b/datasette/utils/__init__.py @@ -167,6 +167,8 @@ allowed_sql_res = [ re.compile(r"^explain select\b"), re.compile(r"^explain query plan select\b"), re.compile(r"^with\b"), + re.compile(r"^explain with\b"), + re.compile(r"^explain query plan with\b"), ] disallawed_sql_res = [(re.compile("pragma"), "Statement may not contain PRAGMA")] diff --git a/tests/test_utils.py b/tests/test_utils.py index 4b14126e..28b0d0e1 100644 --- a/tests/test_utils.py +++ b/tests/test_utils.py @@ -151,8 +151,12 @@ def test_validate_sql_select_bad(bad_sql): "select count(*) from airports", "select foo from bar", "select 1 + 1", + "explain select 1 + 1", + "explain query plan select 1 + 1", "SELECT\nblah FROM foo", "WITH RECURSIVE cnt(x) AS (SELECT 1 UNION ALL SELECT x+1 FROM cnt LIMIT 10) SELECT x FROM cnt;", + "explain WITH RECURSIVE cnt(x) AS (SELECT 1 UNION ALL SELECT x+1 FROM cnt LIMIT 10) SELECT x FROM cnt;", + "explain query plan WITH RECURSIVE cnt(x) AS (SELECT 1 UNION ALL SELECT x+1 FROM cnt LIMIT 10) SELECT x FROM cnt;", ], ) def test_validate_sql_select_good(good_sql):