Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 16 additions & 5 deletions packages/nodes-base/nodes/Microsoft/Sql/GenericFunctions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -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(', ')};`;

Expand All @@ -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);
});
Expand All @@ -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);
});
Expand Down
Loading