PageRenderTime 50ms CodeModel.GetById 21ms RepoModel.GetById 0ms app.codeStats 0ms

/RestAPI/vendor/doctrine/dbal/lib/Doctrine/DBAL/Portability/Connection.php

https://gitlab.com/martinstti/silex-microframework-rest
PHP | 150 lines | 84 code | 17 blank | 49 comment | 9 complexity | 23ca8615bb2511b5c4962ec4de4becc7 MD5 | raw file
  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. namespace Doctrine\DBAL\Portability;
  20. use Doctrine\DBAL\Cache\QueryCacheProfile;
  21. /**
  22. * Portability wrapper for a Connection.
  23. *
  24. * @link www.doctrine-project.org
  25. * @since 2.0
  26. * @author Benjamin Eberlei <kontakt@beberlei.de>
  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. const PORTABILITY_DB2 = 13;
  36. const PORTABILITY_ORACLE = 9;
  37. const PORTABILITY_POSTGRESQL = 13;
  38. const PORTABILITY_SQLITE = 13;
  39. const PORTABILITY_OTHERVENDORS = 12;
  40. const PORTABILITY_DRIZZLE = 13;
  41. const PORTABILITY_SQLANYWHERE = 13;
  42. const PORTABILITY_SQLSRV = 13;
  43. /**
  44. * @var integer
  45. */
  46. private $portability = self::PORTABILITY_NONE;
  47. /**
  48. * @var integer
  49. */
  50. private $case;
  51. /**
  52. * {@inheritdoc}
  53. */
  54. public function connect()
  55. {
  56. $ret = parent::connect();
  57. if ($ret) {
  58. $params = $this->getParams();
  59. if (isset($params['portability'])) {
  60. if ($this->getDatabasePlatform()->getName() === "oracle") {
  61. $params['portability'] = $params['portability'] & self::PORTABILITY_ORACLE;
  62. } elseif ($this->getDatabasePlatform()->getName() === "postgresql") {
  63. $params['portability'] = $params['portability'] & self::PORTABILITY_POSTGRESQL;
  64. } elseif ($this->getDatabasePlatform()->getName() === "sqlite") {
  65. $params['portability'] = $params['portability'] & self::PORTABILITY_SQLITE;
  66. } elseif ($this->getDatabasePlatform()->getName() === "drizzle") {
  67. $params['portability'] = self::PORTABILITY_DRIZZLE;
  68. } elseif ($this->getDatabasePlatform()->getName() === 'sqlanywhere') {
  69. $params['portability'] = self::PORTABILITY_SQLANYWHERE;
  70. } elseif ($this->getDatabasePlatform()->getName() === 'db2') {
  71. $params['portability'] = self::PORTABILITY_DB2;
  72. } elseif ($this->getDatabasePlatform()->getName() === 'mssql') {
  73. $params['portability'] = $params['portability'] & self::PORTABILITY_SQLSRV;
  74. } else {
  75. $params['portability'] = $params['portability'] & self::PORTABILITY_OTHERVENDORS;
  76. }
  77. $this->portability = $params['portability'];
  78. }
  79. if (isset($params['fetch_case']) && $this->portability & self::PORTABILITY_FIX_CASE) {
  80. if ($this->_conn instanceof \Doctrine\DBAL\Driver\PDOConnection) {
  81. // make use of c-level support for case handling
  82. $this->_conn->setAttribute(\PDO::ATTR_CASE, $params['fetch_case']);
  83. } else {
  84. $this->case = ($params['fetch_case'] == \PDO::CASE_LOWER) ? CASE_LOWER : CASE_UPPER;
  85. }
  86. }
  87. }
  88. return $ret;
  89. }
  90. /**
  91. * @return integer
  92. */
  93. public function getPortability()
  94. {
  95. return $this->portability;
  96. }
  97. /**
  98. * @return integer
  99. */
  100. public function getFetchCase()
  101. {
  102. return $this->case;
  103. }
  104. /**
  105. * {@inheritdoc}
  106. */
  107. public function executeQuery($query, array $params = array(), $types = array(), QueryCacheProfile $qcp = null)
  108. {
  109. $stmt = new Statement(parent::executeQuery($query, $params, $types, $qcp), $this);
  110. $stmt->setFetchMode($this->defaultFetchMode);
  111. return $stmt;
  112. }
  113. /**
  114. * {@inheritdoc}
  115. */
  116. public function prepare($statement)
  117. {
  118. $stmt = new Statement(parent::prepare($statement), $this);
  119. $stmt->setFetchMode($this->defaultFetchMode);
  120. return $stmt;
  121. }
  122. /**
  123. * {@inheritdoc}
  124. */
  125. public function query()
  126. {
  127. $this->connect();
  128. $stmt = call_user_func_array(array($this->_conn, 'query'), func_get_args());
  129. $stmt = new Statement($stmt, $this);
  130. $stmt->setFetchMode($this->defaultFetchMode);
  131. return $stmt;
  132. }
  133. }