From d152635e259a0f929944889748bdcf996c33d79e Mon Sep 17 00:00:00 2001 From: mike12345567 Date: Mon, 4 Apr 2022 15:39:38 +0100 Subject: [PATCH] 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. --- packages/server/src/threads/query.js | 16 +++++++++------- 1 file changed, 9 insertions(+), 7 deletions(-) diff --git a/packages/server/src/threads/query.js b/packages/server/src/threads/query.js index 270c2cc713..aee3ddb205 100644 --- a/packages/server/src/threads/query.js +++ b/packages/server/src/threads/query.js @@ -37,7 +37,7 @@ class QueryRunner { arrays = [] for (let binding of bindings) { // 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) // check if the variable was used as part of a string concat e.g. 'Hello {{binding}}' const charConstRegex = new RegExp(`'[^']*${binding}[^']*'`) @@ -63,12 +63,14 @@ class QueryRunner { "," ) // build a string like ($1, $2, $3) - sql = sql.replace( - binding, - `(${Array.apply(null, Array(value.length)) - .map(() => integration.getBindingIdentifier()) - .join(",")})` - ) + let replacement = `${Array.apply(null, Array(value.length)) + .map(() => integration.getBindingIdentifier()) + .join(",")}` + // check if parentheses are needed + if (!listRegexMatch[0].includes(`(${binding})`)) { + replacement = `(${replacement})` + } + sql = sql.replace(binding, replacement) } else { sql = sql.replace(binding, integration.getBindingIdentifier()) }