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: Align all quote functions with @sap/cds-compiler #619

Merged
merged 4 commits into from
Apr 30, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
3 changes: 1 addition & 2 deletions db-service/lib/cqn2sql.js
Original file line number Diff line number Diff line change
Expand Up @@ -967,9 +967,8 @@ class CQN2SQLRenderer {
*/
quote(s) {
if (typeof s !== 'string') return '"' + s + '"'
if (s.includes('"')) return '"' + s.replace(/"/g, '""') + '"'
// Column names like "Order" clash with "ORDER" keyword so toUpperCase is required
if (s in this.class.ReservedWords || /^\d|[$' ?@./\\]/.test(s)) return '"' + s + '"'
if (s.toUpperCase() in this.class.ReservedWords || !/^[A-Za-z_][A-Za-z_$0-9]*$/.test(s)) return '"' + s + '"'
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please add 'Order', 'order', and 'ORDER' to ReservedWords, and thereby eliminate the need to always do toUpperCase() -- as we had it in a former revision. And no, we don't have to correctly handle pathological variants like 'OrDeR' ;)

return s
}

Expand Down
3 changes: 1 addition & 2 deletions hana/lib/HANAService.js
Original file line number Diff line number Diff line change
Expand Up @@ -877,8 +877,7 @@ class HANAService extends SQLService {
// When returning columns from a query they should be case sensitive
// cds-compiler effectiveName uses toUpperCase for hana dialect, but not for hdbcds
if (typeof s !== 'string') return '"' + s + '"'
if (s.includes('"')) return '"' + s.replace(/"/g, '""').toUpperCase() + '"'
if (s.toUpperCase() in this.class.ReservedWords || /^\d|[$' @./\\]/.test(s)) return '"' + s.toUpperCase() + '"'
if (s.toUpperCase() in this.class.ReservedWords || !/^[A-Za-z_][A-Za-z_$#0-9]*$/.test(s)) return '"' + s.toUpperCase() + '"'
return s
}

Expand Down
7 changes: 7 additions & 0 deletions postgres/lib/PostgresService.js
Original file line number Diff line number Diff line change
Expand Up @@ -441,6 +441,13 @@ GROUP BY k
return 'FOR SHARE'
}

// Postgres requires own quote function, becuase the effective name is lower case
quote(s) {
if (typeof s !== 'string') return '"' + s + '"'
if (s.toUpperCase() in this.class.ReservedWords || !/^[A-Za-z_][A-Za-z_$0-9]*$/.test(s)) return '"' + s.toLowerCase() + '"'
return s
}

defaultValue(defaultValue = this.context.timestamp.toISOString()) {
return this.string(`${defaultValue}`)
}
Expand Down
Loading