Commit 37b2f72
committed
refactor: use AST pattern matching instead of string matching for statement detection
Fixes #159
The codebase was using starts_with() string checks to detect statement
types (SET, SHOW, INSERT, etc.) which is fragile - it can break with
leading whitespace, comments, or case variations.
Since we already have the parsed Statement AST from sqlparser, this
switches to using pattern matching directly on the Statement enum.
Changes in permissions.rs:
- Renamed check_query_permission to check_statement_permission, now
takes &Statement instead of &str
- Permission detection (SELECT/INSERT/UPDATE/DELETE/CREATE/DROP/ALTER)
now uses match on Statement variants
- Added should_skip_permission_check() helper using matches!() macro
for SET, SHOW, and transaction statements
- Removed all the to_lowercase().starts_with() chains
Changes in handlers.rs:
- INSERT detection now uses matches!(statement, Statement::Insert(_))
- Removed unnecessary query_lower variable construction
- Fixed extended query handler to properly destructure statement from
the portal tuple
All 12 unit tests pass. The existing integration test failures
(dbeaver, metabase, psql) are unrelated - they fail due to missing
DataFusion functions like array_length and array_contains.1 parent 2b51166 commit 37b2f72
2 files changed
+54
-60
lines changed| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
139 | 139 | | |
140 | 140 | | |
141 | 141 | | |
142 | | - | |
143 | 142 | | |
144 | | - | |
145 | 143 | | |
146 | 144 | | |
147 | 145 | | |
| |||
179 | 177 | | |
180 | 178 | | |
181 | 179 | | |
182 | | - | |
| 180 | + | |
183 | 181 | | |
184 | 182 | | |
185 | 183 | | |
| |||
265 | 263 | | |
266 | 264 | | |
267 | 265 | | |
268 | | - | |
269 | | - | |
270 | | - | |
271 | | - | |
272 | | - | |
273 | | - | |
274 | | - | |
| 266 | + | |
275 | 267 | | |
276 | 268 | | |
277 | 269 | | |
| |||
302 | 294 | | |
303 | 295 | | |
304 | 296 | | |
305 | | - | |
| 297 | + | |
306 | 298 | | |
307 | 299 | | |
308 | 300 | | |
| |||
345 | 337 | | |
346 | 338 | | |
347 | 339 | | |
348 | | - | |
| 340 | + | |
349 | 341 | | |
350 | 342 | | |
351 | 343 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
23 | 23 | | |
24 | 24 | | |
25 | 25 | | |
26 | | - | |
27 | | - | |
| 26 | + | |
| 27 | + | |
| 28 | + | |
| 29 | + | |
| 30 | + | |
| 31 | + | |
28 | 32 | | |
29 | 33 | | |
30 | 34 | | |
| |||
35 | 39 | | |
36 | 40 | | |
37 | 41 | | |
38 | | - | |
39 | | - | |
40 | | - | |
41 | | - | |
42 | | - | |
43 | | - | |
44 | | - | |
45 | | - | |
46 | | - | |
47 | | - | |
48 | | - | |
49 | | - | |
50 | | - | |
51 | | - | |
52 | | - | |
53 | | - | |
54 | | - | |
55 | | - | |
56 | | - | |
57 | | - | |
58 | | - | |
59 | | - | |
60 | | - | |
| 42 | + | |
| 43 | + | |
| 44 | + | |
| 45 | + | |
| 46 | + | |
| 47 | + | |
| 48 | + | |
| 49 | + | |
| 50 | + | |
| 51 | + | |
| 52 | + | |
| 53 | + | |
| 54 | + | |
61 | 55 | | |
62 | 56 | | |
63 | 57 | | |
| |||
78 | 72 | | |
79 | 73 | | |
80 | 74 | | |
| 75 | + | |
| 76 | + | |
| 77 | + | |
| 78 | + | |
| 79 | + | |
| 80 | + | |
| 81 | + | |
| 82 | + | |
| 83 | + | |
| 84 | + | |
| 85 | + | |
| 86 | + | |
| 87 | + | |
| 88 | + | |
| 89 | + | |
81 | 90 | | |
82 | 91 | | |
83 | 92 | | |
| |||
89 | 98 | | |
90 | 99 | | |
91 | 100 | | |
92 | | - | |
93 | | - | |
94 | | - | |
95 | | - | |
96 | | - | |
97 | | - | |
98 | | - | |
99 | | - | |
100 | | - | |
101 | | - | |
102 | | - | |
103 | | - | |
104 | | - | |
105 | | - | |
106 | | - | |
107 | | - | |
| 101 | + | |
| 102 | + | |
| 103 | + | |
| 104 | + | |
| 105 | + | |
| 106 | + | |
| 107 | + | |
| 108 | + | |
108 | 109 | | |
109 | 110 | | |
110 | 111 | | |
| |||
127 | 128 | | |
128 | 129 | | |
129 | 130 | | |
130 | | - | |
| 131 | + | |
| 132 | + | |
| 133 | + | |
| 134 | + | |
131 | 135 | | |
132 | | - | |
133 | | - | |
134 | | - | |
135 | | - | |
136 | | - | |
137 | | - | |
| 136 | + | |
| 137 | + | |
| 138 | + | |
138 | 139 | | |
| 140 | + | |
139 | 141 | | |
140 | 142 | | |
141 | 143 | | |
0 commit comments