if ($limitfrom or $limitnum) {
if ($limitnum >= 1) { // Only apply TOP clause if we have any limitnum (limitfrom offset is handled later)
$fetch = $limitfrom + $limitnum;
- $sql = preg_replace('/^([\s(])*SELECT([\s]+)(DISTINCT|ALL)?(?!\s*TOP\s*\()/i',
- "\\1SELECT\\2\\3 TOP $fetch", $sql);
+ $sql = preg_replace('/^([\s(])*SELECT([\s]+(DISTINCT|ALL))?(?!\s*TOP\s*\()/i',
+ "\\1SELECT\\2 TOP $fetch", $sql);
}
}
$offset = max(0, $offset);
if ($limit > 0 && $offset == 0) {
- $sql1 = preg_replace('/^([\s(])*SELECT([\s]+)(DISTINCT|ALL)?(?!\s*TOP\s*\()/i',
- "\\1SELECT\\2\\3 TOP $limit", $sql);
+ $sql1 = preg_replace('/^([\s(])*SELECT([\s]+(DISTINCT|ALL))?(?!\s*TOP\s*\()/i',
+ "\\1SELECT\\2 TOP $limit", $sql);
} else {
// Only apply TOP clause if we have any limitnum (limitfrom offset is handled later)
if ($limit < 1) {