|
1
|
|
|
<?php |
|
2
|
|
|
/* |
|
3
|
|
|
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS |
|
4
|
|
|
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT |
|
5
|
|
|
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR |
|
6
|
|
|
* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT |
|
7
|
|
|
* OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, |
|
8
|
|
|
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT |
|
9
|
|
|
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, |
|
10
|
|
|
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY |
|
11
|
|
|
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT |
|
12
|
|
|
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE |
|
13
|
|
|
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
|
14
|
|
|
* |
|
15
|
|
|
* This software consists of voluntary contributions made by many individuals |
|
16
|
|
|
* and is licensed under the MIT license. For more information, see |
|
17
|
|
|
* <http://www.doctrine-project.org>. |
|
18
|
|
|
*/ |
|
19
|
|
|
|
|
20
|
|
|
namespace Doctrine\DBAL\Portability; |
|
21
|
|
|
|
|
22
|
|
|
use Doctrine\DBAL\Cache\QueryCacheProfile; |
|
23
|
|
|
use Doctrine\DBAL\ColumnCase; |
|
24
|
|
|
use const CASE_LOWER; |
|
25
|
|
|
use const CASE_UPPER; |
|
26
|
|
|
use function func_get_args; |
|
27
|
|
|
|
|
28
|
|
|
/** |
|
29
|
|
|
* Portability wrapper for a Connection. |
|
30
|
|
|
* |
|
31
|
|
|
* @link www.doctrine-project.org |
|
32
|
|
|
* @since 2.0 |
|
33
|
|
|
* @author Benjamin Eberlei <[email protected]> |
|
34
|
|
|
*/ |
|
35
|
|
|
class Connection extends \Doctrine\DBAL\Connection |
|
36
|
|
|
{ |
|
37
|
|
|
const PORTABILITY_ALL = 255; |
|
38
|
|
|
const PORTABILITY_NONE = 0; |
|
39
|
|
|
const PORTABILITY_RTRIM = 1; |
|
40
|
|
|
const PORTABILITY_EMPTY_TO_NULL = 4; |
|
41
|
|
|
const PORTABILITY_FIX_CASE = 8; |
|
42
|
|
|
|
|
43
|
|
|
const PORTABILITY_DB2 = 13; |
|
44
|
|
|
const PORTABILITY_ORACLE = 9; |
|
45
|
|
|
const PORTABILITY_POSTGRESQL = 13; |
|
46
|
|
|
const PORTABILITY_SQLITE = 13; |
|
47
|
|
|
const PORTABILITY_OTHERVENDORS = 12; |
|
48
|
|
|
const PORTABILITY_DRIZZLE = 13; |
|
49
|
|
|
const PORTABILITY_SQLANYWHERE = 13; |
|
50
|
|
|
const PORTABILITY_SQLSRV = 13; |
|
51
|
|
|
|
|
52
|
|
|
/** |
|
53
|
|
|
* @var int |
|
54
|
|
|
*/ |
|
55
|
|
|
private $portability = self::PORTABILITY_NONE; |
|
56
|
|
|
|
|
57
|
|
|
/** |
|
58
|
|
|
* @var int |
|
59
|
|
|
*/ |
|
60
|
|
|
private $case; |
|
61
|
|
|
|
|
62
|
|
|
/** |
|
63
|
|
|
* {@inheritdoc} |
|
64
|
|
|
*/ |
|
65
|
114 |
|
public function connect() |
|
66
|
|
|
{ |
|
67
|
114 |
|
$ret = parent::connect(); |
|
68
|
114 |
|
if ($ret) { |
|
69
|
114 |
|
$params = $this->getParams(); |
|
70
|
114 |
|
if (isset($params['portability'])) { |
|
71
|
114 |
|
if ($this->getDatabasePlatform()->getName() === "oracle") { |
|
72
|
|
|
$params['portability'] = $params['portability'] & self::PORTABILITY_ORACLE; |
|
73
|
114 |
|
} elseif ($this->getDatabasePlatform()->getName() === "postgresql") { |
|
74
|
30 |
|
$params['portability'] = $params['portability'] & self::PORTABILITY_POSTGRESQL; |
|
75
|
84 |
|
} elseif ($this->getDatabasePlatform()->getName() === "sqlite") { |
|
76
|
5 |
|
$params['portability'] = $params['portability'] & self::PORTABILITY_SQLITE; |
|
77
|
79 |
|
} elseif ($this->getDatabasePlatform()->getName() === "drizzle") { |
|
78
|
|
|
$params['portability'] = $params['portability'] & self::PORTABILITY_DRIZZLE; |
|
79
|
79 |
|
} elseif ($this->getDatabasePlatform()->getName() === 'sqlanywhere') { |
|
80
|
|
|
$params['portability'] = $params['portability'] & self::PORTABILITY_SQLANYWHERE; |
|
81
|
79 |
|
} elseif ($this->getDatabasePlatform()->getName() === 'db2') { |
|
82
|
5 |
|
$params['portability'] = $params['portability'] & self::PORTABILITY_DB2; |
|
83
|
74 |
|
} elseif ($this->getDatabasePlatform()->getName() === 'mssql') { |
|
84
|
29 |
|
$params['portability'] = $params['portability'] & self::PORTABILITY_SQLSRV; |
|
85
|
|
|
} else { |
|
86
|
45 |
|
$params['portability'] = $params['portability'] & self::PORTABILITY_OTHERVENDORS; |
|
87
|
|
|
} |
|
88
|
114 |
|
$this->portability = $params['portability']; |
|
89
|
|
|
} |
|
90
|
|
|
|
|
91
|
114 |
|
if (isset($params['fetch_case']) && $this->portability & self::PORTABILITY_FIX_CASE) { |
|
92
|
95 |
|
if ($this->_conn instanceof \Doctrine\DBAL\Driver\PDOConnection) { |
|
93
|
|
|
// make use of c-level support for case handling |
|
94
|
70 |
|
$this->_conn->setAttribute(\PDO::ATTR_CASE, $params['fetch_case']); |
|
95
|
|
|
} else { |
|
96
|
25 |
|
$this->case = ($params['fetch_case'] === ColumnCase::LOWER) ? CASE_LOWER : CASE_UPPER; |
|
97
|
|
|
} |
|
98
|
|
|
} |
|
99
|
|
|
} |
|
100
|
|
|
|
|
101
|
114 |
|
return $ret; |
|
102
|
|
|
} |
|
103
|
|
|
|
|
104
|
|
|
/** |
|
105
|
|
|
* @return int |
|
106
|
|
|
*/ |
|
107
|
114 |
|
public function getPortability() |
|
108
|
|
|
{ |
|
109
|
114 |
|
return $this->portability; |
|
110
|
|
|
} |
|
111
|
|
|
|
|
112
|
|
|
/** |
|
113
|
|
|
* @return int |
|
114
|
|
|
*/ |
|
115
|
95 |
|
public function getFetchCase() |
|
116
|
|
|
{ |
|
117
|
95 |
|
return $this->case; |
|
118
|
|
|
} |
|
119
|
|
|
|
|
120
|
|
|
/** |
|
121
|
|
|
* {@inheritdoc} |
|
122
|
|
|
*/ |
|
123
|
38 |
|
public function executeQuery($query, array $params = [], $types = [], QueryCacheProfile $qcp = null) |
|
124
|
|
|
{ |
|
125
|
38 |
|
$stmt = new Statement(parent::executeQuery($query, $params, $types, $qcp), $this); |
|
126
|
38 |
|
$stmt->setFetchMode($this->defaultFetchMode); |
|
127
|
|
|
|
|
128
|
38 |
|
return $stmt; |
|
129
|
|
|
} |
|
130
|
|
|
|
|
131
|
|
|
/** |
|
132
|
|
|
* {@inheritdoc} |
|
133
|
|
|
*/ |
|
134
|
38 |
|
public function prepare($statement) |
|
135
|
|
|
{ |
|
136
|
38 |
|
$stmt = new Statement(parent::prepare($statement), $this); |
|
137
|
38 |
|
$stmt->setFetchMode($this->defaultFetchMode); |
|
138
|
|
|
|
|
139
|
38 |
|
return $stmt; |
|
140
|
|
|
} |
|
141
|
|
|
|
|
142
|
|
|
/** |
|
143
|
|
|
* {@inheritdoc} |
|
144
|
|
|
*/ |
|
145
|
95 |
|
public function query() |
|
146
|
|
|
{ |
|
147
|
95 |
|
$this->connect(); |
|
148
|
|
|
|
|
149
|
95 |
|
$stmt = $this->_conn->query(...func_get_args()); |
|
|
|
|
|
|
150
|
95 |
|
$stmt = new Statement($stmt, $this); |
|
151
|
95 |
|
$stmt->setFetchMode($this->defaultFetchMode); |
|
152
|
|
|
|
|
153
|
95 |
|
return $stmt; |
|
154
|
|
|
} |
|
155
|
|
|
} |
|
156
|
|
|
|
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.