diff --git a/src/Dibi/Drivers/FirebirdDriver.php b/src/Dibi/Drivers/FirebirdDriver.php index 3609c6324..2fda73fbf 100644 --- a/src/Dibi/Drivers/FirebirdDriver.php +++ b/src/Dibi/Drivers/FirebirdDriver.php @@ -276,7 +276,8 @@ public function escapeDateTime($value): string */ public function escapeLike(string $value, int $pos): string { - throw new Dibi\NotImplementedException; + $value = addcslashes(str_replace('\\', '\\\\', $value), "\x00\n\r\\'%_"); + return ($pos <= 0 ? "'%" : "'") . $value . ($pos >= 0 ? "%'" : "'"); } diff --git a/src/Dibi/Drivers/SqlsrvDriver.php b/src/Dibi/Drivers/SqlsrvDriver.php index 57a093487..d7a35b4a3 100644 --- a/src/Dibi/Drivers/SqlsrvDriver.php +++ b/src/Dibi/Drivers/SqlsrvDriver.php @@ -271,7 +271,10 @@ public function applyLimit(string &$sql, ?int $limit, ?int $offset): void } elseif ($limit !== null) { // requires ORDER BY, see https://technet.microsoft.com/en-us/library/gg699618(v=sql.110).aspx - $sql = sprintf('%s OFFSET %d ROWS FETCH NEXT %d ROWS ONLY', rtrim($sql), $offset, $limit); + if (strpos($sql, ' ORDER BY ')=== false){ + $sql = sprintf('%s ORDER BY 1 ', rtrim($sql)); + } + $sql = sprintf('%s OFFSET %d ROWS FETCH NEXT %d ROWS ONLY', rtrim($sql), $offset, $limit); } elseif ($offset) { // requires ORDER BY, see https://technet.microsoft.com/en-us/library/gg699618(v=sql.110).aspx $sql = sprintf('%s OFFSET %d ROWS', rtrim($sql), $offset);