🐛 Fix issue escaping single quotes and mapping empty fields (#1929)

Fixes #1915 and #1916
This commit is contained in:
Ricardo Espinoza
2021-06-27 02:44:15 -04:00
committed by GitHub
parent f940ba8f71
commit 7dea5d8a4b
2 changed files with 10 additions and 2 deletions

View File

@@ -95,7 +95,16 @@ export function executeQueryQueue(
*/ */
export function extractValues(item: IDataObject): string { export function extractValues(item: IDataObject): string {
return `(${Object.values(item as any) // tslint:disable-line:no-any 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(',')})`; .join(',')})`;
} }

View File

@@ -278,7 +278,6 @@ export class MicrosoftSql implements INodeType {
const values = insertValues const values = insertValues
.map((item: IDataObject) => extractValues(item)) .map((item: IDataObject) => extractValues(item))
.join(','); .join(',');
return pool return pool
.request() .request()
.query( .query(