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

feat: Add quoted mode support #681

Merged
merged 8 commits into from
Oct 1, 2024
Merged
6 changes: 6 additions & 0 deletions db-service/lib/cqn2sql.js
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,12 @@ class CQN2SQLRenderer {
this.class = new.target // for IntelliSense
this.class._init() // is a noop for subsequent calls
this.model = srv?.model

// Overwrite smart quoting
if (cds.env.cdsc.sqlMapping === 'quoted') {
Copy link
Contributor

Choose a reason for hiding this comment

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

Use official setting cds.env.sql.names instead

this.class.prototype.name = (name) => name.id || name
this.class.prototype.quote = (s) => `"${s.replace(/"/g, '""')}"`
}
patricebender marked this conversation as resolved.
Show resolved Hide resolved
}

static _add_mixins(aspect, mixins) {
Expand Down
4 changes: 2 additions & 2 deletions hana/lib/HANAService.js
Original file line number Diff line number Diff line change
Expand Up @@ -600,11 +600,11 @@ class HANAService extends SQLService {

// Calculate final output columns once
let outputColumns = ''
outputColumns = `_path_ as "_path_",${blobs} as "_blobs_",${expands} as "_expands_",${jsonColumn} as "_json_"`
outputColumns = `${this.quote('_path_')} as "_path_",${blobs} as "_blobs_",${expands} as "_expands_",${jsonColumn} as "_json_"`
johannes-vogel marked this conversation as resolved.
Show resolved Hide resolved
if (blobColumns.length)
outputColumns = `${outputColumns},${blobColumns.map(b => `${this.quote(b)} as "${b.replace(/"/g, '""')}"`)}`
this._outputColumns = outputColumns
sql = `*,${path} as _path_`
sql = `*,${path} as ${this.quote('_path_')}`
}
return sql
}
Expand Down