Extension of fix for 4978 - fixing an issue where parentheses are added to the IN query, causing the query system to not recognise the need to switch out the binding.
This commit is contained in:
parent
6dd09b6b4f
commit
d152635e25
|
@ -37,7 +37,7 @@ class QueryRunner {
|
||||||
arrays = []
|
arrays = []
|
||||||
for (let binding of bindings) {
|
for (let binding of bindings) {
|
||||||
// look for array/list operations in the SQL statement, which will need handled later
|
// look for array/list operations in the SQL statement, which will need handled later
|
||||||
const listRegex = new RegExp(`(in|IN|In|iN)( )+${binding}`)
|
const listRegex = new RegExp(`(in|IN|In|iN)( )+[(]?${binding}[)]?`)
|
||||||
const listRegexMatch = sql.match(listRegex)
|
const listRegexMatch = sql.match(listRegex)
|
||||||
// check if the variable was used as part of a string concat e.g. 'Hello {{binding}}'
|
// check if the variable was used as part of a string concat e.g. 'Hello {{binding}}'
|
||||||
const charConstRegex = new RegExp(`'[^']*${binding}[^']*'`)
|
const charConstRegex = new RegExp(`'[^']*${binding}[^']*'`)
|
||||||
|
@ -63,12 +63,14 @@ class QueryRunner {
|
||||||
","
|
","
|
||||||
)
|
)
|
||||||
// build a string like ($1, $2, $3)
|
// build a string like ($1, $2, $3)
|
||||||
sql = sql.replace(
|
let replacement = `${Array.apply(null, Array(value.length))
|
||||||
binding,
|
|
||||||
`(${Array.apply(null, Array(value.length))
|
|
||||||
.map(() => integration.getBindingIdentifier())
|
.map(() => integration.getBindingIdentifier())
|
||||||
.join(",")})`
|
.join(",")}`
|
||||||
)
|
// check if parentheses are needed
|
||||||
|
if (!listRegexMatch[0].includes(`(${binding})`)) {
|
||||||
|
replacement = `(${replacement})`
|
||||||
|
}
|
||||||
|
sql = sql.replace(binding, replacement)
|
||||||
} else {
|
} else {
|
||||||
sql = sql.replace(binding, integration.getBindingIdentifier())
|
sql = sql.replace(binding, integration.getBindingIdentifier())
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue