File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -4,7 +4,7 @@ build-backend = "hatchling.build"
44
55[project ]
66name = " t-sql"
7- version = " 4.7.0 "
7+ version = " 4.7.1 "
88description = " Safe SQL. SQL queries for python t-strings (PEP 750)"
99readme = " README.md"
1010requires-python = " >=3.14"
Original file line number Diff line number Diff line change @@ -311,7 +311,8 @@ def test_case_expression_with_subqueries():
311311
312312 sql , params = tsql .render (query , style = styles .QMARK )
313313
314- assert "CASE WHEN (SELECT COUNT(*)" in sql
314+ assert "CASE" in sql
315+ assert "WHEN (SELECT COUNT(*)" in sql
315316 assert "> ?" in sql
316317 assert "THEN 'active'" in sql
317318 assert params == [10 ]
Original file line number Diff line number Diff line change @@ -35,15 +35,26 @@ def test_merges_literals_using_exsiting_tstring():
3535 assert result ._sql == 'hello there'
3636
3737
38- def test_strips_literal_whitespace ():
39- result = tsql .render (t "SELECT \n * \n FROM table" )
38+ def test_strips_horizontal_whitespace ():
39+ # Horizontal whitespace (spaces/tabs) is collapsed, but newlines are preserved
40+ result = tsql .render (t "SELECT * FROM table" )
4041 assert result [0 ] == 'SELECT * FROM table'
4142
4243
44+ def test_preserves_newlines_for_sql_comments ():
45+ # Newlines must be preserved so -- style SQL comments work correctly
46+ query = t """SELECT * FROM users
47+ -- Filter by active status
48+ WHERE active = true"""
49+ result = tsql .render (query )
50+ assert '-- Filter by active status\n ' in result [0 ]
51+ assert 'WHERE active = true' in result [0 ]
52+
53+
4354def test_doesnt_strip_whitespace_in_values ():
4455 user_input = 'Some string\n With whitespace. With Formating that is \n just right'
45- result = tsql .render (t 'INSERT \n INTO table (vals) VALUES({user_input})' )
46- assert result [0 ] == f 'INSERT INTO table (vals) VALUES(?)'
56+ result = tsql .render (t 'INSERT INTO table (vals) VALUES({user_input})' )
57+ assert result [0 ] == 'INSERT INTO table (vals) VALUES(?)'
4758 assert result [1 ] == [user_input ]
4859
4960
Original file line number Diff line number Diff line change 99
1010logger = logging .getLogger (__name__ )
1111
12- # Pre-compile regex for whitespace collapsing to avoid cache lookup overhead
13- _WHITESPACE_RE = re .compile (r'\s+' )
12+ # Pre-compile regex for horizontal whitespace collapsing (spaces/tabs only)
13+ # Preserves newlines so that -- style SQL comments work correctly
14+ _WHITESPACE_RE = re .compile (r'[ \t]+' )
1415
1516if TYPE_CHECKING :
1617 from tsql .query_builder import QueryBuilder
You can’t perform that action at this time.
0 commit comments