From 7dea5d8a4bec3c9fd2f1b07586579d4e828747dc Mon Sep 17 00:00:00 2001 From: Ricardo Espinoza Date: Sun, 27 Jun 2021 02:44:15 -0400 Subject: [PATCH] :bug: Fix issue escaping single quotes and mapping empty fields (#1929) Fixes #1915 and #1916 --- .../nodes/Microsoft/Sql/GenericFunctions.ts | 11 ++++++++++- .../nodes/Microsoft/Sql/MicrosoftSql.node.ts | 1 - 2 files changed, 10 insertions(+), 2 deletions(-) diff --git a/packages/nodes-base/nodes/Microsoft/Sql/GenericFunctions.ts b/packages/nodes-base/nodes/Microsoft/Sql/GenericFunctions.ts index 601d3b5393..d01643c124 100644 --- a/packages/nodes-base/nodes/Microsoft/Sql/GenericFunctions.ts +++ b/packages/nodes-base/nodes/Microsoft/Sql/GenericFunctions.ts @@ -95,7 +95,16 @@ export function executeQueryQueue( */ export function extractValues(item: IDataObject): string { return `(${Object.values(item as any) // tslint:disable-line:no-any - .map(val => (typeof val === 'string' ? `'${val}'` : val)) // maybe other types such as dates have to be handled as well + .map(val => { + //the column cannot be found in the input + //so, set it to null in the sql query + if (val === null) { + return 'NULL'; + } else if (typeof val === 'string') { + return `'${val.replace(/'/g, '\'\'')}'`; + } + return val; + }) // maybe other types such as dates have to be handled as well .join(',')})`; } diff --git a/packages/nodes-base/nodes/Microsoft/Sql/MicrosoftSql.node.ts b/packages/nodes-base/nodes/Microsoft/Sql/MicrosoftSql.node.ts index cd9c308f58..3043600c99 100644 --- a/packages/nodes-base/nodes/Microsoft/Sql/MicrosoftSql.node.ts +++ b/packages/nodes-base/nodes/Microsoft/Sql/MicrosoftSql.node.ts @@ -278,7 +278,6 @@ export class MicrosoftSql implements INodeType { const values = insertValues .map((item: IDataObject) => extractValues(item)) .join(','); - return pool .request() .query(