|
1
|
|
|
<?php namespace AgelxNash\Modx\Evo\Database\Drivers; |
|
2
|
|
|
|
|
3
|
|
|
use AgelxNash\Modx\Evo\Database\Interfaces\DriverInterface; |
|
4
|
|
|
use AgelxNash\Modx\Evo\Database\Traits\ConfigTrait; |
|
5
|
|
|
|
|
6
|
|
|
abstract class AbstractDriver implements DriverInterface |
|
7
|
|
|
{ |
|
8
|
|
|
use ConfigTrait; |
|
9
|
|
|
|
|
10
|
|
|
/** |
|
11
|
|
|
* @var mixed |
|
12
|
|
|
*/ |
|
13
|
|
|
protected $conn; |
|
14
|
|
|
|
|
15
|
|
|
/** |
|
16
|
|
|
* {@inheritDoc} |
|
17
|
|
|
*/ |
|
18
|
|
|
abstract public function __construct(array $config = []); |
|
19
|
|
|
|
|
20
|
|
|
/** |
|
21
|
|
|
* {@inheritDoc} |
|
22
|
|
|
*/ |
|
23
|
|
|
abstract public function getConnect(); |
|
24
|
|
|
|
|
25
|
|
|
/** |
|
26
|
|
|
* {@inheritDoc} |
|
27
|
|
|
*/ |
|
28
|
|
|
abstract public function isConnected(); |
|
29
|
|
|
|
|
30
|
|
|
/** |
|
31
|
|
|
* {@inheritDoc} |
|
32
|
|
|
*/ |
|
33
|
|
|
abstract public function getLastError(); |
|
34
|
|
|
|
|
35
|
|
|
/** |
|
36
|
|
|
* {@inheritDoc} |
|
37
|
|
|
*/ |
|
38
|
|
|
abstract public function getLastErrorNo(); |
|
39
|
|
|
|
|
40
|
|
|
/** |
|
41
|
|
|
* {@inheritDoc} |
|
42
|
|
|
*/ |
|
43
|
|
|
abstract public function connect(); |
|
44
|
|
|
|
|
45
|
|
|
/** |
|
46
|
|
|
* {@inheritDoc} |
|
47
|
|
|
*/ |
|
48
|
|
|
abstract public function disconnect(); |
|
49
|
|
|
|
|
50
|
|
|
/** |
|
51
|
|
|
* {@inheritDoc} |
|
52
|
|
|
*/ |
|
53
|
|
|
abstract public function isResult($result); |
|
54
|
|
|
|
|
55
|
|
|
/** |
|
56
|
|
|
* {@inheritDoc} |
|
57
|
|
|
*/ |
|
58
|
|
|
abstract public function numFields($result); |
|
59
|
|
|
|
|
60
|
|
|
/** |
|
61
|
|
|
* {@inheritDoc} |
|
62
|
|
|
*/ |
|
63
|
|
|
abstract public function fieldName($result, $col = 0); |
|
64
|
|
|
|
|
65
|
|
|
/** |
|
66
|
|
|
* {@inheritDoc} |
|
67
|
|
|
*/ |
|
68
|
|
|
abstract public function setCharset($charset, $method = null); |
|
69
|
|
|
|
|
70
|
|
|
/** |
|
71
|
|
|
* {@inheritDoc} |
|
72
|
|
|
*/ |
|
73
|
|
|
abstract public function selectDb($name); |
|
74
|
|
|
|
|
75
|
|
|
/** |
|
76
|
|
|
* {@inheritDoc} |
|
77
|
|
|
*/ |
|
78
|
|
|
abstract public function escape($data); |
|
79
|
|
|
|
|
80
|
|
|
/** |
|
81
|
|
|
* {@inheritDoc} |
|
82
|
|
|
*/ |
|
83
|
|
|
abstract public function query($sql); |
|
84
|
|
|
|
|
85
|
|
|
/** |
|
86
|
|
|
* {@inheritDoc} |
|
87
|
|
|
*/ |
|
88
|
|
|
abstract public function getRecordCount($result); |
|
89
|
|
|
|
|
90
|
|
|
/** |
|
91
|
|
|
* {@inheritDoc} |
|
92
|
|
|
*/ |
|
93
|
|
|
abstract public function getRow($result, $mode = 'assoc'); |
|
94
|
|
|
|
|
95
|
|
|
/** |
|
96
|
|
|
* {@inheritDoc} |
|
97
|
|
|
*/ |
|
98
|
|
|
abstract public function getVersion(); |
|
99
|
|
|
|
|
100
|
|
|
/** |
|
101
|
|
|
* {@inheritDoc} |
|
102
|
|
|
*/ |
|
103
|
|
|
abstract public function getInsertId(); |
|
104
|
|
|
|
|
105
|
|
|
/** |
|
106
|
|
|
* {@inheritDoc} |
|
107
|
|
|
*/ |
|
108
|
|
|
abstract public function begin($flag = 0, $name = null); |
|
109
|
|
|
|
|
110
|
|
|
/** |
|
111
|
|
|
* {@inheritDoc} |
|
112
|
|
|
*/ |
|
113
|
|
|
abstract public function commit($flag = 0, $name = null); |
|
114
|
|
|
|
|
115
|
|
|
/** |
|
116
|
|
|
* {@inheritDoc} |
|
117
|
|
|
*/ |
|
118
|
|
|
abstract public function rollback($flag = 0, $name = null); |
|
119
|
|
|
|
|
120
|
|
|
/** |
|
121
|
|
|
* {@inheritDoc} |
|
122
|
|
|
*/ |
|
123
|
|
|
abstract public function getAffectedRows(); |
|
124
|
|
|
|
|
125
|
|
|
/** |
|
126
|
|
|
* {@inheritDoc} |
|
127
|
|
|
*/ |
|
128
|
6 |
|
public function getColumn($name, $result) |
|
129
|
|
|
{ |
|
130
|
6 |
|
$col = []; |
|
131
|
|
|
|
|
132
|
6 |
|
if ($this->isResult($result)) { |
|
133
|
6 |
|
while ($row = $this->getRow($result)) { |
|
134
|
6 |
|
if (array_key_exists($name, $row)) { |
|
135
|
6 |
|
$col[] = $row[$name]; |
|
136
|
|
|
} |
|
137
|
|
|
} |
|
138
|
|
|
} |
|
139
|
|
|
|
|
140
|
6 |
|
return $col; |
|
141
|
|
|
} |
|
142
|
|
|
|
|
143
|
|
|
/** |
|
144
|
|
|
* {@inheritDoc} |
|
145
|
|
|
*/ |
|
146
|
2 |
|
public function getColumnNames($result) |
|
147
|
|
|
{ |
|
148
|
2 |
|
$names = []; |
|
149
|
|
|
|
|
150
|
2 |
|
if ($this->isResult($result)) { |
|
151
|
2 |
|
$limit = $this->numFields($result); |
|
152
|
2 |
|
for ($i = 0; $i < $limit; $i++) { |
|
153
|
2 |
|
$names[] = $this->fieldName($result, $i); |
|
154
|
|
|
} |
|
155
|
|
|
} |
|
156
|
|
|
|
|
157
|
2 |
|
return $names; |
|
158
|
|
|
} |
|
159
|
|
|
|
|
160
|
|
|
/** |
|
161
|
|
|
* {@inheritDoc} |
|
162
|
|
|
*/ |
|
163
|
14 |
|
public function getValue($result) |
|
164
|
|
|
{ |
|
165
|
14 |
|
$out = false; |
|
166
|
|
|
|
|
167
|
14 |
|
if ($this->isResult($result)) { |
|
168
|
14 |
|
$result = $this->getRow($result, 'num'); |
|
169
|
14 |
|
$out = is_array($result) && array_key_exists(0, $result) ? $result[0] : false; |
|
170
|
|
|
} |
|
171
|
|
|
|
|
172
|
14 |
|
return $out; |
|
173
|
|
|
} |
|
174
|
|
|
|
|
175
|
|
|
/** |
|
176
|
|
|
* {@inheritDoc} |
|
177
|
|
|
*/ |
|
178
|
2 |
|
public function getTableMetaData($result) |
|
179
|
|
|
{ |
|
180
|
2 |
|
$out = []; |
|
181
|
|
|
|
|
182
|
2 |
|
if ($this->isResult($result)) { |
|
183
|
2 |
|
while ($row = $this->getRow($result)) { |
|
184
|
2 |
|
$fieldName = $row['Field']; |
|
185
|
2 |
|
$out[$fieldName] = $row; |
|
186
|
|
|
} |
|
187
|
|
|
} |
|
188
|
|
|
|
|
189
|
2 |
|
return $out; |
|
190
|
|
|
} |
|
191
|
|
|
|
|
192
|
|
|
|
|
193
|
|
|
|
|
194
|
|
|
/** |
|
195
|
|
|
* {@inheritDoc} |
|
196
|
|
|
*/ |
|
197
|
61 |
|
public function getTableName($table, $escape = true) |
|
198
|
|
|
{ |
|
199
|
61 |
|
if (empty($table)) { |
|
200
|
2 |
|
throw new Exceptions\TableNotDefinedException($table); |
|
|
|
|
|
|
201
|
|
|
} |
|
202
|
|
|
|
|
203
|
61 |
|
$out = $this->getConfig('prefix') . $table; |
|
204
|
|
|
|
|
205
|
61 |
|
return $escape ? '`' . $out . '`' : $out; |
|
206
|
|
|
} |
|
207
|
|
|
|
|
208
|
|
|
/** |
|
209
|
|
|
* {@inheritDoc} |
|
210
|
|
|
*/ |
|
211
|
59 |
|
public function getFullTableName($table) |
|
212
|
|
|
{ |
|
213
|
59 |
|
if (empty($table)) { |
|
214
|
1 |
|
throw new Exceptions\TableNotDefinedException($table); |
|
215
|
|
|
} |
|
216
|
|
|
|
|
217
|
59 |
|
return implode('.', [ |
|
218
|
59 |
|
'`' . $this->getConfig('database') . '`', |
|
219
|
59 |
|
$this->getTableName($table) |
|
220
|
|
|
]); |
|
221
|
|
|
} |
|
222
|
|
|
} |
|
223
|
|
|
|
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