Skip to content

fix(db): guard every SQLite identifier quoting form in the ILIKE rewrite - #544

Merged
emoss08 merged 1 commit into
masterfrom
claude/trenova-sqlite-support-4oc8h8
Aug 12, 2026
Merged

fix(db): guard every SQLite identifier quoting form in the ILIKE rewrite#544
emoss08 merged 1 commit into
masterfrom
claude/trenova-sqlite-support-4oc8h8

Conversation

@emoss08

@emoss08 emoss08 commented Aug 12, 2026

Copy link
Copy Markdown
Owner

Description

Follow-up to #543, which merged before its review came back.

The ILIKE rewrite only tracked ' and " when deciding what to skip. SQLite also
accepts backtick and bracket quoted identifiers, so `ILIKE` and [ILIKE] were
being rewritten inside their quotes. It also treated $ as a word boundary, which
split identifiers like foo$ilike and rewrote the tail.

Neither shows up in what Bun's sqlitedialect emits — it quotes with " — so nothing
is broken today. It's a raw query away from mattering, and both are cheap to close.

Two smaller things came along with it:

  • The strings.ToLower in the pre-check copied every statement before every prepare,
    including the ones with no ILIKE in them. Replaced with a byte scan, so the common
    path no longer allocates.
  • The comment explaining that rewriteConn implements only the prepare path is now
    TestRewriteConnHasNoFastPath. database/sql skips Prepare when a conn advertises
    QueryerContext or ExecerContext, so adding either would quietly route statements
    around the rewrite. A comment wasn't going to stop that; a failing test will. The rest
    of the comments in the file are gone, per CLAUDE.md.

Related Issue or Discussion

Follows #543. Part of the SQLite development-database work.

Type of Change

  • Bug fix
  • Feature
  • Documentation
  • Refactor
  • Tests
  • Build, CI, or infrastructure

Scope

  • services/tms/internal/infrastructure/postgres/sqlitedriver.go
  • services/tms/internal/infrastructure/postgres/sqlitedriver_test.go

Postgres is untouched — this file only runs when the driver is SQLite.

Validation

  • go build ./... — clean
  • go vet ./internal/infrastructure/postgres/ — clean
  • go test ./internal/infrastructure/postgres/ -run 'TestRewriteILike|TestSQLiteDriver|TestRewriteConn' -v — 14/14 pass
  • Other: formatted with golangci/golines@v0.15.0 --max-len=100 --tab-len=4

Four new tests: backtick identifiers, bracket identifiers, $ in identifiers, and the
no-fast-path guard.

Deployment Notes

None. Development-only code path, no migrations, no config changes.

Checklist

  • I kept the change focused and reviewable.
  • I followed AGENTS.md, CLAUDE.md, and existing repository patterns.
  • I added or updated tests for behavior changes, or explained why tests are not applicable.
  • I updated relevant documentation, examples, migrations, or configuration.
  • I did not include secrets, credentials, private customer data, unrelated refactors, or placeholder code.

Generated by Claude Code

The rewrite only knew about single and double quotes, so it happily
mangled `ILIKE` and [ILIKE] — SQLite accepts both as quoted identifiers.
It also treated $ as a word boundary, which split identifiers like
foo$ilike.

Track the backtick and bracket forms, count $ as part of an identifier,
and drop the ToLower copy in the pre-check so statements without the
operator no longer allocate on their way to the driver.

The comment about the connection only implementing Prepare is now a test
instead, since a comment would not have stopped anyone from adding a
QueryerContext fast path that skips the rewrite.

Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01FXYnxBszfwkNUeeAcVSSNf
@cloudflare-workers-and-pages

Copy link
Copy Markdown
Contributor

Deploying with  Cloudflare Workers  Cloudflare Workers

The latest updates on your project. Learn more about integrating Git with Workers.

Status Name Latest Commit Updated (UTC)
❌ Deployment failed
View logs
trenova 577d271 Aug 12 2026, 06:28 PM

@coderabbitai

coderabbitai Bot commented Aug 12, 2026

Copy link
Copy Markdown
Contributor

Warning

Review limit reached

@emoss08, you've reached your PR review limit, so we couldn't start this review.

Next review available in: 18 minutes

You've used all free OSS reviews for now. Wait for the free limit to reset to keep reviewing this public repository.

How can I continue?

After more reviews become available, a review can be triggered using the @coderabbitai review command as a PR comment. Alternatively, push new commits to this PR.

To avoid repeated limits, reduce automatic review volume by pausing incremental auto-reviews earlier, using label-based review opt-in, excluding WIP or generated PR titles, or requesting reviews manually when the PR is ready. If your team needs uninterrupted high-volume reviews, an organization admin can enable usage-based reviews.

How do review limits work?

CodeRabbit enforces per-developer PR review limits for each organization. Most developers receive the normal plan review availability.

For paid Pro and Pro+ PR reviews, CodeRabbit uses adaptive limits for sustained high-volume activity. When a developer's recent PR review activity reaches the 95th percentile or higher among CodeRabbit users, additional reviews become available more gradually as earlier reviews age out of the rolling window.

Please refer docs for additional details.

Review details
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro Plus

Run ID: 7eab451c-365d-4200-a5d3-0b7853c220e4

📥 Commits

Reviewing files that changed from the base of the PR and between 20a6729 and 577d271.

📒 Files selected for processing (2)
  • services/tms/internal/infrastructure/postgres/sqlitedriver.go
  • services/tms/internal/infrastructure/postgres/sqlitedriver_test.go

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

@emoss08
emoss08 merged commit 8cf20cb into master Aug 12, 2026
19 of 20 checks passed
@emoss08
emoss08 deleted the claude/trenova-sqlite-support-4oc8h8 branch August 12, 2026 19:03
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants