Passed
Push — main ( 9d67f9...af7fe2 )
by Thierry
02:49
created

QueryTrait::execute()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 1
eloc 1
c 1
b 0
f 0
nc 1
nop 1
dl 0
loc 3
rs 10
1
<?php
2
3
namespace Lagdo\DbAdmin\Driver;
4
5
use Lagdo\DbAdmin\Driver\Entity\ConfigEntity;
6
use Lagdo\DbAdmin\Driver\Entity\TableEntity;
7
use Lagdo\DbAdmin\Driver\Entity\TableFieldEntity;
8
use Lagdo\DbAdmin\Driver\Entity\ForeignKeyEntity;
9
use Lagdo\DbAdmin\Driver\Entity\TriggerEntity;
10
use Lagdo\DbAdmin\Driver\Entity\RoutineEntity;
11
12
use Lagdo\DbAdmin\Driver\Db\ConnectionInterface;
13
use Lagdo\DbAdmin\Driver\Db\StatementInterface;
14
15
trait QueryTrait
16
{
17
    /**
18
     * Get logged user
19
     *
20
     * @return string
21
     */
22
    public function user()
23
    {
24
        return $this->query->user();
25
    }
26
27
    /**
28
     * Get current schema from the database
29
     *
30
     * @return string
31
     */
32
    // public function schema()
33
    // {
34
    //     return $this->query->schema();
35
    // }
36
37
    /**
38
     * Select data from table
39
     *
40
     * @param string $table
41
     * @param array $select Result of processSelectColumns()[0]
42
     * @param array $where Result of processSelectSearch()
43
     * @param array $group Result of processSelectColumns()[1]
44
     * @param array $order Result of processSelectOrder()
45
     * @param int $limit Result of processSelectLimit()
46
     * @param int $page Index of page starting at zero
47
     *
48
     * @return StatementInterface|bool
49
     */
50
    public function select(string $table, array $select, array $where,
51
        array $group, array $order = [], int $limit = 1, int $page = 0)
52
    {
53
        return $this->query->select($table, $select, $where, $group, $order, $limit, $page);
54
    }
55
56
    /**
57
     * Insert data into table
58
     *
59
     * @param string $table
60
     * @param array $set Escaped columns in keys, quoted data in values
61
     *
62
     * @return StatementInterface|bool
63
     */
64
    public function insert(string $table, array $set)
65
    {
66
        return $this->query->insert($table, $set);
67
    }
68
69
    /**
70
     * Update data in table
71
     *
72
     * @param string $table
73
     * @param array $set Escaped columns in keys, quoted data in values
74
     * @param string $queryWhere " WHERE ..."
75
     * @param int $limit 0 or 1
76
     * @param string $separator
77
     *
78
     * @return StatementInterface|bool
79
     */
80
    public function update(string $table, array $set, string $queryWhere, int $limit = 0, string $separator = "\n")
81
    {
82
        return $this->query->update($table, $set, $queryWhere, $limit, $separator);
83
    }
84
85
    /**
86
     * Delete data from table
87
     *
88
     * @param string $table
89
     * @param string $queryWhere " WHERE ..."
90
     * @param int $limit 0 or 1
91
     *
92
     * @return StatementInterface|bool
93
     */
94
    public function delete(string $table, string $queryWhere, int $limit = 0)
95
    {
96
        return $this->query->delete($table, $queryWhere, $limit);
97
    }
98
99
    /**
100
     * Insert or update data in table
101
     *
102
     * @param string $table
103
     * @param array $rows
104
     * @param array $primary of arrays with escaped columns in keys and quoted data in values
105
     *
106
     * @return StatementInterface|bool
107
     */
108
    public function insertOrUpdate(string $table, array $rows, array $primary)
109
    {
110
        return $this->query->insertOrUpdate($table, $rows, $primary);
111
    }
112
113
    /**
114
     * Get last auto increment ID
115
     *
116
     * @return string
117
     */
118
    public function lastAutoIncrementId()
119
    {
120
        return $this->query->lastAutoIncrementId();
121
    }
122
123
    /**
124
     * Return query with a timeout
125
     *
126
     * @param string $query
127
     * @param int $timeout In seconds
128
     *
129
     * @return string or null if the driver doesn't support query timeouts
130
     */
131
    public function slowQuery(string $query, int $timeout)
132
    {
133
        return $this->query->slowQuery($query, $timeout);
134
    }
135
136
    /**
137
     * Begin transaction
138
     *
139
     * @return StatementInterface|bool
140
     */
141
    public function begin()
142
    {
143
        return $this->query->begin();
144
    }
145
146
    /**
147
     * Commit transaction
148
     *
149
     * @return StatementInterface|bool
150
     */
151
    public function commit()
152
    {
153
        return $this->query->commit();
154
    }
155
156
    /**
157
     * Rollback transaction
158
     *
159
     * @return StatementInterface|bool
160
     */
161
    public function rollback()
162
    {
163
        return $this->query->rollback();
164
    }
165
166
    /**
167
     * Set the error message
168
     *
169
     * @param string $error
170
     *
171
     * @return void
172
     */
173
    public function setError(string $error = '')
174
    {
175
        return $this->query->setError($error);
176
    }
177
178
    /**
179
     * Get the raw error message
180
     *
181
     * @return string
182
     */
183
    public function error()
184
    {
185
        return $this->query->error();
186
    }
187
188
    /**
189
     * Check if the last query returned an error message
190
     *
191
     * @return bool
192
     */
193
    public function hasError()
194
    {
195
        return $this->query->hasError();
196
    }
197
198
    /**
199
     * Set the error number
200
     *
201
     * @param int $errno
202
     *
203
     * @return void
204
     */
205
    public function setErrno(int $errno)
206
    {
207
        return $this->query->setErrno($errno);
208
    }
209
210
    /**
211
     * Get the last error number
212
     *
213
     * @return string
214
     */
215
    public function errno()
216
    {
217
        return $this->query->errno();
218
    }
219
220
    /**
221
     * Check if the last query returned an error number
222
     *
223
     * @return bool
224
     */
225
    public function hasErrno()
226
    {
227
        return $this->query->hasErrno();
228
    }
229
230
    /**
231
     * Set the number of rows affected by the last query
232
     *
233
     * @param int $affectedRows
234
     *
235
     * @return void
236
     */
237
    public function setAffectedRows(int $affectedRows)
238
    {
239
        return $this->query->setAffectedRows($affectedRows);
240
    }
241
242
    /**
243
     * Get the number of rows affected by the last query
244
     *
245
     * @return integer
246
     */
247
    public function affectedRows()
248
    {
249
        return $this->query->affectedRows();
250
    }
251
252
    /**
253
     * Execute and remember query
254
     *
255
     * @param string $query
256
     *
257
     * @return StatementInterface|bool
258
     */
259
    public function execute(string $query)
260
    {
261
        return $this->query->execute($query);
262
    }
263
264
    /**
265
     * Get the remembered queries
266
     *
267
     * @return array
268
     */
269
    public function queries()
270
    {
271
        return $this->query->queries();
272
    }
273
274
    /**
275
     * Apply command to all array items
276
     *
277
     * @param string $query
278
     * @param array $tables
279
     * @param callback|null $escape
280
     *
281
     * @return bool
282
     */
283
    public function applyQueries(string $query, array $tables, $escape = null)
284
    {
285
        return $this->query->applyQueries($query, $tables, $escape);
286
    }
287
288
    /**
289
     * Get list of values from database
290
     *
291
     * @param string $query
292
     * @param string|int $column
293
     *
294
     * @return array
295
     */
296
    public function values(string $query, $column = 0)
297
    {
298
        return $this->query->values($query, $column);
299
    }
300
301
    /**
302
     * Get keys from first column and values from second
303
     *
304
     * @param string $query
305
     * @param ConnectionInterface $connection
306
     * @param bool $setKeys
307
     *
308
     * @return array
309
     */
310
    public function keyValues(string $query, ConnectionInterface $connection = null, bool $setKeys = true)
311
    {
312
        return $this->query->keyValues($query, $connection, $setKeys);
313
    }
314
315
    /**
316
     * Get all rows of result
317
     *
318
     * @param string $query
319
     * @param ConnectionInterface $connection
320
     *
321
     * @return array
322
     */
323
    public function rows(string $query, ConnectionInterface $connection = null)
324
    {
325
        return $this->query->rows($query, $connection);
326
    }
327
328
    /**
329
     * Remove current user definer from SQL command
330
     *
331
     * @param string $query
332
     *
333
     * @return string
334
     */
335
    public function removeDefiner(string $query)
336
    {
337
        return $this->query->removeDefiner($query);
338
    }
339
340
    /**
341
     * Explain select
342
     *
343
     * @param ConnectionInterface $connection
344
     * @param string $query
345
     *
346
     * @return Statement|null
0 ignored issues
show
Bug introduced by
The type Lagdo\DbAdmin\Driver\Statement was not found. Maybe you did not declare it correctly or list all dependencies?

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:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
347
     */
348
    public function explain(ConnectionInterface $connection, string $query)
349
    {
350
        return $this->query->explain($connection, $query);
351
    }
352
353
    /**
354
     * Get approximate number of rows
355
     *
356
     * @param TableEntity $tableStatus
357
     * @param array $where
358
     *
359
     * @return int|null
360
     */
361
    public function countRows(TableEntity $tableStatus, array $where)
362
    {
363
        return $this->query->countRows($tableStatus, $where);
364
    }
365
366
    /**
367
     * Convert column to be searchable
368
     *
369
     * @param string $idf Escaped column name
370
     * @param array $value ["op" => , "val" => ]
371
     * @param TableFieldEntity $field
372
     *
373
     * @return string
374
     */
375
    public function convertSearch(string $idf, array $value, TableFieldEntity $field)
376
    {
377
        return $this->query->convertSearch($idf, $value, $field);
378
    }
379
380
    /**
381
     * Get view SELECT
382
     *
383
     * @param string $name
384
     *
385
     * @return array array("select" => )
386
     */
387
    public function view(string $name)
388
    {
389
        return $this->query->view($name);
390
    }
391
}
392