Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: nested functions in comparisons #861

Merged
merged 2 commits into from
Oct 23, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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