Skip to content

Commit 243eb5b

Browse files
Merge pull request #5 from puzzleYOU/nesting-correction-station
Do not treat parentheses as special characters when parsing inner query
2 parents 453cb42 + 2ce8648 commit 243eb5b

5 files changed

Lines changed: 14 additions & 7 deletions

File tree

.github/workflows/python-publish.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ name: publish to PyPI
22

33
on:
44
release:
5-
types: [published]
5+
types: ["published", "created", "released"]
66

77
jobs:
88
deploy:

pyproject.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[project]
22
name = "sqlquerypp"
3-
version = "0.1.0a5"
3+
version = "0.1.0a6"
44
description = "SQL query preprocessor for generating optimized queries"
55
readme = "README.md"
66
repository = "https://github.com/puzzleYOU/sqlquerypp"

python/tests/expected_queries/mysql84/test_combined_result/test_with_multiple_parameters_and_union_fragments.sql

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515
b.col_b2
1616
FROM
1717
table_a AS a
18-
LEFT JOIN table_b AS b ON b.col_a1 = a.col_a1 AND b.cond1 = %s AND b.cond2 = %s
18+
LEFT JOIN table_b AS b ON b.col_a1 = a.col_a1 AND b.cond1 = %s AND b.cond2 = %s AND b.rangecond IN ('a', 'b')
1919
WHERE
2020
a.col_a1 = (SELECT * FROM loop_values LIMIT 1)
2121
UNION ALL
@@ -28,7 +28,7 @@
2828
FROM
2929
all_entries
3030
LEFT JOIN table_a AS a ON a.col_a1 = (SELECT col_a1 FROM loop_values WHERE col_a1 > all_entries.col_a1 LIMIT 1)
31-
LEFT JOIN table_b AS b ON b.col_a1 = a.col_a1 AND b.cond1 = %s AND b.cond2 = %s
31+
LEFT JOIN table_b AS b ON b.col_a1 = a.col_a1 AND b.cond1 = %s AND b.cond2 = %s AND b.rangecond IN ('a', 'b')
3232
WHERE
3333
n + 1 < (SELECT COUNT(*) FROM loop_values)
3434
)
@@ -59,7 +59,7 @@ UNION ALL
5959
b.col_b2
6060
FROM
6161
table_a AS a
62-
LEFT JOIN table_b AS b ON b.col_a1 = a.col_a1 AND b.cond3 = %s AND b.cond4 = %s
62+
LEFT JOIN table_b AS b ON b.col_a1 = a.col_a1 AND b.cond3 = %s AND b.cond4 = %s AND b.rangecond IN ('a', 'b')
6363
WHERE
6464
a.col_a1 = (SELECT * FROM loop_values LIMIT 1)
6565
UNION ALL
@@ -72,7 +72,7 @@ UNION ALL
7272
FROM
7373
all_entries
7474
LEFT JOIN table_a AS a ON a.col_a1 = (SELECT col_a1 FROM loop_values WHERE col_a1 > all_entries.col_a1 LIMIT 1)
75-
LEFT JOIN table_b AS b ON b.col_a1 = a.col_a1 AND b.cond3 = %s AND b.cond4 = %s
75+
LEFT JOIN table_b AS b ON b.col_a1 = a.col_a1 AND b.cond3 = %s AND b.cond4 = %s AND b.rangecond IN ('a', 'b')
7676
WHERE
7777
n + 1 < (SELECT COUNT(*) FROM loop_values)
7878
)

python/tests/mysql84/test_combined_result.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ def test_with_multiple_parameters_and_union_fragments(self) -> None:
1818
ON b.col_a1 = a.col_a1
1919
AND b.cond1 = %s
2020
AND b.cond2 = %s
21+
AND b.rangecond IN ('a', 'b')
2122
WHERE a.col_a1 = $id
2223
}
2324
UNION ALL
@@ -29,6 +30,7 @@ def test_with_multiple_parameters_and_union_fragments(self) -> None:
2930
ON b.col_a1 = a.col_a1
3031
AND b.cond3 = %s
3132
AND b.cond4 = %s
33+
AND b.rangecond IN ('a', 'b')
3234
WHERE a.col_a1 = $id
3335
}
3436
""",

src/parser/state.rs

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ pub struct ParserState<'t> {
2020
statement: &'t String,
2121
seen_token_state: Option<TokenState>,
2222
combined_result_nodes_state: NodesState<CombinedResultNode>,
23+
visiting_inner_query: bool,
2324
offset: usize,
2425
}
2526

@@ -34,6 +35,7 @@ impl<'t> ParserState<'t> {
3435
Self { statement,
3536
seen_token_state: None,
3637
combined_result_nodes_state: NodesState::new(),
38+
visiting_inner_query: false,
3739
offset: 0 }
3840
}
3941

@@ -180,7 +182,8 @@ impl<'t> ParserState<'t> {
180182
},
181183

182184
(_, TokenState::OpeningParenthese(offset))
183-
if handles_combined_result_node =>
185+
if handles_combined_result_node
186+
&& !self.visiting_inner_query =>
184187
{
185188
self.attach_iteration_query(*offset + 1)?
186189
},
@@ -194,12 +197,14 @@ impl<'t> ParserState<'t> {
194197
(_, TokenState::OpeningBrace(offset))
195198
if handles_combined_result_node =>
196199
{
200+
self.visiting_inner_query = true;
197201
self.mark_inner_query_begin(*offset)?
198202
},
199203

200204
(_, TokenState::ClosingBrace(offset))
201205
if handles_combined_result_node =>
202206
{
207+
self.visiting_inner_query = false;
203208
self.finalize_combined_result_node(offset)
204209
},
205210

0 commit comments

Comments
 (0)