Skip to content

Commit

Permalink
Merge branch 'main' into fix/insert-calculated-column
Browse files Browse the repository at this point in the history
  • Loading branch information
johannes-vogel committed Sep 2, 2024
2 parents 1783b09 + 6e8ff0f commit 50c8fd1
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 16 deletions.
12 changes: 6 additions & 6 deletions db-service/lib/cqn2sql.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,14 +13,14 @@ const BINARY_TYPES = {
const { Readable } = require('stream')

const DEBUG = (() => {
let DEBUG = cds.debug('sql-json')
if (DEBUG) return DEBUG
else DEBUG = cds.debug('sql|sqlite')
if (DEBUG) {
return DEBUG
const LOG = cds.log('sql-json')
if (LOG._debug) return cds.debug('sql-json')
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
}
//}
})()

class CQN2SQLRenderer {
Expand Down
8 changes: 8 additions & 0 deletions hana/lib/HANAService.js
Original file line number Diff line number Diff line change
Expand Up @@ -977,6 +977,13 @@ class HANAService extends SQLService {
this.values.push(JSON.stringify(list.list.map(l => l.list.reduce((l, c, i) => { l[`V${i}`] = c.val; return l }, {}))))
return `(SELECT * FROM JSON_TABLE(?, '$' COLUMNS(${extraction})))`
}
// If the list only contains of vals it is replaced with a json function and a placeholder
if (this.values && first.val) {
const v = first
const extraction = `"val" ${this.constructor.InsertTypeMap[typeof v.val]()} PATH '$.val'`
this.values.push(JSON.stringify(list.list))
return `(SELECT * FROM JSON_TABLE(?, '$' COLUMNS(${extraction})))`
}
// Call super for normal SQL behavior
return super.list(list)
}
Expand Down Expand Up @@ -1124,6 +1131,7 @@ class HANAService extends SQLService {

static OutputConverters = {
...super.OutputConverters,
LargeString: cds.env.features.sql_simple_queries > 0 ? e => `TO_NVARCHAR(${e})` : undefined,
// REVISIT: binaries should use BASE64_ENCODE, but this results in BASE64_ENCODE(BINTONHEX(${e}))
Binary: e => `BINTONHEX(${e})`,
Date: e => `to_char(${e}, 'YYYY-MM-DD')`,
Expand Down
20 changes: 10 additions & 10 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit 50c8fd1

Please sign in to comment.