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];