SQLite's CAST to INTEGER never returns NULL - it returns 0 for
invalid strings. This meant the malformed ID detection query was
completely broken and never found any malformed IDs.
The Problem:
- Query used: CAST(suffix AS INTEGER) IS NULL
- SQLite behavior: CAST('abc' AS INTEGER) = 0 (not NULL!)
- Result: Malformed IDs were never detected
The Fix:
- Check if CAST returns 0 AND suffix doesn't start with '0'
- This catches non-numeric suffixes like 'abc', 'foo123'
- Avoids false positives on legitimate IDs like 'test-0', 'test-007'
Changes:
- internal/storage/sqlite/sqlite.go:126-131
* Updated malformed ID query logic
* Check: CAST = 0 AND first char != '0'
* Added third parameter for prefix (used 3 times now)
Testing:
- Created test DB with test-abc, test-1, test-foo123
- Warning correctly shows: [test-abc test-foo123] ✓
- Added test-0, test-007 (zero-prefixed IDs)
- No false positives ✓
- All existing tests pass ✓
Impact:
- Malformed IDs are now properly detected and warned about
- Helps maintain data quality
- Prevents confusion when auto-incrementing IDs
Closes bd-54
🤖 Generated with [Claude Code](https://claude.com/claude-code)
Co-Authored-By: Claude <noreply@anthropic.com>