1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace Doctrine\DBAL\Portability; |
4
|
|
|
|
5
|
|
|
use Doctrine\DBAL\Cache\QueryCacheProfile; |
6
|
|
|
use Doctrine\DBAL\ColumnCase; |
7
|
|
|
use Doctrine\DBAL\Driver\PDOConnection; |
8
|
|
|
use PDO; |
9
|
|
|
use const CASE_LOWER; |
10
|
|
|
use const CASE_UPPER; |
11
|
|
|
use function func_get_args; |
12
|
|
|
|
13
|
|
|
/** |
14
|
|
|
* Portability wrapper for a Connection. |
15
|
|
|
*/ |
16
|
|
|
class Connection extends \Doctrine\DBAL\Connection |
17
|
|
|
{ |
18
|
|
|
public const PORTABILITY_ALL = 255; |
19
|
|
|
public const PORTABILITY_NONE = 0; |
20
|
|
|
public const PORTABILITY_RTRIM = 1; |
21
|
|
|
public const PORTABILITY_EMPTY_TO_NULL = 4; |
22
|
|
|
public const PORTABILITY_FIX_CASE = 8; |
23
|
|
|
|
24
|
|
|
public const PORTABILITY_DB2 = 13; |
25
|
|
|
public const PORTABILITY_ORACLE = 9; |
26
|
|
|
public const PORTABILITY_POSTGRESQL = 13; |
27
|
|
|
public const PORTABILITY_SQLITE = 13; |
28
|
|
|
public const PORTABILITY_OTHERVENDORS = 12; |
29
|
|
|
public const PORTABILITY_DRIZZLE = 13; |
30
|
|
|
public const PORTABILITY_SQLANYWHERE = 13; |
31
|
|
|
public const PORTABILITY_SQLSRV = 13; |
32
|
|
|
|
33
|
|
|
/** @var int */ |
34
|
|
|
private $portability = self::PORTABILITY_NONE; |
35
|
|
|
|
36
|
|
|
/** @var int */ |
37
|
|
|
private $case; |
38
|
|
|
|
39
|
|
|
/** |
40
|
|
|
* {@inheritdoc} |
41
|
|
|
*/ |
42
|
138 |
|
public function connect() |
43
|
|
|
{ |
44
|
138 |
|
$ret = parent::connect(); |
45
|
138 |
|
if ($ret) { |
46
|
138 |
|
$params = $this->getParams(); |
47
|
138 |
|
if (isset($params['portability'])) { |
48
|
138 |
|
if ($this->getDatabasePlatform()->getName() === 'oracle') { |
49
|
10 |
|
$params['portability'] &= self::PORTABILITY_ORACLE; |
50
|
128 |
|
} elseif ($this->getDatabasePlatform()->getName() === 'postgresql') { |
51
|
35 |
|
$params['portability'] &= self::PORTABILITY_POSTGRESQL; |
52
|
93 |
|
} elseif ($this->getDatabasePlatform()->getName() === 'sqlite') { |
53
|
|
|
$params['portability'] &= self::PORTABILITY_SQLITE; |
54
|
93 |
|
} elseif ($this->getDatabasePlatform()->getName() === 'drizzle') { |
55
|
|
|
$params['portability'] &= self::PORTABILITY_DRIZZLE; |
56
|
93 |
|
} elseif ($this->getDatabasePlatform()->getName() === 'sqlanywhere') { |
57
|
|
|
$params['portability'] &= self::PORTABILITY_SQLANYWHERE; |
58
|
93 |
|
} elseif ($this->getDatabasePlatform()->getName() === 'db2') { |
59
|
5 |
|
$params['portability'] &= self::PORTABILITY_DB2; |
60
|
88 |
|
} elseif ($this->getDatabasePlatform()->getName() === 'mssql') { |
61
|
9 |
|
$params['portability'] &= self::PORTABILITY_SQLSRV; |
62
|
|
|
} else { |
63
|
79 |
|
$params['portability'] &= self::PORTABILITY_OTHERVENDORS; |
64
|
|
|
} |
65
|
138 |
|
$this->portability = $params['portability']; |
66
|
|
|
} |
67
|
|
|
|
68
|
138 |
|
if (isset($params['fetch_case']) && $this->portability & self::PORTABILITY_FIX_CASE) { |
69
|
138 |
|
if ($this->_conn instanceof PDOConnection) { |
70
|
|
|
// make use of c-level support for case handling |
71
|
89 |
|
$this->_conn->setAttribute(PDO::ATTR_CASE, $params['fetch_case']); |
72
|
|
|
} else { |
73
|
49 |
|
$this->case = $params['fetch_case'] === ColumnCase::LOWER ? CASE_LOWER : CASE_UPPER; |
74
|
|
|
} |
75
|
|
|
} |
76
|
|
|
} |
77
|
|
|
|
78
|
138 |
|
return $ret; |
79
|
|
|
} |
80
|
|
|
|
81
|
|
|
/** |
82
|
|
|
* @return int |
83
|
|
|
*/ |
84
|
138 |
|
public function getPortability() |
85
|
|
|
{ |
86
|
138 |
|
return $this->portability; |
87
|
|
|
} |
88
|
|
|
|
89
|
|
|
/** |
90
|
|
|
* @return int |
91
|
|
|
*/ |
92
|
138 |
|
public function getFetchCase() |
93
|
|
|
{ |
94
|
138 |
|
return $this->case; |
95
|
|
|
} |
96
|
|
|
|
97
|
|
|
/** |
98
|
|
|
* {@inheritdoc} |
99
|
|
|
*/ |
100
|
132 |
|
public function executeQuery($query, array $params = [], $types = [], ?QueryCacheProfile $qcp = null) |
101
|
|
|
{ |
102
|
132 |
|
$stmt = new Statement(parent::executeQuery($query, $params, $types, $qcp), $this); |
103
|
132 |
|
$stmt->setFetchMode($this->defaultFetchMode); |
104
|
|
|
|
105
|
132 |
|
return $stmt; |
106
|
|
|
} |
107
|
|
|
|
108
|
|
|
/** |
109
|
|
|
* {@inheritdoc} |
110
|
|
|
*/ |
111
|
132 |
|
public function prepare($statement) |
112
|
|
|
{ |
113
|
132 |
|
$stmt = new Statement(parent::prepare($statement), $this); |
114
|
132 |
|
$stmt->setFetchMode($this->defaultFetchMode); |
115
|
|
|
|
116
|
132 |
|
return $stmt; |
117
|
|
|
} |
118
|
|
|
|
119
|
|
|
/** |
120
|
|
|
* {@inheritdoc} |
121
|
|
|
*/ |
122
|
138 |
|
public function query() |
123
|
|
|
{ |
124
|
138 |
|
$connection = $this->getWrappedConnection(); |
125
|
|
|
|
126
|
138 |
|
$stmt = $connection->query(...func_get_args()); |
|
|
|
|
127
|
138 |
|
$stmt = new Statement($stmt, $this); |
128
|
138 |
|
$stmt->setFetchMode($this->defaultFetchMode); |
129
|
|
|
|
130
|
138 |
|
return $stmt; |
131
|
|
|
} |
132
|
|
|
} |
133
|
|
|
|
This check compares calls to functions or methods with their respective definitions. If the call has more arguments than are defined, it raises an issue.
If a function is defined several times with a different number of parameters, the check may pick up the wrong definition and report false positives. One codebase where this has been known to happen is Wordpress. Please note the @ignore annotation hint above.