-
-
Notifications
You must be signed in to change notification settings - Fork 1.4k
/
Copy pathConnection.php
98 lines (83 loc) · 2.78 KB
/
Connection.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
<?php
namespace Doctrine\DBAL\Portability;
use Doctrine\DBAL\Abstraction\Result as AbstractionResult;
use Doctrine\DBAL\Cache\QueryCacheProfile;
use Doctrine\DBAL\ColumnCase;
use Doctrine\DBAL\Driver\PDOConnection;
use Doctrine\DBAL\Driver\Result as DriverResult;
use Doctrine\DBAL\Driver\Statement as DriverStatement;
use Doctrine\DBAL\Result as DBALResult;
use PDO;
use const CASE_LOWER;
use const CASE_UPPER;
/**
* Portability wrapper for a Connection.
*/
class Connection extends \Doctrine\DBAL\Connection
{
public const PORTABILITY_ALL = 255;
public const PORTABILITY_NONE = 0;
public const PORTABILITY_RTRIM = 1;
public const PORTABILITY_EMPTY_TO_NULL = 4;
public const PORTABILITY_FIX_CASE = 8;
/** @var Converter */
private $converter;
/**
* {@inheritdoc}
*/
public function connect()
{
$ret = parent::connect();
if ($ret) {
$params = $this->getParams();
$portability = self::PORTABILITY_NONE;
if (isset($params['portability'])) {
$portability = $params['portability'] = (new OptimizeFlags())(
$this->getDatabasePlatform(),
$params['portability']
);
}
$case = null;
if (isset($params['fetch_case']) && ($portability & self::PORTABILITY_FIX_CASE) !== 0) {
if ($this->_conn instanceof PDOConnection) {
// make use of c-level support for case handling
$this->_conn->getWrappedConnection()->setAttribute(PDO::ATTR_CASE, $params['fetch_case']);
} else {
$case = $params['fetch_case'] === ColumnCase::LOWER ? CASE_LOWER : CASE_UPPER;
}
}
$this->converter = new Converter(
($portability & self::PORTABILITY_EMPTY_TO_NULL) !== 0,
($portability & self::PORTABILITY_RTRIM) !== 0,
$case
);
}
return $ret;
}
/**
* {@inheritdoc}
*/
public function executeQuery(string $query, array $params = [], $types = [], ?QueryCacheProfile $qcp = null): AbstractionResult
{
return $this->wrapResult(
parent::executeQuery($query, $params, $types, $qcp)
);
}
public function prepare(string $sql): DriverStatement
{
return new Statement(parent::prepare($sql), $this->converter);
}
public function query(string $sql): DriverResult
{
return $this->wrapResult(
parent::query($sql)
);
}
private function wrapResult(DriverResult $result): AbstractionResult
{
return new DBALResult(
new Result($result, $this->converter),
$this
);
}
}