Skip to content

Commit

Permalink
fix: nested functions in comparisons (#861)
Browse files Browse the repository at this point in the history
Adds a test to reproduce an issue.

---------

Co-authored-by: Bob den Os <[email protected]>
  • Loading branch information
David-Kunz and BobdenOs authored Oct 23, 2024
1 parent 338e9f5 commit f3fd254
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 1 deletion.
2 changes: 1 addition & 1 deletion hana/lib/HANAService.js
Original file line number Diff line number Diff line change
Expand Up @@ -959,7 +959,7 @@ SELECT ${mixing} FROM JSON_TABLE(SRC.JSON, '$' COLUMNS(${extraction})) AS NEW LE
// When it is a local check it cannot be compared outside of the xpr
if (up in logicOperators) {
// ensure AND is not part of BETWEEN
if (up === 'AND' && xpr[i - 2]?.toUpperCase() in { 'BETWEEN': 1, 'NOT BETWEEN': 1 }) return true
if (up === 'AND' && xpr[i - 2]?.toUpperCase?.() in { 'BETWEEN': 1, 'NOT BETWEEN': 1 }) return true
return !local
}
// When a compare operator is found the expression is a comparison
Expand Down
6 changes: 6 additions & 0 deletions test/compliance/SELECT.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -306,6 +306,12 @@ describe('SELECT', () => {
assert.strictEqual(timestampMatches.length, 1, 'Ensure that the dateTime column matches the timestamp value')
})

test('combine expr with nested functions and other compare', async () => {
const { string } = cds.entities('basic.literals')
const res = await cds.run(CQL`SELECT string FROM ${string} WHERE string != ${'foo'} and contains(tolower(string),tolower(${'bar'}))`)
assert.strictEqual(res.length, 0, 'Ensure that no row is coming back')
})

test('combine expr and other compare', async () => {
const { globals } = cds.entities('basic.literals')
const res = await cds.run(CQL`SELECT bool FROM ${globals} WHERE (bool != ${true}) and bool = ${false}`)
Expand Down

0 comments on commit f3fd254

Please sign in to comment.