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
13 changes: 12 additions & 1 deletion 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.sql.names === 'quoted') {
this.class.prototype.name = (name) => name.id || name
this.class.prototype.quote = (s) => `"${String(s).replace(/"/g, '""')}"`
}
}

static _add_mixins(aspect, mixins) {
Expand Down Expand Up @@ -336,7 +342,12 @@ class CQN2SQLRenderer {
const { ref, as } = from
const _aliased = as ? s => s + ` as ${this.quote(as)}` : s => s
if (ref) {
const z = ref[0]
let z = ref[0]
if (cds.env.sql.names === 'quoted') {
// use SELECT.from to infer query, cds.infer also expects a query
const { target } = SELECT.from(from)
z = target?.['@cds.persistence.name'] || ref[0]
}
if (z.args) {
return _aliased(`${this.quote(this.name(z))}${this.from_args(z.args)}`)
}
Expand Down
4 changes: 2 additions & 2 deletions hana/lib/HANAService.js
Original file line number Diff line number Diff line change
Expand Up @@ -607,11 +607,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
Loading