Skip to content

Commit b3b6e9b

Browse files
JosefDohnaldg
authored andcommitted
SqlsrvDriver::applyLimit(): supports keywords DISTINCT and ALL after SELECT
1 parent fc9dd56 commit b3b6e9b

File tree

3 files changed

+3
-3
lines changed

3 files changed

+3
-3
lines changed

src/Database/Drivers/MsSqlDriver.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,7 @@ public function formatLike($value, $pos)
7878
public function applyLimit(& $sql, $limit, $offset)
7979
{
8080
if ($limit >= 0) {
81-
$sql = preg_replace('#^\s*(SELECT|UPDATE|DELETE)#i', '$0 TOP ' . (int) $limit, $sql, 1, $count);
81+
$sql = preg_replace('#^\s*(SELECT(\s+DISTINCT|\s+ALL)?|UPDATE|DELETE)#i', '$0 TOP ' . (int) $limit, $sql, 1, $count);
8282
if (!$count) {
8383
throw new Nette\InvalidArgumentException('SQL query must begin with SELECT, UPDATE or DELETE command.');
8484
}

src/Database/Drivers/OdbcDriver.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,7 @@ public function formatLike($value, $pos)
7777
public function applyLimit(& $sql, $limit, $offset)
7878
{
7979
if ($limit >= 0) {
80-
$sql = preg_replace('#^\s*(SELECT|UPDATE|DELETE)#i', '$0 TOP ' . (int) $limit, $sql, 1, $count);
80+
$sql = preg_replace('#^\s*(SELECT(\s+DISTINCT|\s+ALL)?|UPDATE|DELETE)#i', '$0 TOP ' . (int) $limit, $sql, 1, $count);
8181
if (!$count) {
8282
throw new Nette\InvalidArgumentException('SQL query must begin with SELECT, UPDATE or DELETE command.');
8383
}

src/Database/Drivers/SqlsrvDriver.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -89,7 +89,7 @@ public function formatLike($value, $pos)
8989
public function applyLimit(& $sql, $limit, $offset)
9090
{
9191
if ($limit >= 0) {
92-
$sql = preg_replace('#^\s*(SELECT|UPDATE|DELETE)#i', '$0 TOP ' . (int) $limit, $sql, 1, $count);
92+
$sql = preg_replace('#^\s*(SELECT(\s+DISTINCT|\s+ALL)?|UPDATE|DELETE)#i', '$0 TOP ' . (int) $limit, $sql, 1, $count);
9393
if (!$count) {
9494
throw new Nette\InvalidArgumentException('SQL query must begin with SELECT, UPDATE or DELETE command.');
9595
}

0 commit comments

Comments
 (0)