Skip to content

Commit ab323cf

Browse files
authored
Merge pull request #679 from Lawrence72/master
Ignore LiMIT when using RETURNING
2 parents 88d7032 + a3f47bc commit ab323cf

3 files changed

Lines changed: 13 additions & 1 deletion

File tree

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,3 +10,4 @@ clover.xml
1010
phpcs.xml
1111
.runway-config.json
1212
.runway-creds.json
13+
.DS_Store

flight/database/SimplePdo.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,7 @@ public function __construct(
6868
public function fetchRow(string $sql, array $params = []): ?Collection
6969
{
7070
// Smart LIMIT 1 addition (avoid if already present at end or complex query)
71-
if (!preg_match('/\sLIMIT\s+\d+(?:\s+OFFSET\s+\d+)?\s*$/i', trim($sql))) {
71+
if (!preg_match('/\s(LIMIT\s+\d+(?:\s+OFFSET\s+\d+)?|RETURNING\s+.+)\s*$/i', trim($sql))) {
7272
$sql .= ' LIMIT 1';
7373
}
7474

tests/SimplePdoTest.php

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -153,6 +153,17 @@ public function testFetchRowDoesNotDuplicateLimitClause(): void
153153
$this->assertInstanceOf(Collection::class, $row);
154154
$this->assertEquals(3, $row['id']); // Should be Bob (id=3)
155155
}
156+
157+
public function testFetchRowDoesNotAddLimitAfterReturningClause(): void
158+
{
159+
$row = $this->db->fetchRow(
160+
'INSERT INTO users (name, email) VALUES (?, ?) RETURNING id, name',
161+
['Alice', 'alice@example.com']
162+
);
163+
164+
$this->assertInstanceOf(Collection::class, $row);
165+
$this->assertSame('Alice', $row['name']);
166+
}
156167

157168
// =========================================================================
158169
// fetchAll Tests

0 commit comments

Comments
 (0)