Commit 5367e09
committed
fix(sql): reject procedural division/modulo by zero (#227)
The procedural executor's constant-expression evaluator — a separate,
sqlparser-based tree-walk evaluator used by trigger bodies and
EXCEPTION blocks, with no dependency on the DataFusion-backed
row-expression evaluator — still folded `/` and `%` by a zero divisor
to NULL instead of raising an error. A trigger computing
`NEW.ratio := NEW.numerator / NEW.denominator` would silently write
NULL when the denominator was zero instead of failing the insert.
try_eval_constant, eval_expr, and eval_binary_op now return
Result<Option<Value>, ConstEvalError> instead of Option<Value>, and
raise a division-by-zero signal only when a `/` or `%` reaches a zero
divisor; every other historically-NULL-folding case (unknown
identifiers, unsupported operators, overflow, non-finite float
results) keeps folding to None as before. The signal converts to a
new crate::Error::DivisionByZero variant, which pgwire renders as
SQLSTATE 22012 (division_by_zero), so trigger bodies can also match
it with EXCEPTION WHEN DIVISION_BY_ZERO.
Add the supporting DivisionByZero plumbing at the nodedb-types layer
(ErrorCode, ErrorDetails, msgpack wire tag, SQLSTATE constant,
NodeDbError constructor) and e2e coverage: a BEFORE INSERT trigger
dividing by zero rejects the insert without persisting the row, a
non-zero divisor still computes and persists normally, and an
EXCEPTION WHEN DIVISION_BY_ZERO handler catches the signal and lets
the insert proceed with its fallback assignment.1 parent a2fdf9e commit 5367e09
13 files changed
Lines changed: 324 additions & 53 deletions
File tree
- nodedb-types/src/error
- ctors
- msgpack
- decode
- nodedb
- src
- control
- planner/procedural/executor
- server/pgwire/types
- tests
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
43 | 43 | | |
44 | 44 | | |
45 | 45 | | |
| 46 | + | |
| 47 | + | |
46 | 48 | | |
47 | 49 | | |
48 | 50 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
120 | 120 | | |
121 | 121 | | |
122 | 122 | | |
| 123 | + | |
| 124 | + | |
| 125 | + | |
| 126 | + | |
| 127 | + | |
| 128 | + | |
| 129 | + | |
| 130 | + | |
| 131 | + | |
| 132 | + | |
| 133 | + | |
| 134 | + | |
| 135 | + | |
123 | 136 | | |
124 | 137 | | |
125 | 138 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
80 | 80 | | |
81 | 81 | | |
82 | 82 | | |
| 83 | + | |
| 84 | + | |
| 85 | + | |
83 | 86 | | |
84 | 87 | | |
85 | 88 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
69 | 69 | | |
70 | 70 | | |
71 | 71 | | |
| 72 | + | |
72 | 73 | | |
73 | 74 | | |
74 | 75 | | |
| |||
136 | 137 | | |
137 | 138 | | |
138 | 139 | | |
| 140 | + | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
123 | 123 | | |
124 | 124 | | |
125 | 125 | | |
| 126 | + | |
| 127 | + | |
| 128 | + | |
| 129 | + | |
126 | 130 | | |
127 | 131 | | |
128 | 132 | | |
| |||
346 | 350 | | |
347 | 351 | | |
348 | 352 | | |
| 353 | + | |
349 | 354 | | |
350 | 355 | | |
351 | 356 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
153 | 153 | | |
154 | 154 | | |
155 | 155 | | |
| 156 | + | |
156 | 157 | | |
157 | 158 | | |
158 | 159 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
40 | 40 | | |
41 | 41 | | |
42 | 42 | | |
| 43 | + | |
| 44 | + | |
| 45 | + | |
| 46 | + | |
43 | 47 | | |
44 | 48 | | |
45 | 49 | | |
| |||
237 | 241 | | |
238 | 242 | | |
239 | 243 | | |
| 244 | + | |
240 | 245 | | |
241 | 246 | | |
242 | 247 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
98 | 98 | | |
99 | 99 | | |
100 | 100 | | |
| 101 | + | |
101 | 102 | | |
102 | 103 | | |
103 | 104 | | |
| |||
0 commit comments