| Conditions | 5 |
| Paths | 3 |
| Total Lines | 21 |
| Code Lines | 10 |
| Lines | 0 |
| Ratio | 0 % |
| Tests | 9 |
| CRAP Score | 5 |
| Changes | 0 | ||
| 1 | <?php |
||
| 44 | 35 | public function applyLimit($stm, $limit, $offset) |
|
| 45 | { |
||
| 46 | 35 | if (! $limit && ! $offset) { |
|
| 47 | 33 | return $stm; // no limit or offset |
|
| 48 | } |
||
| 49 | |||
| 50 | // limit but no offset? |
||
| 51 | 2 | if ($limit && ! $offset) { |
|
| 52 | // use TOP in place |
||
| 53 | 1 | return preg_replace( |
|
| 54 | 1 | '/^(SELECT( DISTINCT)?)/', |
|
| 55 | 1 | "$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 | 2 | return $stm . PHP_EOL . "OFFSET {$offset} ROWS " |
|
| 63 | 2 | . "FETCH NEXT {$limit} ROWS ONLY"; |
|
| 64 | } |
||
| 65 | } |
||
| 66 |