1
|
|
|
<?php
|
2
|
|
|
/**
|
3
|
|
|
* This file is part of the O2System Framework package.
|
4
|
|
|
*
|
5
|
|
|
* For the full copyright and license information, please view the LICENSE
|
6
|
|
|
* file that was distributed with this source code.
|
7
|
|
|
*
|
8
|
|
|
* @author Steeve Andrian Salim
|
9
|
|
|
* @copyright Copyright (c) Steeve Andrian Salim
|
10
|
|
|
*/
|
11
|
|
|
// ------------------------------------------------------------------------
|
12
|
|
|
|
13
|
|
|
namespace O2System\Database\NoSql\DataStructures\Query;
|
14
|
|
|
|
15
|
|
|
// ------------------------------------------------------------------------
|
16
|
|
|
|
17
|
|
|
use O2System\Spl\Traits\Collectors\ErrorCollectorTrait;
|
18
|
|
|
|
19
|
|
|
/**
|
20
|
|
|
* Class Statement
|
21
|
|
|
*
|
22
|
|
|
* @package O2System\Database\Sql\DataStructures
|
23
|
|
|
*/
|
24
|
|
|
class Statement
|
25
|
|
|
{
|
26
|
|
|
use ErrorCollectorTrait;
|
27
|
|
|
|
28
|
|
|
/**
|
29
|
|
|
* Statement::$builderCache
|
30
|
|
|
*
|
31
|
|
|
* @var \O2System\Database\NoSql\DataStructures\Query\BuilderCache
|
32
|
|
|
*/
|
33
|
|
|
private $builderCache;
|
34
|
|
|
|
35
|
|
|
/**
|
36
|
|
|
* Statement::$collection
|
37
|
|
|
*
|
38
|
|
|
* Query collection name.
|
39
|
|
|
*
|
40
|
|
|
* @var string
|
41
|
|
|
*/
|
42
|
|
|
private $collection;
|
43
|
|
|
|
44
|
|
|
/**
|
45
|
|
|
* Statement::$document
|
46
|
|
|
*
|
47
|
|
|
* Query document.
|
48
|
|
|
*
|
49
|
|
|
* @var array
|
50
|
|
|
*/
|
51
|
|
|
private $document = [];
|
52
|
|
|
|
53
|
|
|
/**
|
54
|
|
|
* Statement::$filter
|
55
|
|
|
*
|
56
|
|
|
* Query filter array.
|
57
|
|
|
*
|
58
|
|
|
* @var array
|
59
|
|
|
*/
|
60
|
|
|
private $filter = [];
|
61
|
|
|
|
62
|
|
|
/**
|
63
|
|
|
* Statement::$options
|
64
|
|
|
*
|
65
|
|
|
* Query options array.
|
66
|
|
|
*
|
67
|
|
|
* @var array
|
68
|
|
|
*/
|
69
|
|
|
private $options = [];
|
70
|
|
|
|
71
|
|
|
/**
|
72
|
|
|
* Statement::$startExecutionTime
|
73
|
|
|
*
|
74
|
|
|
* The start time in seconds with microseconds
|
75
|
|
|
* for when this query was executed.
|
76
|
|
|
*
|
77
|
|
|
* @var float
|
78
|
|
|
*/
|
79
|
|
|
private $startExecutionTime;
|
80
|
|
|
|
81
|
|
|
/**
|
82
|
|
|
* Statement::$endExecutionTime
|
83
|
|
|
*
|
84
|
|
|
* The end time in seconds with microseconds
|
85
|
|
|
* for when this query was executed.
|
86
|
|
|
*
|
87
|
|
|
* @var float
|
88
|
|
|
*/
|
89
|
|
|
private $endExecutionTime;
|
90
|
|
|
|
91
|
|
|
/**
|
92
|
|
|
* Statement::$affectedDocuments
|
93
|
|
|
*
|
94
|
|
|
* The numbers of affected documents.
|
95
|
|
|
*
|
96
|
|
|
* @var int
|
97
|
|
|
*/
|
98
|
|
|
private $affectedDocuments;
|
99
|
|
|
|
100
|
|
|
/**
|
101
|
|
|
* Statement::$lastInsertId
|
102
|
|
|
*
|
103
|
|
|
* The last insert id.
|
104
|
|
|
*
|
105
|
|
|
* @var string|int
|
106
|
|
|
*/
|
107
|
|
|
private $lastInsertId;
|
108
|
|
|
|
109
|
|
|
//--------------------------------------------------------------------
|
110
|
|
|
|
111
|
|
|
/**
|
112
|
|
|
* Statement::__construct
|
113
|
|
|
*
|
114
|
|
|
* @param \O2System\Database\NoSql\DataStructures\QueryBuilderCache $queryBuilderCache
|
115
|
|
|
*/
|
116
|
|
|
public function __construct(QueryBuilderCache $queryBuilderCache)
|
|
|
|
|
117
|
|
|
{
|
118
|
|
|
$this->builderCache = $queryBuilderCache;
|
119
|
|
|
$this->setCollection($queryBuilderCache->from);
|
120
|
|
|
|
121
|
|
|
if (count($queryBuilderCache->sets)) {
|
122
|
|
|
$this->document = $queryBuilderCache->sets;
|
123
|
|
|
}
|
124
|
|
|
}
|
125
|
|
|
|
126
|
|
|
//--------------------------------------------------------------------
|
127
|
|
|
|
128
|
|
|
/**
|
129
|
|
|
* Statement::getBuilderCache
|
130
|
|
|
*
|
131
|
|
|
* @return \O2System\Database\NoSql\DataStructures\Query\BuilderCache
|
132
|
|
|
*/
|
133
|
|
|
public function getBuilderCache()
|
134
|
|
|
{
|
135
|
|
|
return $this->builderCache;
|
136
|
|
|
}
|
137
|
|
|
|
138
|
|
|
//--------------------------------------------------------------------
|
139
|
|
|
|
140
|
|
|
/**
|
141
|
|
|
* Statement::getCollection
|
142
|
|
|
*
|
143
|
|
|
* Get Query Collection name
|
144
|
|
|
*
|
145
|
|
|
* @return string
|
146
|
|
|
*/
|
147
|
|
|
public function getCollection()
|
148
|
|
|
{
|
149
|
|
|
return $this->collection;
|
150
|
|
|
}
|
151
|
|
|
|
152
|
|
|
//--------------------------------------------------------------------
|
153
|
|
|
|
154
|
|
|
/**
|
155
|
|
|
* Statement::setCollection
|
156
|
|
|
*
|
157
|
|
|
* Set Query Collection name
|
158
|
|
|
*
|
159
|
|
|
* @param string $collection
|
160
|
|
|
*
|
161
|
|
|
* @return static
|
162
|
|
|
*/
|
163
|
|
|
public function setCollection($collection)
|
164
|
|
|
{
|
165
|
|
|
$this->collection = trim($collection);
|
166
|
|
|
|
167
|
|
|
return $this;
|
168
|
|
|
}
|
169
|
|
|
|
170
|
|
|
//--------------------------------------------------------------------
|
171
|
|
|
|
172
|
|
|
/**
|
173
|
|
|
* Statement::addFilter
|
174
|
|
|
*
|
175
|
|
|
* Add Query Filter
|
176
|
|
|
*
|
177
|
|
|
* @param string $field
|
178
|
|
|
* @param int $value
|
179
|
|
|
*
|
180
|
|
|
* @return static
|
181
|
|
|
*/
|
182
|
|
|
public function addFilter($field, $value)
|
183
|
|
|
{
|
184
|
|
|
$this->filter[ $field ] = $value;
|
185
|
|
|
|
186
|
|
|
return $this;
|
187
|
|
|
}
|
188
|
|
|
|
189
|
|
|
//--------------------------------------------------------------------
|
190
|
|
|
|
191
|
|
|
/**
|
192
|
|
|
* Statement::getFilter
|
193
|
|
|
*
|
194
|
|
|
* Get Query Filter
|
195
|
|
|
*
|
196
|
|
|
* @return array
|
197
|
|
|
*/
|
198
|
|
|
public function getFilter()
|
199
|
|
|
{
|
200
|
|
|
return $this->filter;
|
201
|
|
|
}
|
202
|
|
|
|
203
|
|
|
//--------------------------------------------------------------------
|
204
|
|
|
|
205
|
|
|
/**
|
206
|
|
|
* Statement::setFilter
|
207
|
|
|
*
|
208
|
|
|
* Set Query Filter Array
|
209
|
|
|
*
|
210
|
|
|
* @param array $filter
|
211
|
|
|
*
|
212
|
|
|
* @return static
|
213
|
|
|
*/
|
214
|
|
|
public function setFilter(array $filter)
|
215
|
|
|
{
|
216
|
|
|
$this->filter = $filter;
|
217
|
|
|
|
218
|
|
|
return $this;
|
219
|
|
|
}
|
220
|
|
|
|
221
|
|
|
//--------------------------------------------------------------------
|
222
|
|
|
|
223
|
|
|
/**
|
224
|
|
|
* Statement::addOption
|
225
|
|
|
*
|
226
|
|
|
* Add Query Option
|
227
|
|
|
*
|
228
|
|
|
* @param string $option
|
229
|
|
|
* @param mixed $value
|
230
|
|
|
*
|
231
|
|
|
* @return static
|
232
|
|
|
*/
|
233
|
|
|
public function addOption($option, $value)
|
234
|
|
|
{
|
235
|
|
|
$this->options[ $option ] = $value;
|
236
|
|
|
|
237
|
|
|
return $this;
|
238
|
|
|
}
|
239
|
|
|
|
240
|
|
|
//--------------------------------------------------------------------
|
241
|
|
|
|
242
|
|
|
/**
|
243
|
|
|
* Statement::getOptions
|
244
|
|
|
*
|
245
|
|
|
* Get Query Options
|
246
|
|
|
*
|
247
|
|
|
* @return array
|
248
|
|
|
*/
|
249
|
|
|
public function getOptions()
|
250
|
|
|
{
|
251
|
|
|
return $this->options;
|
252
|
|
|
}
|
253
|
|
|
|
254
|
|
|
//--------------------------------------------------------------------
|
255
|
|
|
|
256
|
|
|
/**
|
257
|
|
|
* Statement::setOptions
|
258
|
|
|
*
|
259
|
|
|
* Set Query Options
|
260
|
|
|
*
|
261
|
|
|
* @param array $options
|
262
|
|
|
*
|
263
|
|
|
* @return static
|
264
|
|
|
*/
|
265
|
|
|
public function setOptions(array $options)
|
266
|
|
|
{
|
267
|
|
|
$this->options = $options;
|
268
|
|
|
|
269
|
|
|
return $this;
|
270
|
|
|
}
|
271
|
|
|
|
272
|
|
|
//--------------------------------------------------------------------
|
273
|
|
|
|
274
|
|
|
/**
|
275
|
|
|
* Statement::getDocument
|
276
|
|
|
*
|
277
|
|
|
* Get Query Document
|
278
|
|
|
*
|
279
|
|
|
* @return array
|
280
|
|
|
*/
|
281
|
|
|
public function getDocument()
|
282
|
|
|
{
|
283
|
|
|
return $this->document;
|
284
|
|
|
}
|
285
|
|
|
|
286
|
|
|
//--------------------------------------------------------------------
|
287
|
|
|
|
288
|
|
|
/**
|
289
|
|
|
* Statement::setDuration
|
290
|
|
|
*
|
291
|
|
|
* Records the execution time of the statement using microtime(true)
|
292
|
|
|
* for it's start and end values. If no end value is present, will
|
293
|
|
|
* use the current time to determine total duration.
|
294
|
|
|
*
|
295
|
|
|
* @param int $start
|
296
|
|
|
* @param int|null $end
|
297
|
|
|
*
|
298
|
|
|
* @return static
|
299
|
|
|
*/
|
300
|
|
|
public function setDuration($start, $end = null)
|
301
|
|
|
{
|
302
|
|
|
$this->startExecutionTime = $start;
|
303
|
|
|
|
304
|
|
|
if (is_null($end)) {
|
305
|
|
|
$end = microtime(true);
|
306
|
|
|
}
|
307
|
|
|
|
308
|
|
|
$this->endExecutionTime = $end;
|
309
|
|
|
|
310
|
|
|
return $this;
|
311
|
|
|
}
|
312
|
|
|
|
313
|
|
|
//--------------------------------------------------------------------
|
314
|
|
|
|
315
|
|
|
/**
|
316
|
|
|
* Statement::getStartExecutionTime
|
317
|
|
|
*
|
318
|
|
|
* Returns the start time in seconds with microseconds.
|
319
|
|
|
*
|
320
|
|
|
* @param bool $numberFormat
|
321
|
|
|
* @param int $decimals
|
322
|
|
|
*
|
323
|
|
|
* @return mixed
|
324
|
|
|
*/
|
325
|
|
|
public function getStartExecutionTime($numberFormat = false, $decimals = 6)
|
326
|
|
|
{
|
327
|
|
|
if ( ! $numberFormat) {
|
328
|
|
|
return $this->startExecutionTime;
|
329
|
|
|
}
|
330
|
|
|
|
331
|
|
|
return number_format($this->startExecutionTime, $decimals);
|
332
|
|
|
}
|
333
|
|
|
|
334
|
|
|
//--------------------------------------------------------------------
|
335
|
|
|
|
336
|
|
|
/**
|
337
|
|
|
* Statement::getExecutionDuration
|
338
|
|
|
*
|
339
|
|
|
* Returns the duration of this query during execution, or null if
|
340
|
|
|
* the query has not been executed yet.
|
341
|
|
|
*
|
342
|
|
|
* @param int $decimals The accuracy of the returned time.
|
343
|
|
|
*
|
344
|
|
|
* @return mixed
|
345
|
|
|
*/
|
346
|
|
|
public function getExecutionDuration($decimals = 6)
|
347
|
|
|
{
|
348
|
|
|
return number_format(($this->endExecutionTime - $this->startExecutionTime), $decimals);
|
349
|
|
|
}
|
350
|
|
|
|
351
|
|
|
//--------------------------------------------------------------------
|
352
|
|
|
|
353
|
|
|
/**
|
354
|
|
|
* Statement::getAffectedRows
|
355
|
|
|
*
|
356
|
|
|
* Gets numbers of affected rows.
|
357
|
|
|
*
|
358
|
|
|
* @return int
|
359
|
|
|
*/
|
360
|
|
|
public function getAffectedDocuments()
|
361
|
|
|
{
|
362
|
|
|
return $this->affectedDocuments;
|
363
|
|
|
}
|
364
|
|
|
|
365
|
|
|
//--------------------------------------------------------------------
|
366
|
|
|
|
367
|
|
|
/**
|
368
|
|
|
* Statement::setAffectedRows
|
369
|
|
|
*
|
370
|
|
|
* Sets numbers of affected rows.
|
371
|
|
|
*
|
372
|
|
|
* @param int $affectedDocuments Numbers of affected rows,
|
373
|
|
|
*
|
374
|
|
|
* @return static
|
375
|
|
|
*/
|
376
|
|
|
public function setAffectedDocuments($affectedDocuments)
|
377
|
|
|
{
|
378
|
|
|
$this->affectedDocuments = $affectedDocuments;
|
379
|
|
|
|
380
|
|
|
return $this;
|
381
|
|
|
}
|
382
|
|
|
|
383
|
|
|
//--------------------------------------------------------------------
|
384
|
|
|
|
385
|
|
|
/**
|
386
|
|
|
* Statement::getAffectedRows
|
387
|
|
|
*
|
388
|
|
|
* Gets query last insert id.
|
389
|
|
|
*
|
390
|
|
|
* @return string|int
|
391
|
|
|
*/
|
392
|
|
|
public function getLastInsertId()
|
393
|
|
|
{
|
394
|
|
|
return $this->lastInsertId;
|
395
|
|
|
}
|
396
|
|
|
|
397
|
|
|
//--------------------------------------------------------------------
|
398
|
|
|
|
399
|
|
|
/**
|
400
|
|
|
* Statement::setAffectedRows
|
401
|
|
|
*
|
402
|
|
|
* Sets query last insert id.
|
403
|
|
|
*
|
404
|
|
|
* @param string|int
|
405
|
|
|
*
|
406
|
|
|
* @return static
|
407
|
|
|
*/
|
408
|
|
|
public function setLastInsertId($lastInsertId)
|
409
|
|
|
{
|
410
|
|
|
$this->lastInsertId = $lastInsertId;
|
411
|
|
|
|
412
|
|
|
return $this;
|
413
|
|
|
}
|
414
|
|
|
}
|
415
|
|
|
|
The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g.
excluded_paths: ["lib/*"]
, you can move it to the dependency path list as follows:For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths