Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix whereILike issue with sqlite (#5604) #5687

Merged

Conversation

mohammedbalila
Copy link
Contributor

@mohammedbalila mohammedbalila marked this pull request as ready for review September 13, 2023 19:38
@kibertoad
Copy link
Collaborator

@mustafabalila I'm happy to help with tests, what can I do?

@mohammedbalila
Copy link
Contributor Author

Hello @kibertoad, I found that the unit tests for QueryBuilder do not include sqlite3 for in all iLike queries because sqlite3 does not support iLike, I updated the underlying query builder for sqlite to use a normal like query when calling iLike related methods, I added tests but there are failing test cases even on master, should I keep it this way or there are changes to be made?

Also do you think changing any iLike query to like is okay for sqlite? this will lead to unexpected behavior but I thought removing the functions from sqlite3 might break some of the existing dependent code

@kibertoad
Copy link
Collaborator

@mustafabalila Using "LIKE" should be fine, SQLite LIKE is case-insensitive unless compiled with custom flags. Let me take a look which tests fail in CI now

@@ -632,7 +639,12 @@ describe('Where', function () {

it("doesn't find data using whereLike when different case sensitivity", async () => {
const result = await knex('accounts').whereLike('email', 'Test1%');
expect(result).to.deep.equal([]);
if (isSQLite(knex)) {
Copy link
Collaborator

Choose a reason for hiding this comment

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

please add comment that sqlite only supports case-insensitive search

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Done

@coveralls
Copy link

coveralls commented Dec 2, 2023

Coverage Status

coverage: 92.843% (+0.001%) from 92.842%
when pulling b58d757 on mohammedbalila:fixing-whereILike-in-sqlite-issue-5604
into aedba5e on knex:master.

@@ -329,6 +329,13 @@ class QueryCompiler_SQLite3 extends QueryCompiler {
onJsonPathEquals(clause) {
return this._onJsonPathEquals('json_extract', clause);
}

whereILike(statement) {
return `${this._columnClause(statement)} ${this._not(
Copy link
Collaborator

Choose a reason for hiding this comment

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

can you add test for the not branch too?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I'm a bit confused, if I understood correctly the _not should add a not to the sql statement
to use it with an ilike query with sqlite or any other dialect it has to look like

knex('table').whereNot('col', 'ilike', 'test_string').select();

Since there's no a whereNotILike function, what the test should be?

Copy link
Collaborator

@kibertoad kibertoad Dec 2, 2023

Choose a reason for hiding this comment

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

Is it possible to set that "not" flag currently at all?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

For this query? no I kept it in case there will be a support for functions like whereNotILike

@mohammedbalila
Copy link
Contributor Author

Hey @kibertoad 
Is this PR and PR-5761 still relevant?

If the work on these two PRs is okay but the merge is delayed for any reason, I think I can pick something else, but if you think they need more work, please let me know

@kibertoad
Copy link
Collaborator

@rluvaton Could you please take a look?

@rluvaton
Copy link
Member

rluvaton commented Apr 2, 2024

Yes, will look at it in few hours, not near a computer

@@ -632,7 +639,13 @@ describe('Where', function () {

it("doesn't find data using whereLike when different case sensitivity", async () => {
const result = await knex('accounts').whereLike('email', 'Test1%');
expect(result).to.deep.equal([]);
// sqlite only supports case-insensitive search
if (isSQLite(knex)) {
Copy link
Member

Choose a reason for hiding this comment

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

I would split this into 2 tests, as the test name no longer represents the test behavior when in SQLite

Copy link
Contributor Author

Choose a reason for hiding this comment

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

It's done @rluvaton

@rluvaton
Copy link
Member

rluvaton commented Apr 4, 2024

if I'm not responding, ping me on twitter, I have a lot of GitHub notification

@mohammedbalila
Copy link
Contributor Author

if I'm not responding, ping me on twitter, I have a lot of GitHub notification

DM is closed

@rluvaton
Copy link
Member

rluvaton commented Apr 6, 2024

if I'm not responding, ping me on twitter, I have a lot of GitHub notification

DM is closed

Fixed

Copy link
Member

@rluvaton rluvaton left a comment

Choose a reason for hiding this comment

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

Thank you for the PR, sorry for the long review time

@mohammedbalila
Copy link
Contributor Author

Thanks @rluvaton
No worries, hopefully we'll meet in another PR

@rluvaton rluvaton merged commit 9659a20 into knex:master Apr 7, 2024
35 of 36 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants