Skip to content

Commit

Permalink
fix fucntions.Function not passing down kwargs during sql generation …
Browse files Browse the repository at this point in the history
…of function
  • Loading branch information
larsschwegmann committed Oct 2, 2024
1 parent 2054a6a commit 8411ee6
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 2 deletions.
2 changes: 1 addition & 1 deletion pypika/terms.py
Original file line number Diff line number Diff line change
Expand Up @@ -1429,7 +1429,7 @@ def get_sql(self, **kwargs: Any) -> str:

# FIXME escape
function_sql = self.get_function_sql(
with_namespace=with_namespace, quote_char=quote_char, dialect=dialect
with_namespace=with_namespace, quote_char=quote_char, dialect=dialect, **kwargs
)

if self.schema is not None:
Expand Down
18 changes: 17 additions & 1 deletion tests/test_parameter.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,8 @@
Query,
Tables,
)
from pypika.terms import ListParameter, ParameterValueWrapper
from pypika.functions import Upper
from pypika.terms import ListParameter, ParameterValueWrapper, ValueWrapper


class ParametrizedTests(unittest.TestCase):
Expand Down Expand Up @@ -212,3 +213,18 @@ def test_pyformat_parameter(self):
'INSERT INTO "abc" ("a","b","c") VALUES (%(param1)s,%(param2)s,%(param3)s)', sql
)
self.assertEqual({"param1": 1, "param2": 2.2, "param3": "foo"}, parameter.get_parameters())

def test_function_parameter(self):
q = (
Query
.from_(self.table_abc)
.select("*")
.where(self.table_abc.category == Upper(ValueWrapper("foobar")))
)
p = ListParameter("%s")
sql = q.get_sql(parameter=p)
self.assertEqual(
'SELECT * FROM "abc" WHERE "category"=UPPER(%s)', sql
)

self.assertEqual(["foobar"], p.get_parameters())

0 comments on commit 8411ee6

Please sign in to comment.