From 26c8af3c1eb00e9606e9bdcf50b2fdada4d6168c Mon Sep 17 00:00:00 2001 From: Mel O'Hagan Date: Wed, 27 Jul 2022 16:40:07 +0100 Subject: [PATCH] SQL Server containsAny unit test --- packages/server/src/integrations/base/sql.ts | 6 ++++-- packages/server/src/integrations/tests/sql.spec.js | 10 +++++----- 2 files changed, 9 insertions(+), 7 deletions(-) diff --git a/packages/server/src/integrations/base/sql.ts b/packages/server/src/integrations/base/sql.ts index 2a7d0262ad..aea740f6f5 100644 --- a/packages/server/src/integrations/base/sql.ts +++ b/packages/server/src/integrations/base/sql.ts @@ -177,8 +177,10 @@ class InternalBuilder { const tableName = fieldNames[0] const columnName = fieldNames[1] // @ts-ignore - query = query[rawFnc](`${not}"${tableName}"."${columnName}"::jsonb ${containsOp} ${wrap}${stringifyArray( - value, any ? "'" : '"' + query = query[rawFnc]( + `${not}"${tableName}"."${columnName}"::jsonb ${containsOp} ${wrap}${stringifyArray( + value, + any ? "'" : '"' )}${wrap}` ) }) diff --git a/packages/server/src/integrations/tests/sql.spec.js b/packages/server/src/integrations/tests/sql.spec.js index 121403174c..772e408fec 100644 --- a/packages/server/src/integrations/tests/sql.spec.js +++ b/packages/server/src/integrations/tests/sql.spec.js @@ -330,18 +330,18 @@ describe("SQL query builder", () => { }) }) - it("should use OR like expression for MS-SQL when filter is containsAny", () => { + it("should use like expression for MS-SQL when filter is containsAny", () => { const query = new Sql(SqlClients.MS_SQL, 10)._query(generateReadJson({ filters: { containsAny: { - age: [20, 25], - name: ["John", "Mary"] + age: [20], + name: ["John"] } } })) expect(query).toEqual({ - bindings: [10, "%20%", "%25%", `%"John"%`, `%"Mary"%`], - sql: `select * from (select top (@p0) * from [${TABLE_NAME}] where LOWER(${TABLE_NAME}.age) LIKE @p1 and LOWER(${TABLE_NAME}.name) LIKE @p2) as [${TABLE_NAME}]` + bindings: [10, "%20%", `%"John"%`], + sql: `select * from (select top (@p0) * from [${TABLE_NAME}] where (LOWER(${TABLE_NAME}.age) LIKE @p1) and (LOWER(${TABLE_NAME}.name) LIKE @p2)) as [${TABLE_NAME}]` }) })