fix: SHOW is not DML (#13464)

* fix: SHOW is not DML

* Fix test
This commit is contained in:
Beto Dealmeida 2021-03-04 17:17:25 -08:00 committed by GitHub
parent d2e03ab9b4
commit 528ea9cbb0
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 8 additions and 2 deletions

View File

@ -1096,4 +1096,8 @@ class BaseEngineSpec: # pylint: disable=too-many-public-methods
@classmethod
def is_readonly_query(cls, parsed_query: ParsedQuery) -> bool:
"""Pessimistic readonly, 100% sure statement won't mutate anything"""
return parsed_query.is_select() or parsed_query.is_explain()
return (
parsed_query.is_select()
or parsed_query.is_explain()
or parsed_query.is_show()
)

View File

@ -263,9 +263,11 @@ def test_is_readonly():
def is_readonly(sql: str) -> bool:
return BaseEngineSpec.is_readonly_query(ParsedQuery(sql))
assert not is_readonly("SHOW LOCKS test EXTENDED")
assert is_readonly("SHOW LOCKS test EXTENDED")
assert not is_readonly("SET hivevar:desc='Legislators'")
assert not is_readonly("UPDATE t1 SET col1 = NULL")
assert is_readonly("EXPLAIN SELECT 1")
assert is_readonly("SELECT 1")
assert is_readonly("WITH (SELECT 1) bla SELECT * from bla")
assert is_readonly("SHOW CATALOGS")
assert is_readonly("SHOW TABLES")