Conditions | 5 |
Paths | 3 |
Total Lines | 21 |
Code Lines | 10 |
Lines | 0 |
Ratio | 0 % |
Changes | 0 |
1 | <?php |
||
44 | public function applyLimit($stm, $limit, $offset) |
||
45 | { |
||
46 | if (! $limit && ! $offset) { |
||
47 | return $stm; // no limit or offset |
||
48 | } |
||
49 | |||
50 | // limit but no offset? |
||
51 | if ($limit && ! $offset) { |
||
52 | // use TOP in place |
||
53 | return preg_replace( |
||
54 | '/^(SELECT( DISTINCT)?)/', |
||
55 | "$1 TOP {$limit}", |
||
56 | $stm |
||
57 | ); |
||
58 | } |
||
59 | |||
60 | // both limit and offset. must have an ORDER clause to work; OFFSET is |
||
61 | // a sub-clause of the ORDER clause. cannot use FETCH without OFFSET. |
||
62 | return $stm . PHP_EOL . "OFFSET {$offset} ROWS " |
||
63 | . "FETCH NEXT {$limit} ROWS ONLY"; |
||
64 | } |
||
65 | } |
||
66 |