From ff242e809633867076d3c60a0026283facd09a99 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Micha=C5=82=20Fox?= Date: Wed, 18 Nov 2026 15:32:07 +0100 Subject: [PATCH] Fix DELETE builder adding a zero offset to LIMIT MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit DELETE only accepts `LIMIT row_count`, but the builder always printed `LIMIT offset, row_count`, so `DELETE FROM a LIMIT 1` was rebuilt as `DELETE FROM a LIMIT 0, 1`, which MySQL rejects. A zero offset is now left out, a non-zero one is still printed as before. Signed-off-by: MichaƂ Fox --- src/Statements/DeleteStatement.php | 3 ++- tests/Builder/DeleteStatementTest.php | 2 +- 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/src/Statements/DeleteStatement.php b/src/Statements/DeleteStatement.php index 697082ae..e4764947 100644 --- a/src/Statements/DeleteStatement.php +++ b/src/Statements/DeleteStatement.php @@ -186,7 +186,8 @@ public function build(): string } if ($this->limit !== null && strlen((string) $this->limit) > 0) { - $ret .= ' LIMIT ' . $this->limit->build(); + // DELETE only accepts `LIMIT row_count`, so a zero offset is left out. + $ret .= ' LIMIT ' . ($this->limit->offset === 0 ? $this->limit->rowCount : $this->limit->build()); } return $ret; diff --git a/tests/Builder/DeleteStatementTest.php b/tests/Builder/DeleteStatementTest.php index 60f1e728..e03c57b4 100644 --- a/tests/Builder/DeleteStatementTest.php +++ b/tests/Builder/DeleteStatementTest.php @@ -36,7 +36,7 @@ public function testBuilderSingleTable(): void $this->assertEquals($query, $stmt->build()); /* Assertion 4 */ - $query = 'DELETE IGNORE FROM t1 WHERE 1=1 ORDER BY id ASC LIMIT 0, 25'; + $query = 'DELETE IGNORE FROM t1 WHERE 1=1 ORDER BY id ASC LIMIT 25'; $parser = new Parser($query); $stmt = $parser->statements[0];