Return -1 from SQLite String.IndexOf(value, startIndex) when the valu… - #38729
Open
ilkertskn wants to merge 1 commit into
Open
Return -1 from SQLite String.IndexOf(value, startIndex) when the valu…#38729ilkertskn wants to merge 1 commit into
ilkertskn wants to merge 1 commit into
Conversation
…e is not found - The translation computed (instr(substr(...)) - 1) + startIndex, which yields startIndex - 1 instead of -1 when instr returns 0 (the value is not found), so IndexOf produced a wrong non-negative result - Wrap the result in a CASE that returns -1 when instr is 0, matching String.IndexOf - Add a test for the not-found case and update the affected SQL baselines
Contributor
Author
|
@dotnet-policy-service agree |
There was a problem hiding this comment.
Pull request overview
Fixes SQLite translation of string.IndexOf(value, startIndex) so that it correctly returns -1 when the searched value isn’t found (SQLite instr() returns 0, which previously caused the expression to yield startIndex - 1).
Changes:
- Update SQLite
IndexOf(..., startIndex)translation to wrapinstr(substr(...))in aCASEreturning-1wheninstr()returns0. - Update existing SQL baselines for
IndexOfstarting-position tests to reflect the newCASEtranslation. - Add a new functional test covering the “not found => -1” case for
IndexOfwith a starting position.
Reviewed changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated no comments.
| File | Description |
|---|---|
| test/EFCore.Sqlite.FunctionalTests/Query/Translations/StringTranslationsSqliteTest.cs | Updates SQL baselines for starting-position IndexOf and adds a new test asserting -1 when not found. |
| src/EFCore.Sqlite.Core/Query/Internal/Translators/SqliteStringMethodTranslator.cs | Fixes the SQLite translation for IndexOf(value, startIndex) by guarding the instr() result with a CASE. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
…e is not found