1 | <?php |
||
2 | /** |
||
3 | * Rows limiting |
||
4 | * User: moyo |
||
5 | * Date: 25/12/2017 |
||
6 | * Time: 11:09 AM |
||
7 | */ |
||
8 | |||
9 | namespace Carno\Database\SQL\Builders; |
||
10 | |||
11 | use Carno\Database\SQL\Builder; |
||
12 | |||
13 | trait Limit |
||
14 | { |
||
15 | /** |
||
16 | * @var array |
||
17 | */ |
||
18 | private $bLimit = []; |
||
19 | |||
20 | /** |
||
21 | * @return string |
||
22 | */ |
||
23 | protected function gLimit() : string |
||
24 | { |
||
25 | return $this->bLimit ? sprintf(' LIMIT %d,%d', $this->bLimit[0], $this->bLimit[1]) : ''; |
||
26 | } |
||
27 | |||
28 | /** |
||
29 | * @param array ...$expr |
||
30 | * @return Builder |
||
31 | */ |
||
32 | public function limit(...$expr) : Builder |
||
33 | { |
||
34 | switch (count($expr)) { |
||
35 | case 1: |
||
36 | // limit(rows) |
||
37 | $this->bLimit = [0, $expr[0]]; |
||
38 | break; |
||
39 | case 2: |
||
40 | // limit(offset, rows) |
||
41 | $this->bLimit = $expr; |
||
42 | break; |
||
43 | } |
||
44 | |||
45 | return $this; |
||
0 ignored issues
–
show
Bug
Best Practice
introduced
by
![]() |
|||
46 | } |
||
47 | } |
||
48 |