sql-parser icon indicating copy to clipboard operation
sql-parser copied to clipboard

Re-formating LIMIT destroys DELETE and UPDATE queries

Open werner-freytag opened this issue 6 years ago • 0 comments

When building queries, the LIMIT is re-formatted. For example SELECT * FROM tbl LIMIT 1 is changed to SELECT * FROM tbl LIMIT 0, 1. This works just fine for SELECT queries, but not for DELETE or UPDATE queries.

Example:

$query1 = "DELETE FROM a LIMIT 1";
$parser = new PhpMyAdmin\SqlParser\Parser($query1);
$statement = $parser->statements[0];

$table2 = new \PhpMyAdmin\SqlParser\Components\Expression("", "b", "", "");
$statement->from[0] = $table2;

echo $statement->build();

results in

DELETE  FROM `b` LIMIT 0, 1

The changed query fails, while the original query is perfect SQL.

werner-freytag avatar Jun 28 '19 12:06 werner-freytag