From dedd4dfe4ec8b58c64024453cfca8973a0d850a8 Mon Sep 17 00:00:00 2001 From: Patrice Bender Date: Fri, 29 Nov 2024 16:04:03 +0100 Subject: [PATCH 1/2] fix: sort property is case insensitive --- test/compliance/SELECT.test.js | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/test/compliance/SELECT.test.js b/test/compliance/SELECT.test.js index 5083391fd..f585220ad 100644 --- a/test/compliance/SELECT.test.js +++ b/test/compliance/SELECT.test.js @@ -569,6 +569,18 @@ describe('SELECT', () => { assert.deepEqual(res, sorted, 'Ensure that all rows are in the correct order') }) + test('sort is case insensitive', async () => { + const { string } = cds.entities('basic.literals') + const mixedDesc = SELECT.from(string).columns('string').orderBy('string DeSc') + const desc = SELECT.from(string).columns('string').orderBy('string desc') + const mixedAsc = SELECT.from(string).columns('string').orderBy('string aSC') + const asc = SELECT.from(string).columns('string').orderBy('string asc') + + expect(await cds.run(mixedDesc)).to.eql(await cds.run(desc)) + expect(await cds.run(mixedAsc)).to.eql(await cds.run(asc)) + }) + + test('localized', async () => { const { string } = cds.entities('basic.literals') const cqn = CQL`SELECT string FROM ${string} ORDER BY string` From ab794126f400d5f47c0df83e84123aa0951b6397 Mon Sep 17 00:00:00 2001 From: Patrice Bender Date: Fri, 29 Nov 2024 16:04:27 +0100 Subject: [PATCH 2/2] fix the issue --- db-service/lib/cqn2sql.js | 4 ++-- hana/lib/HANAService.js | 4 ++-- postgres/lib/PostgresService.js | 4 ++-- 3 files changed, 6 insertions(+), 6 deletions(-) diff --git a/db-service/lib/cqn2sql.js b/db-service/lib/cqn2sql.js index 77d680f1a..ac41b0236 100644 --- a/db-service/lib/cqn2sql.js +++ b/db-service/lib/cqn2sql.js @@ -423,8 +423,8 @@ class CQN2SQLRenderer { ? c => this.expr(c) + (c.element?.[this.class._localized] ? ' COLLATE NOCASE' : '') + - (c.sort === 'desc' || c.sort === -1 ? ' DESC' : ' ASC') - : c => this.expr(c) + (c.sort === 'desc' || c.sort === -1 ? ' DESC' : ' ASC'), + (c.sort?.toLowerCase() === 'desc' || c.sort === -1 ? ' DESC' : ' ASC') + : c => this.expr(c) + (c.sort?.toLowerCase() === 'desc' || c.sort === -1 ? ' DESC' : ' ASC'), ) } diff --git a/hana/lib/HANAService.js b/hana/lib/HANAService.js index 7d7f57cfe..3a8ba7444 100644 --- a/hana/lib/HANAService.js +++ b/hana/lib/HANAService.js @@ -791,8 +791,8 @@ SELECT ${mixing} FROM JSON_TABLE(SRC.JSON, '$' COLUMNS(${extraction})) AS NEW LE ? ` COLLATE ${collations[this.context.locale] || collations[this.context.locale.split('_')[0]] || collations[''] }` : '') + - (c.sort === 'desc' || c.sort === -1 ? ' DESC' : ' ASC') - : c => this.expr(c) + (c.sort === 'desc' || c.sort === -1 ? ' DESC' : ' ASC'), + (c.sort?.toLowerCase() === 'desc' || c.sort === -1 ? ' DESC' : ' ASC') + : c => this.expr(c) + (c.sort?.toLowerCase() === 'desc' || c.sort === -1 ? ' DESC' : ' ASC'), ) } diff --git a/postgres/lib/PostgresService.js b/postgres/lib/PostgresService.js index a1093c776..80f909f37 100644 --- a/postgres/lib/PostgresService.js +++ b/postgres/lib/PostgresService.js @@ -348,8 +348,8 @@ GROUP BY k ? c => this.expr(c) + (c.element?.[this.class._localized] ? ` COLLATE "${locale}"` : '') + - (c.sort === 'desc' || c.sort === -1 ? ' DESC NULLS LAST' : ' ASC NULLS FIRST') - : c => this.expr(c) + (c.sort === 'desc' || c.sort === -1 ? ' DESC NULLS LAST' : ' ASC NULLS FIRST'), + (c.sort?.toLowerCase() === 'desc' || c.sort === -1 ? ' DESC NULLS LAST' : ' ASC NULLS FIRST') + : c => this.expr(c) + (c.sort?.toLowerCase() === 'desc' || c.sort === -1 ? ' DESC NULLS LAST' : ' ASC NULLS FIRST'), ) }