Skip to content

Commit

Permalink
Merge branch 'knex:master' into master
Browse files Browse the repository at this point in the history
  • Loading branch information
YoutacRandS-VA committed Sep 24, 2024
2 parents 8f9467b + 176151d commit 77ffe25
Show file tree
Hide file tree
Showing 4 changed files with 42 additions and 2 deletions.
1 change: 1 addition & 0 deletions lib/dialects/oracle/utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,7 @@ function isConnectionError(err) {
'ORA-56600', // an illegal OCI function call was issued
'NJS-024',
'NJS-003',
'NJS-500',
].some(function (prefix) {
return err.message.indexOf(prefix) === 0;
});
Expand Down
7 changes: 7 additions & 0 deletions lib/dialects/sqlite3/query/sqlite-querycompiler.js
Original file line number Diff line number Diff line change
Expand Up @@ -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(
statement,
'like '
)}${this._valueClause(statement)}`;
}
}

module.exports = QueryCompiler_SQLite3;
24 changes: 22 additions & 2 deletions test/integration2/query/select/where.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -556,7 +556,14 @@ describe('Where', function () {

describe('where like', async function () {
beforeEach(function () {
if (!(isPostgreSQL(knex) || isMssql(knex) || isMysql(knex))) {
if (
!(
isPostgreSQL(knex) ||
isSQLite(knex) ||
isMssql(knex) ||
isMysql(knex)
)
) {
return this.skip();
}
});
Expand Down Expand Up @@ -630,10 +637,23 @@ describe('Where', function () {
expect(result[7].email).to.equal('test8@example.com');
});

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

it('supports only case-insensitive searches in sqlite', async function () {
const result = await knex('accounts').whereILike('email', 'Test1%');
if (!isSQLite(knex)) {
this.skip();
}
expect(result.length).to.equal(1);
expect(result[0].email).to.equal('test1@example.com');
});
});

it('Retains array bindings, #228', function () {
Expand Down
12 changes: 12 additions & 0 deletions test/unit/query/builder.js
Original file line number Diff line number Diff line change
Expand Up @@ -879,6 +879,10 @@ describe('QueryBuilder', () => {
sql: 'select * from [users] where [name] collate SQL_Latin1_General_CP1_CI_AS like ?',
bindings: ['luk%'],
},
sqlite3: {
sql: 'select * from `users` where `name` like ?',
bindings: ['luk%'],
},
});
});

Expand All @@ -903,6 +907,10 @@ describe('QueryBuilder', () => {
sql: 'select * from [users] where [name] collate SQL_Latin1_General_CP1_CS_AS like ? and [name] collate SQL_Latin1_General_CP1_CS_AS like ? or [name] collate SQL_Latin1_General_CP1_CS_AS like ?',
bindings: ['luk1%', 'luk2%', 'luk3%'],
},
sqlite3: {
sql: 'select * from `users` where `name` like ? and `name` like ? or `name` like ?',
bindings: ['luk1%', 'luk2%', 'luk3%'],
},
}
);
});
Expand All @@ -928,6 +936,10 @@ describe('QueryBuilder', () => {
sql: 'select * from [users] where [name] collate SQL_Latin1_General_CP1_CI_AS like ? and [name] collate SQL_Latin1_General_CP1_CI_AS like ? or [name] collate SQL_Latin1_General_CP1_CI_AS like ?',
bindings: ['luk1%', 'luk2%', 'luk3%'],
},
sqlite3: {
sql: 'select * from `users` where `name` like ? and `name` like ? or `name` like ?',
bindings: ['luk1%', 'luk2%', 'luk3%'],
},
}
);
});
Expand Down

0 comments on commit 77ffe25

Please sign in to comment.