Connection.php 4.0 KB

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