Commit 255e316
fix(after_write): fix dangling pointer in getPkColumnName for compound PKs
PROBLEM: Compound PK inserts were failing with incomplete SQL generation.
Second PK column name was corrupted (null byte instead of actual name).
ROOT CAUSE: getPkColumnName was iterating by value, creating a local copy of
each ColumnInfo, then returning a slice into that local copy. After the
function returned, the copy was destroyed, leaving a dangling pointer.
FIX: Changed from iterating by value to iterating by index with pointer
dereference. This ensures the returned slice points into the actual
TableInfo.columns array, not a temporary copy.
BEFORE:
for (info.columns[0..info.count]) |col| { // Copy!
return col.name[0..col.name_len]; // Dangling!
}
AFTER:
for (0..info.count) |i| {
const col = &info.columns[i]; // Pointer to actual
return col.name[0..col.name_len]; // Safe!
}
IMPACT: Compound PK tables now work correctly for local writes via triggers.
TESTING:
CREATE TABLE foo(a INT NOT NULL, b INT NOT NULL, c TEXT, PRIMARY KEY(a,b));
SELECT crsql_as_crr('foo');
INSERT INTO foo VALUES(4,5,'hello'), (10,20,'world');
-- Both rows inserted successfully, pks table populated correctly
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 bba5977 commit 255e316
1 file changed
+4
-17
lines changed| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
50 | 50 | | |
51 | 51 | | |
52 | 52 | | |
53 | | - | |
| 53 | + | |
54 | 54 | | |
55 | 55 | | |
56 | 56 | | |
| |||
112 | 112 | | |
113 | 113 | | |
114 | 114 | | |
115 | | - | |
| 115 | + | |
| 116 | + | |
| 117 | + | |
116 | 118 | | |
117 | 119 | | |
118 | 120 | | |
| |||
221 | 223 | | |
222 | 224 | | |
223 | 225 | | |
224 | | - | |
225 | | - | |
226 | | - | |
227 | | - | |
228 | | - | |
229 | | - | |
230 | | - | |
231 | | - | |
232 | | - | |
233 | | - | |
234 | | - | |
235 | | - | |
236 | | - | |
237 | | - | |
238 | | - | |
239 | 226 | | |
240 | 227 | | |
241 | 228 | | |
| |||
0 commit comments