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: Improve procedure metadata lookup logic #862

Merged
merged 3 commits into from
Oct 24, 2024
Merged
Changes from all commits
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
26 changes: 14 additions & 12 deletions hana/lib/HANAService.js
Original file line number Diff line number Diff line change
Expand Up @@ -987,31 +987,31 @@ SELECT ${mixing} FROM JSON_TABLE(SRC.JSON, '$' COLUMNS(${extraction})) AS NEW LE
list(list) {
const first = list.list[0]
// If the list only contains of lists it is replaced with a json function and a placeholder
if (this.values && first.list && !first.list.find(v => v.val == null)) {
const listMapped = []
if (this.values && first.list && !first.list.find(v => v.val == null)) {
const listMapped = []
for (let l of list.list) {
const obj ={}
for (let i = 0; i< l.list.length; i++) {
const obj = {}
for (let i = 0; i < l.list.length; i++) {
const c = l.list[i]
if (Buffer.isBuffer(c.val)) {
return super.list(list)
}
}
obj[`V${i}`] = c.val
}
listMapped.push(obj)
}
}
this.values.push(JSON.stringify(listMapped))
const extraction = first.list.map((v, i) => `"${i}" ${this.constructor.InsertTypeMap[typeof v.val]()} PATH '$.V${i}'`)
const extraction = first.list.map((v, i) => `"${i}" ${this.constructor.InsertTypeMap[typeof v.val]()} PATH '$.V${i}'`)
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 != null) {
for (let c of list.list) {
if (Buffer.isBuffer(c.val)) {
return super.list(list)
}
}
}
const v = first
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})))`
Expand Down Expand Up @@ -1301,16 +1301,18 @@ SELECT ${mixing} FROM JSON_TABLE(SRC.JSON, '$' COLUMNS(${extraction})) AS NEW LE
}

async _getProcedureMetadata(name, schema) {
const query = `SELECT PARAMETER_NAME FROM SYS.PROCEDURE_PARAMETERS WHERE SCHEMA_NAME = ${schema?.toUpperCase?.() === 'SYS' ? `'SYS'` : 'CURRENT_SCHEMA'
} AND PROCEDURE_NAME = '${name}' AND PARAMETER_TYPE IN ('OUT', 'INOUT') ORDER BY POSITION`
const sqlString = this.class.CQN2SQL.prototype.string
name = typeof name === 'string' ? sqlString(name) : `'${name}'`
schema = typeof schema === 'string' ? sqlString(schema) : 'CURRENT_SCHEMA'
const query = `SELECT PARAMETER_NAME FROM SYS.PROCEDURE_PARAMETERS WHERE SCHEMA_NAME = ${schema} AND PROCEDURE_NAME = ${name} AND PARAMETER_TYPE IN ('OUT', 'INOUT') ORDER BY POSITION`
return await super.onPlainSQL({ query, data: [] })
}

_getProcedureNameAndSchema(sql) {
// name delimited with "" allows any character
const match = sql
.match(
/^\s*call \s*(("(?<schema_delimited>\w+)"\.)?("(?<delimited>.+)")|(?<schema_undelimited>\w+\.)?(?<undelimited>\w+))\s*\(/i
/^\s*call \s*(("(?<schema_delimited>\w+)"\.)?("(?<delimited>.+)")|((?<schema_undelimited>\w+)\.)?(?<undelimited>\w+))\s*\(/i
)
return (
match && {
Expand Down