Skip to content

Commit 37d7ca1

Browse files
committed
Allow for None as a literal placeholder value
This is acceptable alongside boolean values as I don't think it is possible to SQL Inject with a literal `None` and is useful.
1 parent 09cc33f commit 37d7ca1

2 files changed

Lines changed: 9 additions & 0 deletions

File tree

src/sql_tstring/__init__.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -145,6 +145,8 @@ def _safely_convert_placeholder_value(
145145
if case_insensitive is None:
146146
case_insensitive = set()
147147

148+
if value is None:
149+
return "NULL"
148150
if isinstance(value, bool):
149151
return str(value)
150152
if allow_numeric and isinstance(value, Number):

tests/test_identifiers.py

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,13 @@ def test_numeric_invalid() -> None:
4545
sql("SELECT {a}", locals())
4646

4747

48+
def test_none() -> None:
49+
a = None
50+
query, values = sql("SELECT {a}", locals())
51+
assert query == "SELECT NULL"
52+
assert values == []
53+
54+
4855
def test_partition_by() -> None:
4956
a = RewritingValue.ABSENT
5057
b = "x"

0 commit comments

Comments
 (0)