Skip to content

Commit 1d462a5

Browse files
committed
Try PRAGMA paren-strip again with simpler Rust form
Previous version may have had a subtle issue with &str lifetime in the clone-vs-use branches. Simpler form with explicit bytes iteration and guaranteed-owned String returns on both branches. Targets testCreateTableWithDefaultNowFunction and testCreateTableWithDefaultExpressions which assert that PRAGMA table_info returns DEFAULT expressions with outer parens stripped (matching real SQLite behavior).
1 parent a74dd39 commit 1d462a5

1 file changed

Lines changed: 42 additions & 0 deletions

File tree

.github/workflows/phpunit-tests-turso.yml

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -433,6 +433,48 @@ jobs:
433433
print('patched delete.rs to allow DELETE FROM sqlite_sequence')
434434
PY_DELETE_SEQ
435435
436+
# PRAGMA table_info serializes default-expr AST back to a string
437+
# and keeps any outer parens. Real SQLite strips one level of
438+
# balanced outer parens; match that.
439+
python3 - <<'PY_PRAGMA_DEFAULT'
440+
p = 'core/translate/pragma.rs'
441+
s = open(p).read()
442+
old = (
443+
" Some(expr) => {\n"
444+
" program.emit_string8(expr.to_string(), base_reg + 4);\n"
445+
" }\n"
446+
)
447+
new = (
448+
" Some(expr) => {\n"
449+
" let raw = expr.to_string();\n"
450+
" let bytes = raw.as_bytes();\n"
451+
" let len = bytes.len();\n"
452+
" let stripped: String = if len >= 2 && bytes[0] == b'(' && bytes[len - 1] == b')' {\n"
453+
" let mut depth: i32 = 0;\n"
454+
" let mut ok = true;\n"
455+
" for i in 1..len - 1 {\n"
456+
" if bytes[i] == b'(' { depth += 1; }\n"
457+
" else if bytes[i] == b')' {\n"
458+
" if depth == 0 { ok = false; break; }\n"
459+
" depth -= 1;\n"
460+
" }\n"
461+
" }\n"
462+
" if ok && depth == 0 {\n"
463+
" raw[1..len - 1].trim().to_string()\n"
464+
" } else {\n"
465+
" raw.clone()\n"
466+
" }\n"
467+
" } else {\n"
468+
" raw.clone()\n"
469+
" };\n"
470+
" program.emit_string8(stripped, base_reg + 4);\n"
471+
" }\n"
472+
)
473+
assert old in s, 'PRAGMA table_info default-emit block not found'
474+
open(p, 'w').write(s.replace(old, new, 1))
475+
print('patched PRAGMA table_info to strip outer parens from default')
476+
PY_PRAGMA_DEFAULT
477+
436478
echo '--- Patched stub! macro ---'
437479
sed -n '/macro_rules! stub/,/^}$/p' sqlite3/src/lib.rs
438480

0 commit comments

Comments
 (0)