Permalink
Browse files

msSQL - also handle offset as string

When doing pagination you could get offset not as a int(eg. 10) but string(eg. "10") and it will not paginate at all.

For example DataTables plugin pass offset from params and all params from http request are strings wrapped in numbers.
Adding ctype_digit($offset) will also check the case.
  • Loading branch information...
kolorafa committed Oct 5, 2017
1 parent b3d83af commit 22d2564de95d7d58e7e3d091f000aa96b86bf34f
Showing with 1 addition and 1 deletion.
  1. +1 −1 lib/Cake/Model/Datasource/Database/Sqlserver.php
@@ -411,7 +411,7 @@ public function limit($limit, $offset = null) {
$rt = ' TOP';
}
$rt .= sprintf(' %u', $limit);
if (is_int($offset) && $offset > 0) {
if ((is_int($offset) || ctype_digit($offset)) && $offset > 0) {
$rt = sprintf(' OFFSET %u ROWS FETCH FIRST %u ROWS ONLY', $offset, $limit);
}
return $rt;

0 comments on commit 22d2564

Please sign in to comment.