Commit 3b9a984
refactor(merge_insert): adapt findPkFromBlob for Rust/C pks schema
PROBLEM: Sync operations failing because findPkFromBlob expected old schema
with `pks BLOB` column, but new schema stores PK columns directly.
OLD SCHEMA:
__crsql_pks(pk INTEGER, base_rowid INTEGER, pks BLOB)
Query: SELECT pk FROM pks WHERE pks = ?
NEW SCHEMA (Rust/C compatible):
__crsql_pks(__crsql_key INTEGER PRIMARY KEY, pk_col1, pk_col2, ...)
Query: SELECT __crsql_key FROM pks WHERE col1 = ? AND col2 = ?
CHANGES:
1. Import as_crr module for TableInfo access
2. Make getTableInfo() public in as_crr.zig
3. Completely rewrite findPkFromBlob():
- Load TableInfo to get PK column names and count
- Unpack pk_blob using codec.unpack()
- Build dynamic SQL with WHERE clause for each PK column
- Bind unpacked values (Integer, Float, Text, Blob, Null)
- Query for __crsql_key instead of pk
- Use api.getTransientDestructor() for text/blob binding
IMPACT: findPkFromBlob now correctly queries the new pks schema. Sync
operations will still fail until INSERT path is refactored (next step).
TESTING:
- Compiles successfully
- Returns NoRows for non-existent entries (expected behavior)
- Ready for INSERT path refactoring
PART OF: TASK-147 (Rust/C pks schema compatibility)
🤖 Generated with [Claude Code](https://claude.com/claude-code)
Co-Authored-By: Claude Sonnet 4.5 <[email protected]>1 parent 255e316 commit 3b9a984
2 files changed
+79
-7
lines changed| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
305 | 305 | | |
306 | 306 | | |
307 | 307 | | |
308 | | - | |
| 308 | + | |
309 | 309 | | |
310 | 310 | | |
311 | 311 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
21 | 21 | | |
22 | 22 | | |
23 | 23 | | |
| 24 | + | |
24 | 25 | | |
25 | 26 | | |
26 | 27 | | |
| |||
354 | 355 | | |
355 | 356 | | |
356 | 357 | | |
357 | | - | |
358 | | - | |
| 358 | + | |
| 359 | + | |
| 360 | + | |
| 361 | + | |
| 362 | + | |
| 363 | + | |
359 | 364 | | |
360 | 365 | | |
361 | 366 | | |
362 | 367 | | |
363 | 368 | | |
364 | 369 | | |
365 | | - | |
366 | | - | |
| 370 | + | |
| 371 | + | |
| 372 | + | |
| 373 | + | |
| 374 | + | |
| 375 | + | |
| 376 | + | |
| 377 | + | |
| 378 | + | |
| 379 | + | |
| 380 | + | |
| 381 | + | |
| 382 | + | |
| 383 | + | |
| 384 | + | |
| 385 | + | |
| 386 | + | |
| 387 | + | |
| 388 | + | |
| 389 | + | |
| 390 | + | |
| 391 | + | |
| 392 | + | |
| 393 | + | |
| 394 | + | |
| 395 | + | |
| 396 | + | |
| 397 | + | |
| 398 | + | |
| 399 | + | |
| 400 | + | |
| 401 | + | |
| 402 | + | |
| 403 | + | |
| 404 | + | |
| 405 | + | |
| 406 | + | |
| 407 | + | |
| 408 | + | |
| 409 | + | |
| 410 | + | |
| 411 | + | |
| 412 | + | |
| 413 | + | |
| 414 | + | |
367 | 415 | | |
| 416 | + | |
| 417 | + | |
| 418 | + | |
| 419 | + | |
| 420 | + | |
| 421 | + | |
| 422 | + | |
| 423 | + | |
| 424 | + | |
| 425 | + | |
368 | 426 | | |
369 | | - | |
| 427 | + | |
370 | 428 | | |
371 | 429 | | |
372 | 430 | | |
373 | 431 | | |
374 | | - | |
| 432 | + | |
| 433 | + | |
| 434 | + | |
| 435 | + | |
| 436 | + | |
| 437 | + | |
| 438 | + | |
| 439 | + | |
| 440 | + | |
| 441 | + | |
| 442 | + | |
| 443 | + | |
| 444 | + | |
| 445 | + | |
375 | 446 | | |
| 447 | + | |
376 | 448 | | |
377 | 449 | | |
378 | 450 | | |
| |||
0 commit comments