|
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
|
150 |
|
public function connect() |
|
43
|
|
|
{ |
|
44
|
150 |
|
$ret = parent::connect(); |
|
45
|
150 |
|
if ($ret) { |
|
46
|
150 |
|
$params = $this->getParams(); |
|
47
|
150 |
|
if (isset($params['portability'])) { |
|
48
|
150 |
|
if ($this->getDatabasePlatform()->getName() === 'oracle') { |
|
49
|
|
|
$params['portability'] &= self::PORTABILITY_ORACLE; |
|
50
|
150 |
|
} elseif ($this->getDatabasePlatform()->getName() === 'postgresql') { |
|
51
|
35 |
|
$params['portability'] &= self::PORTABILITY_POSTGRESQL; |
|
52
|
115 |
|
} elseif ($this->getDatabasePlatform()->getName() === 'sqlite') { |
|
53
|
5 |
|
$params['portability'] &= self::PORTABILITY_SQLITE; |
|
54
|
110 |
|
} elseif ($this->getDatabasePlatform()->getName() === 'drizzle') { |
|
55
|
|
|
$params['portability'] &= self::PORTABILITY_DRIZZLE; |
|
56
|
110 |
|
} elseif ($this->getDatabasePlatform()->getName() === 'sqlanywhere') { |
|
57
|
|
|
$params['portability'] &= self::PORTABILITY_SQLANYWHERE; |
|
58
|
110 |
|
} elseif ($this->getDatabasePlatform()->getName() === 'db2') { |
|
59
|
5 |
|
$params['portability'] &= self::PORTABILITY_DB2; |
|
60
|
105 |
|
} elseif ($this->getDatabasePlatform()->getName() === 'mssql') { |
|
61
|
35 |
|
$params['portability'] &= self::PORTABILITY_SQLSRV; |
|
62
|
|
|
} else { |
|
63
|
70 |
|
$params['portability'] &= self::PORTABILITY_OTHERVENDORS; |
|
64
|
|
|
} |
|
65
|
150 |
|
$this->portability = $params['portability']; |
|
66
|
|
|
} |
|
67
|
|
|
|
|
68
|
150 |
|
if (isset($params['fetch_case']) && $this->portability & self::PORTABILITY_FIX_CASE) { |
|
69
|
125 |
|
if ($this->_conn instanceof PDOConnection) { |
|
70
|
|
|
// make use of c-level support for case handling |
|
71
|
80 |
|
$this->_conn->setAttribute(PDO::ATTR_CASE, $params['fetch_case']); |
|
72
|
|
|
} else { |
|
73
|
45 |
|
$this->case = $params['fetch_case'] === ColumnCase::LOWER ? CASE_LOWER : CASE_UPPER; |
|
74
|
|
|
} |
|
75
|
|
|
} |
|
76
|
|
|
} |
|
77
|
|
|
|
|
78
|
150 |
|
return $ret; |
|
79
|
|
|
} |
|
80
|
|
|
|
|
81
|
|
|
/** |
|
82
|
|
|
* @return int |
|
83
|
|
|
*/ |
|
84
|
150 |
|
public function getPortability() |
|
85
|
|
|
{ |
|
86
|
150 |
|
return $this->portability; |
|
87
|
|
|
} |
|
88
|
|
|
|
|
89
|
|
|
/** |
|
90
|
|
|
* @return int |
|
91
|
|
|
*/ |
|
92
|
125 |
|
public function getFetchCase() |
|
93
|
|
|
{ |
|
94
|
125 |
|
return $this->case; |
|
95
|
|
|
} |
|
96
|
|
|
|
|
97
|
|
|
/** |
|
98
|
|
|
* {@inheritdoc} |
|
99
|
|
|
*/ |
|
100
|
50 |
|
public function executeQuery($query, array $params = [], $types = [], ?QueryCacheProfile $qcp = null) |
|
101
|
|
|
{ |
|
102
|
50 |
|
$stmt = new Statement(parent::executeQuery($query, $params, $types, $qcp), $this); |
|
103
|
50 |
|
$stmt->setFetchMode($this->defaultFetchMode); |
|
104
|
|
|
|
|
105
|
50 |
|
return $stmt; |
|
106
|
|
|
} |
|
107
|
|
|
|
|
108
|
|
|
/** |
|
109
|
|
|
* {@inheritdoc} |
|
110
|
|
|
*/ |
|
111
|
50 |
|
public function prepare($statement) |
|
112
|
|
|
{ |
|
113
|
50 |
|
$stmt = new Statement(parent::prepare($statement), $this); |
|
114
|
50 |
|
$stmt->setFetchMode($this->defaultFetchMode); |
|
115
|
|
|
|
|
116
|
50 |
|
return $stmt; |
|
117
|
|
|
} |
|
118
|
|
|
|
|
119
|
|
|
/** |
|
120
|
|
|
* {@inheritdoc} |
|
121
|
|
|
*/ |
|
122
|
125 |
|
public function query() |
|
123
|
|
|
{ |
|
124
|
125 |
|
$this->connect(); |
|
125
|
|
|
|
|
126
|
125 |
|
$stmt = $this->_conn->query(...func_get_args()); |
|
|
|
|
|
|
127
|
125 |
|
$stmt = new Statement($stmt, $this); |
|
128
|
125 |
|
$stmt->setFetchMode($this->defaultFetchMode); |
|
129
|
|
|
|
|
130
|
125 |
|
return $stmt; |
|
131
|
|
|
} |
|
132
|
|
|
} |
|
133
|
|
|
|
This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.
This is most likely a typographical error or the method has been renamed.