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