Skip to content

Commit

Permalink
Quote the alias in MySQL DELETE queries
Browse files Browse the repository at this point in the history
  • Loading branch information
kozlovsky committed Sep 25, 2023
1 parent 1a9c3bb commit cd74248
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 4 deletions.
5 changes: 3 additions & 2 deletions pony/orm/sqlbuilding.py
Original file line number Diff line number Diff line change
Expand Up @@ -232,8 +232,9 @@ def DELETE(builder, alias, from_ast, where=None):
builder.indent += 1
if alias is not None:
assert isinstance(alias, str)
if not where: return 'DELETE ', alias, ' ', builder(from_ast)
return 'DELETE ', alias, ' ', builder(from_ast), builder(where)
if not where:
return 'DELETE ', builder.quote_name(alias), ' ', builder(from_ast)
return 'DELETE ', builder.quote_name(alias), ' ', builder(from_ast), builder(where)
else:
assert from_ast[0] == 'FROM' and len(from_ast) == 2 and from_ast[1][1] == 'TABLE'
alias = from_ast[1][0]
Expand Down
4 changes: 2 additions & 2 deletions pony/orm/tests/queries.txt
Original file line number Diff line number Diff line change
Expand Up @@ -754,7 +754,7 @@ WHERE "id" IN (

MySQL:

DELETE s FROM `student` `s`
DELETE `s` FROM `student` `s`
INNER JOIN `group` `group`
ON `s`.`group` = `group`.`number`
WHERE `group`.`dept` = 1
Expand Down Expand Up @@ -791,7 +791,7 @@ WHERE "ROWID" IN (

MySQL:

DELETE c FROM `course` `c`
DELETE `c` FROM `course` `c`
INNER JOIN `department` `department`
ON `c`.`dept` = `department`.`number`
WHERE `department`.`name` LIKE 'D%%'
Expand Down

0 comments on commit cd74248

Please sign in to comment.