Skip to content

fix(sqlite): declare the LIKE escape once - #1082

Merged
loks0n merged 1 commit into
mainfrom
fix/sqlite-like-escape-once
Nov 24, 2026
Merged

loks0n merged 1 commit into
mainfrom
fix/sqlite-like-escape-once

Conversation

@loks0n

@loks0n loks0n commented Nov 24, 2026 •

Copy link
Copy Markdown
Contributor

The SQLite builder appends ESCAPE '\' to every LIKE, because utopia-php/query declared none. A coming release of that package declares it itself (appwrite/appwrite#15328), and SQLite refuses the clause twice:

SQLSTATE[HY000]: General error: 1 near "ESCAPE": syntax error

That is what LIKE ? ESCAPE '\' ESCAPE '\' gives.

What changes

  • src/Database/Builder/SQLite.php: compileLike() adds the clause only when the statement the parent returns does not already end in it.

It works on both sides of the package release, so this can ship first and the package change can follow without a coordinated bump. Once utopia-php/query with the declared escape is the minimum version, the override and the ESCAPE constant can go.

Tests

The unit suite, on this change:

utopia-php/query before after
current (^0.7.2) 9 fail 9 fail
with appwrite/appwrite#15328 63 fail 9 fail

The nine need a database server and fail the same way on main. The 54 that this fixes are the SQLite tests that run a LIKE, SQLiteLikeEscapeTest among them; no new test is needed to cover it.

Context

appwrite/appwrite#15328 was merged and then taken back out of appwrite's main for this reason (appwrite/appwrite#15734). It re-lands once a release with this change is pinned there.

🤖 Generated with Claude Code

Summary by CodeRabbit

  • Bug Fixes
    • Fixed an issue where SQLite text matching could include a duplicate escape clause. Matching now handles escape characters consistently when the clause is already present, helping prevent unexpected search results.

The SQLite builder appends ESCAPE '\' to every LIKE, because
utopia-php/query declared none. A coming release of that package
declares it itself (appwrite/appwrite#15328), and SQLite refuses the
clause twice: LIKE ? ESCAPE '\' ESCAPE '\' is a syntax error.

The builder now adds the clause only when the statement does not end in
it already, so it works on both sides of that release.

Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
@loks0n loks0n self-assigned this Nov 24, 2026
@appwrite

appwrite Bot commented Nov 24, 2026 •

Copy link
Copy Markdown

Code review

Commit Status Tier Verdict Details
6ec5ddb Reviewed Reviewed 🟢 S · Ready to merge ✅ Approved View review

The suffix check retains the current SQLite behavior and avoids duplicate ESCAPE clauses when the parent builder provides one.

The SQLite builder continues to add an explicit backslash escape clause for LIKE predicates. It now avoids appending the clause when the parent builder already returns it, supporting both query-builder versions.

Walkthrough (1)
File Change
src/Database/Builder/SQLite.php Detects an existing trailing LIKE escape clause before adding one.

Reviewed 6ec5ddb

Tip

Comment @appwrite review to re-run, or mention @appwrite with a question.

@coderabbitai

coderabbitai Bot commented Nov 24, 2026 •

Copy link
Copy Markdown
Contributor

Explain Change →

No actionable comments were generated in the recent review.

Walkthrough

SQLite’s compileLike() now appends the ESCAPE clause only when the parent-generated clause does not already end with it.

Changes: SQLite LIKE Escape Handling

Layer / File(s) Summary
Avoid duplicate ESCAPE clauses
src/Database/Builder/SQLite.php
compileLike() returns the parent-generated clause unchanged when it already ends with ESCAPE. Otherwise, it appends ESCAPE.

Estimated code review effort: 2 (Simple) | ~5 minutes

Change: Bug fix

Suggested reviewers: abnegate

Merge Risk: Minimal · up to 6ec5d

The change prevents duplicate ESCAPE clauses in SQLite LIKE queries, so it works both with the current query package and with the upcoming release. No concrete merge-blocking risk was found.

Pre-merge checks: Passed 4

Check name Status Explanation
Description Check Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check Passed The title names the SQLite LIKE escape change, which matches the summary: compileLike() now appends the ESCAPE clause only when the parent clause lacks it. It is specific and scoped to the sqlite fix.…
Linked Issues check Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check Passed Check skipped because no linked issues were found for this pull request.
Full details: Title check

Explanation

The title names the SQLite LIKE escape change, which matches the summary: compileLike() now appends the ESCAPE clause only when the parent clause lacks it. It is specific and scoped to the sqlite fix. It does not mention the conditional behavior, but it is a real and primary part of the change.

Finishing Touches

Generate unit tests (beta)

  • Commit to this branch
  • Create a new PR
  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

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

Recent review info

Run configuration

Commits

Reviewing files that changed from the base of the PR and between 1571331 and 6ec5ddb.

Files selected for processing: 1

  • src/Database/Builder/SQLite.php

Included review availability: This review used your included allowance. Your plan provides up to 1 included review per hour; 0 remain after this review.

@appwrite appwrite Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟢 Tier S · Looks good to merge. Summary

@loks0n
loks0n merged commit 84bf247 into main Nov 24, 2026
22 checks passed
@loks0n
loks0n deleted the fix/sqlite-like-escape-once branch November 24, 2026 11:20
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.

1 participant