Commit e09df83
authored
fix: encode empty Uint8Array as NULL for BYTEA parameters (#146)
* fix: encode empty Uint8Array as NULL for BYTEA parameters
Problem:
When calling view actions with optional BYTEA parameters, there was no
way to pass SQL NULL from JavaScript. Passing JavaScript `null` resulted
in VarType.NULL (generic null), which didn't work correctly with SQL
`IS NULL` checks for BYTEA columns.
Root Cause:
In kwilEncoding.ts, empty Uint8Array(0) was always encoded as "not null
empty bytea" using encodeNotNull(), which produces '\x' in PostgreSQL.
This is semantically different from NULL and causes SQL `IS NULL` checks
to fail.
Solution:
Treat empty Uint8Array(0) as BYTEA NULL by encoding it with encodeNull()
instead of encodeNotNull(). This provides a JavaScript-idiomatic way to
represent BYTEA NULL while maintaining backward compatibility.
Changes:
- src/utils/kwilEncoding.ts (encodeValue function):
* Add length check for Uint8Array before encoding
* Empty Uint8Array (length === 0) → encodeNull()
* Non-empty Uint8Array (length > 0) → encodeNotNull(value)
resolves: #145
* chore: apply suggestion
* chore: apply suggestion
* chore: bump version1 parent 7484110 commit e09df83
2 files changed
+14
-3
lines changed| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
1 | 1 | | |
2 | 2 | | |
3 | | - | |
| 3 | + | |
4 | 4 | | |
5 | 5 | | |
6 | 6 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
220 | 220 | | |
221 | 221 | | |
222 | 222 | | |
| 223 | + | |
| 224 | + | |
| 225 | + | |
| 226 | + | |
| 227 | + | |
223 | 228 | | |
224 | 229 | | |
225 | 230 | | |
| |||
263 | 268 | | |
264 | 269 | | |
265 | 270 | | |
266 | | - | |
267 | | - | |
| 271 | + | |
| 272 | + | |
| 273 | + | |
| 274 | + | |
| 275 | + | |
| 276 | + | |
| 277 | + | |
| 278 | + | |
268 | 279 | | |
269 | 280 | | |
270 | 281 | | |
| |||
0 commit comments