Skip to content

[db-sync] Escape column name in UPDATE statement #11286

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

Merged
merged 1 commit into from
Jul 11, 2022
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
4 changes: 2 additions & 2 deletions components/ee/db-sync/src/export.ts
Original file line number Diff line number Diff line change
Expand Up @@ -136,7 +136,7 @@ export class TableUpdate {

const pkValues = this.table.primaryKeys.map(c => escape(row[c], true));
const updateValues = this.updateColumns.map(c => escape(row[c], true));
const updates = this.updateColumns.map((c, i) => `${c}=${updateValues[i]}`).join(", ")
const updates = this.updateColumns.map((c, i) => `${escapeWithBackticks(c)}=${updateValues[i]}`).join(", ")
const updateConditions = this.getUpdateConditions(row);

let result = [`INSERT${forceInsert ? '' : ' IGNORE'} INTO ${this.table.name} (${(this.table.primaryKeys.concat(this.updateColumns)).map(escapeWithBackticks).join(", ")}) VALUES (${(pkValues.concat(updateValues)).join(", ")});`];
Expand All @@ -147,7 +147,7 @@ export class TableUpdate {
}

protected getUpdateConditions(row: any): string {
return this.table.primaryKeys.map(pk => `${pk}=${escape(row[pk])}`).concat([`${this.table.timeColumn}<=${escape(row[this.table.timeColumn])}`]).join(" AND ");
return this.table.primaryKeys.map(pk => `${escapeWithBackticks(pk)}=${escape(row[pk])}`).concat([`${this.table.timeColumn}<=${escape(row[this.table.timeColumn])}`]).join(" AND ");
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💯

}

}
Expand Down