Commit 0f69e19
authored
refactor: use AST pattern matching instead of string matching for sta… (#262)
* 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.
* test: add pgAdmin startup queries test for issue #178
Adds a test file to verify pgAdmin startup queries work correctly.
The test covers:
- SELECT version() query
- The CASE expression checking pg_extension for 'bdr' extension
and pg_replication_slots for replication slot count
Both pg_extension and pg_replication_slots tables are already
implemented in pg_catalog, so these queries now pass.
* refactor: avoid String allocation in extended query handler
Use reference instead of calling .to_string() on query string
as suggested by mjgarton - the query is only used for logging
and doesn't need to be owned.
* refactor: remove redundant comments in permissions hook
Remove comments that don't fully describe what's being skipped.
The function name should_skip_permission_check is self-documenting.
Suggested by mjgarton.1 parent 2b51166 commit 0f69e19
3 files changed
Lines changed: 84 additions & 60 deletions
| 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 | | |
| |||
127 | 127 | | |
128 | 128 | | |
129 | 129 | | |
130 | | - | |
| 130 | + | |
| 131 | + | |
| 132 | + | |
131 | 133 | | |
132 | | - | |
133 | | - | |
134 | | - | |
135 | | - | |
136 | | - | |
137 | | - | |
| 134 | + | |
| 135 | + | |
| 136 | + | |
138 | 137 | | |
| 138 | + | |
139 | 139 | | |
140 | 140 | | |
141 | 141 | | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
| 1 | + | |
| 2 | + | |
| 3 | + | |
| 4 | + | |
| 5 | + | |
| 6 | + | |
| 7 | + | |
| 8 | + | |
| 9 | + | |
| 10 | + | |
| 11 | + | |
| 12 | + | |
| 13 | + | |
| 14 | + | |
| 15 | + | |
| 16 | + | |
| 17 | + | |
| 18 | + | |
| 19 | + | |
| 20 | + | |
| 21 | + | |
| 22 | + | |
| 23 | + | |
| 24 | + | |
| 25 | + | |
| 26 | + | |
| 27 | + | |
| 28 | + | |
| 29 | + | |
| 30 | + | |
| 31 | + | |
| 32 | + | |
0 commit comments