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 LGPL. For more information, see |
---|
17 | * <http://www.doctrine-project.org>. |
---|
18 | */ |
---|
19 | |
---|
20 | |
---|
21 | namespace Doctrine\DBAL\Portability; |
---|
22 | |
---|
23 | use Doctrine\Common\EventManager; |
---|
24 | use Doctrine\DBAL\Configuration; |
---|
25 | use Doctrine\DBAL\Driver; |
---|
26 | use Doctrine\DBAL\Cache\QueryCacheProfile; |
---|
27 | |
---|
28 | class Connection extends \Doctrine\DBAL\Connection |
---|
29 | { |
---|
30 | const PORTABILITY_ALL = 255; |
---|
31 | const PORTABILITY_NONE = 0; |
---|
32 | const PORTABILITY_RTRIM = 1; |
---|
33 | const PORTABILITY_EMPTY_TO_NULL = 4; |
---|
34 | const PORTABILITY_FIX_CASE = 8; |
---|
35 | |
---|
36 | const PORTABILITY_ORACLE = 9; |
---|
37 | const PORTABILITY_POSTGRESQL = 13; |
---|
38 | const PORTABILITY_SQLITE = 13; |
---|
39 | const PORTABILITY_OTHERVENDORS = 12; |
---|
40 | |
---|
41 | /** |
---|
42 | * @var int |
---|
43 | */ |
---|
44 | private $portability = self::PORTABILITY_NONE; |
---|
45 | |
---|
46 | /** |
---|
47 | * @var int |
---|
48 | */ |
---|
49 | private $case; |
---|
50 | |
---|
51 | public function connect() |
---|
52 | { |
---|
53 | $ret = parent::connect(); |
---|
54 | if ($ret) { |
---|
55 | $params = $this->getParams(); |
---|
56 | if (isset($params['portability'])) { |
---|
57 | if ($this->_platform->getName() === "oracle") { |
---|
58 | $params['portability'] = $params['portability'] & self::PORTABILITY_ORACLE; |
---|
59 | } else if ($this->_platform->getName() === "postgresql") { |
---|
60 | $params['portability'] = $params['portability'] & self::PORTABILITY_POSTGRESQL; |
---|
61 | } else if ($this->_platform->getName() === "sqlite") { |
---|
62 | $params['portability'] = $params['portability'] & self::PORTABILITY_SQLITE; |
---|
63 | } else { |
---|
64 | $params['portability'] = $params['portability'] & self::PORTABILITY_OTHERVENDORS; |
---|
65 | } |
---|
66 | $this->portability = $params['portability']; |
---|
67 | } |
---|
68 | if (isset($params['fetch_case']) && $this->portability & self::PORTABILITY_FIX_CASE) { |
---|
69 | if ($this->_conn instanceof \Doctrine\DBAL\Driver\PDOConnection) { |
---|
70 | // make use of c-level support for case handling |
---|
71 | $this->_conn->setAttribute(\PDO::ATTR_CASE, $params['fetch_case']); |
---|
72 | } else { |
---|
73 | $this->case = ($params['fetch_case'] == \PDO::CASE_LOWER) ? CASE_LOWER : CASE_UPPER; |
---|
74 | } |
---|
75 | } |
---|
76 | } |
---|
77 | return $ret; |
---|
78 | } |
---|
79 | |
---|
80 | public function getPortability() |
---|
81 | { |
---|
82 | return $this->portability; |
---|
83 | } |
---|
84 | |
---|
85 | public function getFetchCase() |
---|
86 | { |
---|
87 | return $this->case; |
---|
88 | } |
---|
89 | |
---|
90 | public function executeQuery($query, array $params = array(), $types = array(), QueryCacheProfile $qcp = null) |
---|
91 | { |
---|
92 | return new Statement(parent::executeQuery($query, $params, $types, $qcp), $this); |
---|
93 | } |
---|
94 | |
---|
95 | /** |
---|
96 | * Prepares an SQL statement. |
---|
97 | * |
---|
98 | * @param string $statement The SQL statement to prepare. |
---|
99 | * @return Doctrine\DBAL\Driver\Statement The prepared statement. |
---|
100 | */ |
---|
101 | public function prepare($statement) |
---|
102 | { |
---|
103 | return new Statement(parent::prepare($statement), $this); |
---|
104 | } |
---|
105 | |
---|
106 | public function query() |
---|
107 | { |
---|
108 | $this->connect(); |
---|
109 | |
---|
110 | $stmt = call_user_func_array(array($this->_conn, 'query'), func_get_args()); |
---|
111 | return new Statement($stmt, $this); |
---|
112 | } |
---|
113 | } |
---|