Skip to content

Commit

Permalink
Support TypedLiterals in get_parameters
Browse files Browse the repository at this point in the history
  • Loading branch information
Khrol authored and andialbrecht committed Mar 5, 2024
1 parent 8d34105 commit dc2329d
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 3 deletions.
7 changes: 4 additions & 3 deletions sqlparse/sql.py
Original file line number Diff line number Diff line change
Expand Up @@ -619,12 +619,13 @@ class Function(NameAliasMixin, TokenList):
def get_parameters(self):
"""Return a list of parameters."""
parenthesis = self.tokens[-1]
result = []
for token in parenthesis.tokens:
if isinstance(token, IdentifierList):
return token.get_identifiers()
elif imt(token, i=(Function, Identifier), t=T.Literal):
return [token, ]
return []
elif imt(token, i=(Function, Identifier, TypedLiteral), t=T.Literal):
result.append(token)
return result


class Begin(TokenList):
Expand Down
5 changes: 5 additions & 0 deletions tests/test_parse.py
Original file line number Diff line number Diff line change
Expand Up @@ -133,6 +133,11 @@ def test_parse_nested_function():
assert type(t[0]) is sql.Function


def test_parse_casted_params():
t = sqlparse.parse("foo(DATE '2023-11-14', TIMESTAMP '2023-11-15')")[0].tokens[0].get_parameters()
assert len(t) == 2


def test_parse_div_operator():
p = sqlparse.parse('col1 DIV 5 AS div_col1')[0].tokens
assert p[0].tokens[0].tokens[2].ttype is T.Operator
Expand Down

0 comments on commit dc2329d

Please sign in to comment.