|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
namespace Jpina\PdoOci8; |
|
4
|
|
|
|
|
5
|
|
|
use Jpina\Oci8\Oci8Connection; |
|
6
|
|
|
use Jpina\Oci8\Oci8ConnectionInterface; |
|
7
|
|
|
use Jpina\Oci8\Oci8Exception; |
|
8
|
|
|
use Jpina\Oci8\Oci8PersistentConnection; |
|
9
|
|
|
use Jpina\Oci8\Oci8StatementInterface; |
|
10
|
|
|
|
|
11
|
|
|
/** |
|
12
|
|
|
* Custom PDO_OCI implementation via OCI8 driver |
|
13
|
|
|
* |
|
14
|
|
|
* @see http://php.net/manual/en/class.pdo.php |
|
15
|
|
|
*/ |
|
16
|
|
|
class PdoOci8 extends \PDO |
|
17
|
|
|
{ |
|
18
|
|
|
const OCI_ATTR_SESSION_MODE = 8000; |
|
19
|
|
|
|
|
20
|
|
|
const OCI_ATTR_RETURN_LOBS = 8001; |
|
21
|
|
|
|
|
22
|
|
|
/** |
|
23
|
|
|
* @var Oci8ConnectionInterface |
|
24
|
|
|
*/ |
|
25
|
|
|
protected $connection; |
|
26
|
|
|
|
|
27
|
|
|
/** |
|
28
|
|
|
* @var int |
|
29
|
|
|
*/ |
|
30
|
|
|
private $autoCommitMode = false; |
|
|
|
|
|
|
31
|
|
|
|
|
32
|
|
|
/** |
|
33
|
|
|
* @var array |
|
34
|
|
|
*/ |
|
35
|
|
|
protected $options = array(); |
|
36
|
|
|
|
|
37
|
|
|
// TODO Receive Oci8ConnectionInterface? |
|
38
|
13 |
|
public function __construct($dsn, $username = '', $password = '', $options = array()) |
|
39
|
|
|
{ |
|
40
|
13 |
|
$this->options = array( |
|
41
|
13 |
|
\PDO::ATTR_AUTOCOMMIT => true, |
|
42
|
13 |
|
\PDO::ATTR_CASE => \PDO::CASE_NATURAL, |
|
43
|
13 |
|
\PDO::ATTR_CLIENT_VERSION => '', |
|
44
|
13 |
|
\PDO::ATTR_CONNECTION_STATUS => '', |
|
45
|
13 |
|
\PDO::ATTR_DRIVER_NAME => 'oci', |
|
46
|
13 |
|
\PDO::ATTR_ERRMODE => \PDO::ERRMODE_SILENT, |
|
47
|
13 |
|
\PDO::ATTR_ORACLE_NULLS => \PDO::NULL_NATURAL, |
|
48
|
13 |
|
\PDO::ATTR_PERSISTENT => false, |
|
49
|
13 |
|
\PDO::ATTR_PREFETCH => 100, |
|
50
|
13 |
|
\PDO::ATTR_SERVER_INFO => '', |
|
51
|
13 |
|
\PDO::ATTR_SERVER_VERSION => '', |
|
52
|
13 |
|
\PDO::ATTR_TIMEOUT => 600, |
|
53
|
13 |
|
\PDO::ATTR_STRINGIFY_FETCHES => false, |
|
54
|
13 |
|
\PDO::ATTR_STATEMENT_CLASS => null, |
|
55
|
13 |
|
\PDO::ATTR_EMULATE_PREPARES => false, |
|
56
|
13 |
|
\PDO::ATTR_DEFAULT_FETCH_MODE => \PDO::FETCH_BOTH, |
|
57
|
13 |
|
static::OCI_ATTR_SESSION_MODE => OCI_DEFAULT, |
|
58
|
13 |
|
static::OCI_ATTR_RETURN_LOBS => false, |
|
59
|
|
|
); |
|
60
|
|
|
|
|
61
|
13 |
View Code Duplication |
foreach ($options as $option => $value) { |
|
|
|
|
|
|
62
|
3 |
|
if (array_key_exists($option, $this->options)) { |
|
63
|
3 |
|
$this->options[$option] = $value; |
|
64
|
3 |
|
} |
|
65
|
13 |
|
} |
|
66
|
|
|
|
|
67
|
13 |
|
foreach ($options as $attribute => $value) { |
|
68
|
3 |
|
$this->setAttribute($attribute, $value); |
|
69
|
13 |
|
} |
|
70
|
|
|
|
|
71
|
13 |
|
$connection = $this->getOracleConnection($dsn, $username, $password); |
|
72
|
11 |
|
$this->setAttribute(\PDO::ATTR_CLIENT_VERSION, $connection->getClientVersion()); |
|
73
|
11 |
|
$this->setAttribute(\PDO::ATTR_SERVER_VERSION, $connection->getServerVersion()); |
|
74
|
|
|
|
|
75
|
11 |
|
if ($this->getAttribute(\PDO::ATTR_AUTOCOMMIT) === false) { |
|
76
|
|
|
$this->beginTransaction(); |
|
77
|
|
|
} |
|
78
|
|
|
|
|
79
|
11 |
|
$this->connection = $connection; |
|
80
|
11 |
|
} |
|
81
|
|
|
|
|
82
|
12 |
|
protected function getCharset($dsn) |
|
83
|
|
|
{ |
|
84
|
12 |
|
$connectionStringItems = $this->getConnectionStringItems($dsn); |
|
85
|
|
|
|
|
86
|
12 |
|
return $connectionStringItems['charset']; |
|
87
|
|
|
} |
|
88
|
|
|
|
|
89
|
|
|
/** |
|
90
|
|
|
* @return Oci8ConnectionInterface |
|
91
|
|
|
*/ |
|
92
|
42 |
|
protected function getConnection() |
|
93
|
|
|
{ |
|
94
|
42 |
|
return $this->connection; |
|
95
|
|
|
} |
|
96
|
|
|
|
|
97
|
|
|
/** |
|
98
|
|
|
* @param string $dsn |
|
99
|
|
|
* @param string $username |
|
100
|
|
|
* @param string $password |
|
101
|
|
|
* @return Oci8ConnectionInterface |
|
102
|
|
|
*/ |
|
103
|
13 |
|
protected function getOracleConnection($dsn, $username = null, $password = null) |
|
104
|
|
|
{ |
|
105
|
13 |
|
$connectionString = $this->getConnectionString($dsn); |
|
106
|
12 |
|
$charset = $this->getCharset($dsn); |
|
107
|
12 |
|
$sessionMode = $this->getAttribute(static::OCI_ATTR_SESSION_MODE); |
|
108
|
|
|
|
|
109
|
12 |
|
$connection = null; |
|
110
|
|
|
try { |
|
111
|
12 |
|
if ($this->getAttribute(\PDO::ATTR_PERSISTENT)) { |
|
112
|
1 |
|
$connection = new Oci8PersistentConnection( |
|
113
|
1 |
|
$username, |
|
114
|
1 |
|
$password, |
|
115
|
1 |
|
$connectionString, |
|
116
|
1 |
|
$charset, |
|
117
|
|
|
$sessionMode |
|
118
|
1 |
|
); |
|
119
|
1 |
|
} else { |
|
120
|
11 |
|
$connection = new Oci8Connection( |
|
121
|
11 |
|
$username, |
|
122
|
11 |
|
$password, |
|
123
|
11 |
|
$connectionString, |
|
124
|
11 |
|
$charset, |
|
125
|
|
|
$sessionMode |
|
126
|
11 |
|
); |
|
127
|
|
|
} |
|
128
|
12 |
|
} catch (Oci8Exception $ex) { |
|
129
|
1 |
|
throw new PdoOci8Exception($ex->getMessage(), $ex->getCode(), $ex); |
|
130
|
|
|
} |
|
131
|
|
|
|
|
132
|
11 |
|
return $connection; |
|
133
|
|
|
} |
|
134
|
|
|
|
|
135
|
13 |
|
protected function getConnectionString($dsn) |
|
136
|
|
|
{ |
|
137
|
13 |
|
$connectionStringItems = $this->getConnectionStringItems($dsn); |
|
138
|
12 |
|
$hostname = $connectionStringItems['hostname']; |
|
139
|
12 |
|
$port = $connectionStringItems['port']; |
|
140
|
12 |
|
$database = $connectionStringItems['database']; |
|
141
|
12 |
|
$connectionString = "//{$hostname}:{$port}/{$database}"; |
|
142
|
|
|
|
|
143
|
12 |
|
return $connectionString; |
|
144
|
|
|
} |
|
145
|
|
|
|
|
146
|
13 |
|
protected function getConnectionStringItems($dsn) |
|
147
|
|
|
{ |
|
148
|
13 |
|
$dsnRegex = $this->getDsnRegex(); |
|
149
|
13 |
|
$matches = array(); |
|
150
|
13 |
|
if (preg_match("/^{$dsnRegex}$/i", $dsn, $matches) !== 1) { |
|
151
|
1 |
|
throw new PdoOci8Exception('Invalid DSN'); |
|
152
|
|
|
} |
|
153
|
|
|
|
|
154
|
|
|
// TODO Remove the variables below |
|
155
|
12 |
|
$hostname = 'localhost'; |
|
156
|
12 |
|
$port = 1521; |
|
157
|
12 |
|
$database = null; |
|
|
|
|
|
|
158
|
12 |
|
$charset = 'AL32UTF8'; |
|
159
|
|
|
|
|
160
|
12 |
|
switch (count($matches)) { |
|
161
|
12 |
|
case 16: |
|
162
|
10 |
|
$charset = empty($matches[15]) ? $charset : $matches[15]; |
|
163
|
|
|
// fall through next case to get the rest of the variables |
|
164
|
12 |
|
case 14: |
|
165
|
12 |
|
$port = empty($matches[12]) ? $port : (int)$matches[12]; |
|
166
|
12 |
|
$hostname = $matches[4]; |
|
167
|
12 |
|
$database = $matches[13]; |
|
168
|
12 |
|
break; |
|
169
|
|
|
default: |
|
170
|
|
|
$database = $matches[1]; |
|
171
|
12 |
|
} |
|
172
|
|
|
|
|
173
|
|
|
return array( |
|
174
|
12 |
|
'hostname' => $hostname, |
|
175
|
12 |
|
'port' => $port, |
|
176
|
12 |
|
'database' => $database, |
|
177
|
12 |
|
'charset' => $charset, |
|
178
|
12 |
|
); |
|
179
|
|
|
} |
|
180
|
|
|
|
|
181
|
13 |
|
protected function getDsnRegex() |
|
182
|
|
|
{ |
|
183
|
13 |
|
$hostnameRegrex = "(([a-z]|[a-z][a-z0-9\-_]*[a-z0-9])\.)*([a-z]|[a-z][a-z0-9\-_]*[a-z0-9])"; |
|
184
|
|
|
$validIpAddressRegex = "(([0-9]|[1-9][0-9]|1[0-9]{2}|2[0-4][0-9]|25[0-5])\.){3}" . |
|
185
|
13 |
|
"([0-9]|[1-9][0-9]|1[0-9]{2}|2[0-4][0-9]|25[0-5])"; |
|
186
|
13 |
|
$hostnameOrIpAddressRegrex = "\/\/({$hostnameRegrex}|{$validIpAddressRegex})"; |
|
187
|
13 |
|
$databaseRegex = "([a-z_][a-z\-_\d]*)|({$hostnameOrIpAddressRegrex}(:(\d+))?\/([a-z_][a-z\-_\d]*))"; |
|
188
|
13 |
|
$charsetRegex = "(charset=([a-z\d\-_]+))?"; |
|
189
|
13 |
|
$dsnRegex = "oci\:database=({$databaseRegex});?{$charsetRegex}"; |
|
190
|
|
|
|
|
191
|
13 |
|
return $dsnRegex; |
|
192
|
|
|
} |
|
193
|
|
|
|
|
194
|
|
|
/** |
|
195
|
|
|
* @link http://php.net/manual/en/pdo.begintransaction.php |
|
196
|
|
|
* @return bool |
|
197
|
|
|
*/ |
|
198
|
4 |
|
public function beginTransaction() |
|
199
|
|
|
{ |
|
200
|
4 |
|
if ($this->getAttribute(\PDO::ATTR_AUTOCOMMIT) === false) { |
|
201
|
1 |
|
return false; |
|
202
|
|
|
} |
|
203
|
|
|
|
|
204
|
4 |
|
return $this->setAttribute(\PDO::ATTR_AUTOCOMMIT, false); |
|
205
|
|
|
} |
|
206
|
|
|
|
|
207
|
|
|
/** |
|
208
|
|
|
* @link http://php.net/manual/en/pdo.commit.php |
|
209
|
|
|
* @return bool |
|
210
|
|
|
*/ |
|
211
|
1 |
|
public function commit() |
|
212
|
|
|
{ |
|
213
|
|
|
try { |
|
214
|
1 |
|
$isSuccess = $this->getConnection()->commit(); |
|
215
|
1 |
|
} catch (Oci8Exception $ex) { |
|
216
|
|
|
$isSuccess = false; |
|
217
|
|
|
} |
|
218
|
|
|
|
|
219
|
1 |
|
$this->setAttribute(\PDO::ATTR_AUTOCOMMIT, true); |
|
220
|
|
|
|
|
221
|
1 |
|
return $isSuccess; |
|
222
|
|
|
} |
|
223
|
|
|
|
|
224
|
|
|
/** |
|
225
|
|
|
* @link http://php.net/manual/en/pdo.errorcode.php |
|
226
|
|
|
* @return null|string |
|
227
|
|
|
*/ |
|
228
|
1 |
View Code Duplication |
public function errorCode() |
|
|
|
|
|
|
229
|
|
|
{ |
|
230
|
1 |
|
$connection = $this->getConnection(); |
|
231
|
1 |
|
$driverError = $connection->getError(); |
|
232
|
1 |
|
if (!$driverError) { |
|
233
|
1 |
|
return null; |
|
234
|
|
|
} |
|
235
|
|
|
|
|
236
|
|
|
$error = $this->errorInfo(); |
|
237
|
|
|
$sqlStateErrorCode = $error[0]; |
|
238
|
|
|
|
|
239
|
|
|
return $sqlStateErrorCode; |
|
240
|
|
|
} |
|
241
|
|
|
|
|
242
|
|
|
/** |
|
243
|
|
|
* @link http://php.net/manual/en/pdo.errorinfo.php |
|
244
|
|
|
* @return array |
|
245
|
|
|
*/ |
|
246
|
1 |
|
public function errorInfo() |
|
247
|
|
|
{ |
|
248
|
1 |
|
$error = $this->getConnection()->getError(); |
|
249
|
1 |
|
if (is_array($error)) { |
|
250
|
|
|
$errorInfo = array( |
|
251
|
|
|
OracleSqlStateCode::getSqlStateErrorCode((int)$error['code']), |
|
252
|
|
|
$error['message'], |
|
253
|
|
|
$error['code'] |
|
254
|
|
|
); |
|
255
|
|
|
} else { |
|
256
|
|
|
$errorInfo = array( |
|
257
|
1 |
|
'00000', |
|
258
|
1 |
|
null, |
|
259
|
|
|
null |
|
260
|
1 |
|
); |
|
261
|
|
|
} |
|
262
|
|
|
|
|
263
|
1 |
|
return $errorInfo; |
|
264
|
|
|
} |
|
265
|
|
|
|
|
266
|
|
|
/** |
|
267
|
|
|
* @param string $statement |
|
268
|
|
|
* |
|
269
|
|
|
* @link http://php.net/manual/en/pdo.exec.php |
|
270
|
|
|
* @return bool|int |
|
271
|
|
|
*/ |
|
272
|
4 |
|
public function exec($statement) |
|
273
|
|
|
{ |
|
274
|
4 |
|
$statement = $this->prepare($statement, $this->options); |
|
275
|
4 |
|
$type = $this->getStatementType($statement); |
|
276
|
4 |
|
if ($type === 'SELECT') { |
|
277
|
1 |
|
return false; |
|
|
|
|
|
|
278
|
|
|
} |
|
279
|
3 |
|
$statement->execute(); |
|
280
|
|
|
|
|
281
|
3 |
|
return $statement->rowCount(); |
|
282
|
|
|
} |
|
283
|
|
|
|
|
284
|
|
|
/** |
|
285
|
|
|
* @param $statement |
|
286
|
|
|
* @return PdoOci8Statement |
|
287
|
|
|
*/ |
|
288
|
4 |
|
protected function getStatementType($statement) |
|
289
|
|
|
{ |
|
290
|
4 |
|
$class = new \ReflectionClass($statement); |
|
291
|
4 |
|
$property = $class->getProperty('statement'); |
|
292
|
4 |
|
$property->setAccessible(true); |
|
293
|
|
|
/** @var Oci8StatementInterface $rawStatement */ |
|
294
|
4 |
|
$oci8Statement = $property->getValue($statement); |
|
295
|
|
|
|
|
296
|
4 |
|
return $oci8Statement->getType(); |
|
297
|
|
|
} |
|
298
|
|
|
|
|
299
|
|
|
/** |
|
300
|
|
|
* @param int $attribute |
|
301
|
|
|
* |
|
302
|
|
|
* @link http://php.net/manual/en/pdo.getattribute.php |
|
303
|
|
|
* @return mixed |
|
304
|
|
|
*/ |
|
305
|
12 |
|
public function getAttribute($attribute) |
|
306
|
|
|
{ |
|
307
|
12 |
|
if (array_key_exists($attribute, $this->options)) { |
|
308
|
12 |
|
return $this->options[$attribute]; |
|
309
|
|
|
} |
|
310
|
|
|
|
|
311
|
|
|
return null; |
|
312
|
|
|
} |
|
313
|
|
|
|
|
314
|
|
|
/** |
|
315
|
|
|
* @link http://php.net/manual/en/pdo.getavailabledrivers.php |
|
316
|
|
|
* @return array |
|
317
|
|
|
*/ |
|
318
|
1 |
|
public static function getAvailableDrivers() |
|
319
|
|
|
{ |
|
320
|
1 |
|
return array('oci'); |
|
321
|
|
|
} |
|
322
|
|
|
|
|
323
|
|
|
/** |
|
324
|
|
|
* @link http://php.net/manual/en/pdo.intransaction.php |
|
325
|
|
|
* @return bool |
|
326
|
|
|
*/ |
|
327
|
3 |
|
public function inTransaction() |
|
328
|
|
|
{ |
|
329
|
3 |
|
$inTransaction = !$this->getAttribute(\PDO::ATTR_AUTOCOMMIT); |
|
330
|
3 |
|
return $inTransaction; |
|
331
|
|
|
} |
|
332
|
|
|
|
|
333
|
|
|
/** |
|
334
|
|
|
* @param string $name |
|
335
|
|
|
* |
|
336
|
|
|
* @link http://php.net/manual/en/pdo.lastinsertid.php |
|
337
|
|
|
* @return string |
|
338
|
|
|
*/ |
|
339
|
|
|
public function lastInsertId($name = null) |
|
340
|
|
|
{ |
|
341
|
|
|
$statement = $this->query("select {$name}.currval from dual"); |
|
342
|
|
|
$lastInsertedId = $statement->fetch(); |
|
343
|
|
|
|
|
344
|
|
|
return $lastInsertedId; |
|
345
|
|
|
} |
|
346
|
|
|
|
|
347
|
|
|
/** |
|
348
|
|
|
* @param string $statement |
|
349
|
|
|
* @param array $driver_options |
|
350
|
|
|
* |
|
351
|
|
|
* @link http://php.net/manual/en/pdo.prepare.php |
|
352
|
|
|
* @return bool|PdoOci8Statement |
|
353
|
|
|
*/ |
|
354
|
38 |
|
public function prepare($statement, $driver_options = array()) |
|
355
|
|
|
{ |
|
356
|
|
|
// TODO Use $driver_options, eg. configure a cursor |
|
357
|
38 |
|
$exception = null; |
|
|
|
|
|
|
358
|
|
|
try { |
|
359
|
38 |
|
return new PdoOci8Statement($this->getConnection(), $statement, $driver_options); |
|
|
|
|
|
|
360
|
|
|
} catch (\Exception $ex) { |
|
361
|
|
|
$exception = new PdoOci8Exception($ex->getMessage(), $ex->getCode(), $ex); |
|
362
|
|
|
} |
|
363
|
|
|
|
|
364
|
|
|
// TODO Create error handler |
|
365
|
|
|
$errorMode = $this->getAttribute(\PDO::ATTR_ERRMODE); |
|
366
|
|
|
switch ($errorMode) { |
|
367
|
|
|
case \PDO::ERRMODE_EXCEPTION: |
|
368
|
|
|
throw $exception; |
|
369
|
|
|
case \PDO::ERRMODE_WARNING: |
|
370
|
|
|
trigger_error($exception->getMessage(), E_WARNING); |
|
371
|
|
|
break; |
|
372
|
|
|
case \PDO::ERRMODE_SILENT: |
|
373
|
|
|
default: |
|
374
|
|
|
} |
|
375
|
|
|
|
|
376
|
|
|
return false; |
|
|
|
|
|
|
377
|
|
|
} |
|
378
|
|
|
|
|
379
|
|
|
/** |
|
380
|
|
|
* @param string $statement |
|
381
|
|
|
* @param int $mode |
|
382
|
|
|
* @param int|string|object $arg3 |
|
383
|
|
|
* @param array $ctorargs |
|
384
|
|
|
* |
|
385
|
|
|
* @link http://php.net/manual/en/pdo.query.php |
|
386
|
|
|
* @return bool|PdoOci8Statement |
|
387
|
|
|
*/ |
|
388
|
3 |
|
public function query($statement, $mode = \PDO::ATTR_DEFAULT_FETCH_MODE, $arg3 = null, $ctorargs = array()) |
|
389
|
|
|
{ |
|
390
|
3 |
|
$result = false; |
|
391
|
|
|
try { |
|
392
|
3 |
|
$statement = $this->prepare($statement); |
|
393
|
|
|
switch ($mode) { |
|
394
|
3 |
|
case \PDO::FETCH_CLASS: |
|
395
|
|
|
$statement->setFetchMode($mode, $arg3, $ctorargs); |
|
396
|
|
|
break; |
|
397
|
3 |
|
case \PDO::FETCH_INTO: |
|
398
|
|
|
$statement->setFetchMode($mode, $arg3); |
|
399
|
|
|
break; |
|
400
|
3 |
|
case \PDO::FETCH_COLUMN: |
|
401
|
3 |
|
default: |
|
402
|
3 |
|
$statement->setFetchMode($mode); |
|
403
|
3 |
|
} |
|
404
|
3 |
|
$statement->execute(); |
|
405
|
3 |
|
$result = $statement; |
|
406
|
3 |
|
} catch (\PDOException $ex) { |
|
407
|
|
|
//TODO Handle Exception |
|
408
|
|
|
} |
|
409
|
|
|
|
|
410
|
3 |
|
return $result; |
|
|
|
|
|
|
411
|
|
|
} |
|
412
|
|
|
|
|
413
|
|
|
/** |
|
414
|
|
|
* @param string $string |
|
415
|
|
|
* @param int $parameter_type |
|
416
|
|
|
* |
|
417
|
|
|
* @link http://php.net/manual/en/pdo.quote.php |
|
418
|
|
|
* @return bool|string |
|
419
|
|
|
*/ |
|
420
|
5 |
|
public function quote($string, $parameter_type = \PDO::PARAM_STR) |
|
421
|
|
|
{ |
|
422
|
5 |
|
if (!is_scalar($string)) { |
|
423
|
1 |
|
return false; |
|
|
|
|
|
|
424
|
|
|
} |
|
425
|
|
|
|
|
426
|
|
|
try { |
|
427
|
4 |
|
if ($parameter_type !== \PDO::PARAM_STR) { |
|
428
|
1 |
|
$quotedString = (string)$string; |
|
429
|
1 |
|
$quotedString = "'" . $quotedString . "'"; |
|
430
|
1 |
|
return $quotedString; |
|
431
|
|
|
} |
|
432
|
4 |
|
} catch (\Exception $ex) { |
|
|
|
|
|
|
433
|
|
|
return false; |
|
434
|
|
|
} |
|
435
|
|
|
|
|
436
|
4 |
|
$quotedString = str_replace("\'", "'", $string); |
|
437
|
4 |
|
$quotedString = str_replace("'", "''", $quotedString); |
|
438
|
4 |
|
$quotedString = "'" . $quotedString . "'"; |
|
439
|
|
|
|
|
440
|
4 |
|
return $quotedString; |
|
441
|
|
|
} |
|
442
|
|
|
|
|
443
|
|
|
/** |
|
444
|
|
|
* @link http://php.net/manual/en/pdo.rollback.php |
|
445
|
|
|
* @return bool |
|
446
|
|
|
*/ |
|
447
|
2 |
|
public function rollback() |
|
448
|
|
|
{ |
|
449
|
2 |
|
if (!$this->inTransaction()) { |
|
450
|
1 |
|
throw new PdoOci8Exception('There is no active transaction'); |
|
451
|
|
|
} |
|
452
|
|
|
|
|
453
|
|
|
try { |
|
454
|
1 |
|
$isSuccess = $this->getConnection()->rollback(); |
|
455
|
1 |
|
} catch (Oci8Exception $ex) { |
|
456
|
|
|
$isSuccess = false; |
|
457
|
|
|
} |
|
458
|
|
|
|
|
459
|
|
|
// TODO Restore autocommit mode |
|
460
|
|
|
// If the database was set to autocommit mode |
|
461
|
|
|
// this function will restore autocommit mode after |
|
462
|
|
|
// it has rolled back the transaction |
|
463
|
1 |
|
$this->setAttribute(\PDO::ATTR_AUTOCOMMIT, true); |
|
464
|
|
|
|
|
465
|
1 |
|
return $isSuccess; |
|
466
|
|
|
} |
|
467
|
|
|
|
|
468
|
|
|
/** |
|
469
|
|
|
* @param int $attribute |
|
470
|
|
|
* @param mixed $value |
|
471
|
|
|
* |
|
472
|
|
|
* @link http://php.net/manual/en/pdo.setattribute.php |
|
473
|
|
|
* @return bool |
|
474
|
|
|
*/ |
|
475
|
11 |
|
public function setAttribute($attribute, $value) |
|
476
|
|
|
{ |
|
477
|
|
|
$readOnlyAttributes = array( |
|
478
|
11 |
|
\PDO::ATTR_CLIENT_VERSION, |
|
479
|
11 |
|
\PDO::ATTR_CONNECTION_STATUS, |
|
480
|
11 |
|
\PDO::ATTR_DRIVER_NAME, |
|
481
|
11 |
|
\PDO::ATTR_PERSISTENT, |
|
482
|
11 |
|
\PDO::ATTR_SERVER_INFO, |
|
483
|
11 |
|
\PDO::ATTR_SERVER_VERSION, |
|
484
|
11 |
|
); |
|
485
|
|
|
|
|
486
|
11 |
View Code Duplication |
if (array_search($attribute, $readOnlyAttributes) !== false || |
|
|
|
|
|
|
487
|
11 |
|
!array_key_exists($attribute, $this->options)) { |
|
488
|
11 |
|
return false; |
|
489
|
|
|
} |
|
490
|
|
|
|
|
491
|
5 |
|
$this->options[$attribute] = $value; |
|
492
|
|
|
|
|
493
|
5 |
|
return true; |
|
494
|
|
|
} |
|
495
|
|
|
} |
|
496
|
|
|
|
This check marks private properties in classes that are never used. Those properties can be removed.