1 | <?php |
||
28 | class SelectQuery extends Query implements MapperProvider, Countable |
||
29 | { |
||
30 | use Mappers; |
||
31 | use Conditions; |
||
32 | use Order; |
||
33 | use Range; |
||
34 | |||
35 | /** |
||
36 | * @var Driver |
||
37 | */ |
||
38 | protected $driver; |
||
39 | |||
40 | /** |
||
41 | * @var Table root Table of this query (from which JOIN clauses may extend the projection) |
||
42 | */ |
||
43 | protected $root; |
||
44 | |||
45 | /** |
||
46 | * @var string[] list of JOIN clauses extending from the root Table of this query |
||
47 | */ |
||
48 | protected $joins = []; |
||
49 | |||
50 | /** |
||
51 | * @var bool[] map where flag => true |
||
52 | */ |
||
53 | private $flags = []; |
||
54 | |||
55 | /** |
||
56 | * @var ReturnVars |
||
57 | */ |
||
58 | protected $return_vars; |
||
59 | |||
60 | /** |
||
61 | * @var string[] list of GROUP BY expressions |
||
62 | */ |
||
63 | protected $group_by = []; |
||
64 | |||
65 | /** |
||
66 | * @var string[] list of HAVING expressions |
||
67 | */ |
||
68 | protected $having = []; |
||
69 | |||
70 | /** |
||
71 | * @param Table $root |
||
72 | * @param Driver $driver |
||
73 | * @param TypeProvider $types |
||
74 | */ |
||
75 | 1 | public function __construct(Table $root, Driver $driver, TypeProvider $types) |
|
83 | |||
84 | /** |
||
85 | * Add all the Columns of a full Table to be selected and returned |
||
86 | * |
||
87 | * @param Table $table Table to select and return |
||
88 | * |
||
89 | * @return $this |
||
90 | */ |
||
91 | 1 | public function table(Table $table) |
|
97 | |||
98 | /** |
||
99 | * Add one or more Columns to select and return |
||
100 | * |
||
101 | * @param Column|Column[] one or more Columns to select and return |
||
102 | * |
||
103 | * @return $this |
||
104 | */ |
||
105 | 1 | public function columns($cols) |
|
111 | |||
112 | /** |
||
113 | * Add an SQL expression to select and return |
||
114 | * |
||
115 | * @param string $expr return expression |
||
116 | * @param string|null $name return variable name (optional, but usually required) |
||
117 | * @param Type|string|null $type optional Type (or Type class-name) |
||
118 | * |
||
119 | * @return $this |
||
120 | */ |
||
121 | 1 | public function value($expr, $name = null, $type = null) |
|
127 | |||
128 | /** |
||
129 | * Add an expression to apply to a GROUP BY clause |
||
130 | * |
||
131 | * @param Column|string $expr SQL expression (or Column object) to apply to the GROUP BY clause |
||
132 | * |
||
133 | * @return $this |
||
134 | */ |
||
135 | 1 | public function groupBy($expr) |
|
141 | |||
142 | /** |
||
143 | * @param string|string[] $exprs one or more condition expressions to apply to the HAVING clause |
||
144 | * |
||
145 | * @return $this |
||
146 | */ |
||
147 | 1 | public function having($exprs) |
|
155 | |||
156 | /** |
||
157 | * @inheritdoc |
||
158 | */ |
||
159 | 1 | public function getMappers() |
|
163 | |||
164 | /** |
||
165 | * @internal do not call this method directly from client-code (see `Countable` interface) |
||
166 | * |
||
167 | * @ignore |
||
168 | * |
||
169 | * @see Connection::count() |
||
170 | * |
||
171 | * @return SelectQuery |
||
172 | */ |
||
173 | 1 | public function createCountStatement() |
|
190 | |||
191 | /** |
||
192 | * @ignore string magic (enables creation of nested SELECT queries) |
||
193 | */ |
||
194 | 1 | public function __toString() |
|
198 | |||
199 | /** |
||
200 | * @param Table $table |
||
201 | * @param string $expr join condition |
||
202 | * |
||
203 | * @return $this |
||
204 | */ |
||
205 | 1 | public function innerJoin(Table $table, $expr) |
|
209 | |||
210 | /** |
||
211 | * @param Table $table |
||
212 | * @param string $expr join condition |
||
213 | * |
||
214 | * @return $this |
||
215 | */ |
||
216 | public function leftJoin(Table $table, $expr) |
||
220 | |||
221 | /** |
||
222 | * @param Table $table |
||
223 | * @param string $expr join condition |
||
224 | * |
||
225 | * @return $this |
||
226 | */ |
||
227 | public function rightJoin(Table $table, $expr) |
||
231 | |||
232 | /** |
||
233 | * @inheritdoc |
||
234 | */ |
||
235 | 1 | public function getSQL() |
|
267 | |||
268 | /** |
||
269 | * @param string $type join type ("INNER", "LEFT", etc.) |
||
270 | * @param Table $table |
||
271 | * @param string $expr join condition |
||
272 | * |
||
273 | * @return $this |
||
274 | */ |
||
275 | 1 | protected function addJoin($type, Table $table, $expr) |
|
283 | |||
284 | /** |
||
285 | * @param string $flag |
||
286 | * @param bool $state |
||
287 | */ |
||
288 | 1 | protected function setFlag($flag, $state = true) |
|
296 | |||
297 | /** |
||
298 | * @return string root table expression and JOIN clauses (for use in the FROM clause of an SQL statement) |
||
299 | */ |
||
300 | 1 | protected function buildNodes() |
|
304 | |||
305 | /** |
||
306 | * @return string query flags (such as "SQL_CALC_FOUND_ROWS" in a MySQL SELECT query) |
||
307 | */ |
||
308 | 1 | protected function buildFlags() |
|
312 | |||
313 | /** |
||
314 | * @return string combined condition expression (for use in the WHERE clause of an SQL statement) |
||
315 | */ |
||
316 | 1 | protected function buildHaving() |
|
320 | } |
||
321 |