[sqllab] Fix limit parsing bug when using limit-offset comma notation (#7912)

* Fix limit parsing bug when using limit-offset comma notation

* Use native sqlparse semantics to find limit

* black
This commit is contained in:
Ville Brofeldt
2019-07-24 08:18:39 +03:00
committed by GitHub
parent 07a76f83b1
commit 72d1011023
2 changed files with 6 additions and 3 deletions

View File

@@ -182,7 +182,10 @@ class ParsedQuery(object):
_, token = statement.token_next(idx=idx)
if token:
if isinstance(token, IdentifierList):
_, token = token.token_next(idx=-1)
# In case of "LIMIT <offset>, <limit>", find comma and extract
# first succeeding non-whitespace token
idx, _ = token.token_next_by(m=(sqlparse.tokens.Punctuation, ","))
_, token = token.token_next(idx=idx)
if token and token.ttype == sqlparse.tokens.Literal.Number.Integer:
return int(token.value)