fix(MySQL Node): Only escape table names when needed (#8246)

This commit is contained in:
Elias Meire
2024-01-10 14:41:00 +01:00
committed by GitHub
parent dce28f9cb9
commit 3b01eb60c9
8 changed files with 81 additions and 25 deletions

View File

@@ -13,7 +13,7 @@ import type {
WhereClause,
} from '../../helpers/interfaces';
import { addWhereClauses } from '../../helpers/utils';
import { addWhereClauses, escapeSqlIdentifier } from '../../helpers/utils';
import {
optionsCollection,
@@ -98,11 +98,11 @@ export async function execute(
let values: QueryValues = [];
if (deleteCommand === 'drop') {
query = `DROP TABLE IF EXISTS \`${table}\``;
query = `DROP TABLE IF EXISTS ${escapeSqlIdentifier(table)}`;
}
if (deleteCommand === 'truncate') {
query = `TRUNCATE TABLE \`${table}\``;
query = `TRUNCATE TABLE ${escapeSqlIdentifier(table)}`;
}
if (deleteCommand === 'delete') {
@@ -114,7 +114,7 @@ export async function execute(
[query, values] = addWhereClauses(
this.getNode(),
i,
`DELETE FROM \`${table}\``,
`DELETE FROM ${escapeSqlIdentifier(table)}`,
whereClauses,
values,
combineConditions,