Skip to content

Commit

Permalink
fix: sort property is case insensitive (#924)
Browse files Browse the repository at this point in the history
  • Loading branch information
patricebender authored Dec 5, 2024
1 parent 09a40ff commit 2c72c87
Show file tree
Hide file tree
Showing 4 changed files with 18 additions and 6 deletions.
4 changes: 2 additions & 2 deletions db-service/lib/cqn2sql.js
Original file line number Diff line number Diff line change
Expand Up @@ -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'),
)
}

Expand Down
4 changes: 2 additions & 2 deletions hana/lib/HANAService.js
Original file line number Diff line number Diff line change
Expand Up @@ -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'),
)
}

Expand Down
4 changes: 2 additions & 2 deletions postgres/lib/PostgresService.js
Original file line number Diff line number Diff line change
Expand Up @@ -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'),
)
}

Expand Down
12 changes: 12 additions & 0 deletions test/compliance/SELECT.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -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`
Expand Down

0 comments on commit 2c72c87

Please sign in to comment.