Skip to content

Commit

Permalink
Ensure entries has higher priority then rows and values
Browse files Browse the repository at this point in the history
  • Loading branch information
BobdenOs committed Sep 9, 2024
1 parent 0c8088f commit 84ba9f6
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 6 deletions.
10 changes: 5 additions & 5 deletions db-service/lib/cqn2sql.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,8 @@ const DEBUG = (() => {
return cds.debug('sql|sqlite')
//if (DEBUG) {
// return DEBUG
// (sql, ...more) => DEBUG (sql.replace(/(?:SELECT[\n\r\s]+(json_group_array\()?[\n\r\s]*json_insert\((\n|\r|.)*?\)[\n\r\s]*\)?[\n\r\s]+as[\n\r\s]+_json_[\n\r\s]+FROM[\n\r\s]*\(|\)[\n\r\s]*(\)[\n\r\s]+AS )|\)$)/gim,(a,b,c,d) => d || ''), ...more)
// FIXME: looses closing ) on INSERT queries
// (sql, ...more) => DEBUG (sql.replace(/(?:SELECT[\n\r\s]+(json_group_array\()?[\n\r\s]*json_insert\((\n|\r|.)*?\)[\n\r\s]*\)?[\n\r\s]+as[\n\r\s]+_json_[\n\r\s]+FROM[\n\r\s]*\(|\)[\n\r\s]*(\)[\n\r\s]+AS )|\)$)/gim,(a,b,c,d) => d || ''), ...more)
// FIXME: looses closing ) on INSERT queries
//}
})()

Expand Down Expand Up @@ -313,8 +313,8 @@ class CQN2SQLRenderer {
*/
column_expr(x, q) {
if (x === '*') return '*'
let sql = x.param !== true && typeof x.val === 'number' ? this.expr({ param: false, __proto__: x }): this.expr(x)

let sql = x.param !== true && typeof x.val === 'number' ? this.expr({ param: false, __proto__: x }) : this.expr(x)
let alias = this.column_alias4(x, q)
if (alias) sql += ' as ' + this.quote(alias)
return sql
Expand Down Expand Up @@ -1116,7 +1116,7 @@ class CQN2SQLRenderer {

managed_extract(name, element, converter) {
const { UPSERT, INSERT } = this.cqn
const extract = INSERT?.rows || UPSERT?.rows
const extract = !(INSERT?.entries || UPSERT?.entries) && (INSERT?.rows || UPSERT?.rows)
? `value->>'$[${this.columns.indexOf(name)}]'`
: `value->>'$."${name.replace(/"/g, '""')}"'`
const sql = converter?.(extract) || extract
Expand Down
2 changes: 1 addition & 1 deletion postgres/lib/PostgresService.js
Original file line number Diff line number Diff line change
Expand Up @@ -430,7 +430,7 @@ GROUP BY k

managed_extract(name, element, converter) {
const { UPSERT, INSERT } = this.cqn
const extract = INSERT?.rows || UPSERT?.rows
const extract = !(INSERT?.entries || UPSERT?.entries) && (INSERT?.rows || UPSERT?.rows)
? `value->>${this.columns.indexOf(name)}`
: `value->>'${name.replace(/'/g, "''")}'`
const sql = converter?.(extract) || extract
Expand Down

0 comments on commit 84ba9f6

Please sign in to comment.