fix(Microsoft SQL Node): Prevent double escaping table name (#7801)

Github issue / Community forum post (link here to close automatically):
https://community.n8n.io/t/issue-my-mssql-update-in-latest-version/32966
This commit is contained in:
Michael Kret 2023-11-27 16:41:35 +02:00 committed by GitHub
parent dff8456382
commit 73ec7533ce
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -111,6 +111,15 @@ export function configurePool(credentials: IDataObject) {
return new mssql.ConnectionPool(config);
}
const escapeTableName = (table: string) => {
table = table.trim();
if (table.startsWith('[') && table.endsWith(']')) {
return table;
} else {
return `[${table}]`;
}
};
export async function insertOperation(tables: ITables, pool: mssql.ConnectionPool) {
return executeQueryQueue(
tables,
@ -128,7 +137,7 @@ export async function insertOperation(tables: ITables, pool: mssql.ConnectionPoo
}
}
const query = `INSERT INTO [${table}] (${formatColumns(
const query = `INSERT INTO ${escapeTableName(table)} (${formatColumns(
columnString,
)}) VALUES ${valuesPlaceholder.join(', ')};`;
@ -155,7 +164,9 @@ export async function updateOperation(tables: ITables, pool: mssql.ConnectionPoo
request.input(`v${index}`, item[col]);
}
const query = `UPDATE [${table}] SET ${setValues.join(', ')} WHERE ${condition};`;
const query = `UPDATE ${escapeTableName(table)} SET ${setValues.join(
', ',
)} WHERE ${condition};`;
return request.query(query);
});
@ -182,9 +193,9 @@ export async function deleteOperation(tables: ITables, pool: mssql.ConnectionPoo
request.input(`v${index}`, entry[deleteKey]);
}
const query = `DELETE FROM [${table}] WHERE [${deleteKey}] IN (${valuesPlaceholder.join(
', ',
)});`;
const query = `DELETE FROM ${escapeTableName(
table,
)} WHERE [${deleteKey}] IN (${valuesPlaceholder.join(', ')});`;
return request.query(query);
});