@@ 20-55 (lines=36) @@ | ||
17 | protected $quotes = ['[', ']']; |
|
18 | ||
19 | /** @inheritdoc */ |
|
20 | public function select(array $cols, array $from, string $where = null, $limit = null, $offset = null, bool $distinct = null, array $groupby, array $orderby):array{ |
|
21 | $sql = ['SELECT']; |
|
22 | ||
23 | if($distinct){ |
|
24 | $sql[] = 'DISTINCT'; |
|
25 | } |
|
26 | ||
27 | !empty($cols) |
|
28 | ? $sql[] = implode(', ', $cols) |
|
29 | : $sql[] = '*'; |
|
30 | ||
31 | $sql[] = 'FROM'; |
|
32 | $sql[] = implode(', ', $from); |
|
33 | $sql[] = $where; |
|
34 | ||
35 | if(!empty($groupby)){ |
|
36 | $sql[] = 'GROUP BY'; |
|
37 | $sql[] = implode(', ', $groupby); |
|
38 | } |
|
39 | ||
40 | if(!empty($orderby)){ |
|
41 | $sql[] = 'ORDER BY'; |
|
42 | $sql[] = implode(', ', $orderby); |
|
43 | } |
|
44 | ||
45 | if($limit !== null){ |
|
46 | ||
47 | if(empty($orderby)){ |
|
48 | $sql[] = 'ORDER BY 1'; |
|
49 | } |
|
50 | ||
51 | $sql[] = 'OFFSET ? ROWS FETCH NEXT ? ROWS ONLY'; |
|
52 | } |
|
53 | ||
54 | return $sql; |
|
55 | } |
|
56 | ||
57 | /** @inheritdoc */ |
|
58 | public function createDatabase(string $dbname, bool $ifNotExists = null, string $collate = null):array{ |
@@ 22-56 (lines=35) @@ | ||
19 | protected $quotes = ['"', '"']; |
|
20 | ||
21 | /** @inheritdoc */ |
|
22 | public function select(array $cols, array $from, string $where = null, $limit = null, $offset = null, bool $distinct = null, array $groupby, array $orderby):array{ |
|
23 | $sql = ['SELECT']; |
|
24 | ||
25 | if($distinct){ |
|
26 | $sql[] = 'DISTINCT'; |
|
27 | } |
|
28 | ||
29 | !empty($cols) |
|
30 | ? $sql[] = implode(', ', $cols) |
|
31 | : $sql[] = '*'; |
|
32 | ||
33 | $sql[] = 'FROM'; |
|
34 | $sql[] = implode(', ', $from); |
|
35 | $sql[] = $where; |
|
36 | ||
37 | if(!empty($groupby)){ |
|
38 | $sql[] = 'GROUP BY'; |
|
39 | $sql[] = implode(', ', $groupby); |
|
40 | } |
|
41 | ||
42 | if(!empty($orderby)){ |
|
43 | $sql[] = 'ORDER BY'; |
|
44 | $sql[] = implode(', ', $orderby); |
|
45 | } |
|
46 | ||
47 | if($offset !== null){ |
|
48 | $sql[] = 'OFFSET ?'; |
|
49 | } |
|
50 | ||
51 | if($limit !== null){ |
|
52 | $sql[] = 'LIMIT ?'; |
|
53 | } |
|
54 | ||
55 | return $sql; |
|
56 | } |
|
57 | ||
58 | /** |
|
59 | * @link https://www.postgresql.org/docs/9.5/static/sql-insert.html#SQL-ON-CONFLICT |