Oci.php 5.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171
  1. <?php
  2. /**
  3. * Zend Framework
  4. *
  5. * LICENSE
  6. *
  7. * This source file is subject to the new BSD license that is bundled
  8. * with this package in the file LICENSE.txt.
  9. * It is also available through the world-wide-web at this URL:
  10. * http://framework.zend.com/license/new-bsd
  11. * If you did not receive a copy of the license and are unable to
  12. * obtain it through the world-wide-web, please send an email
  13. * to license@zend.com so we can send you a copy immediately.
  14. *
  15. * @category Zend
  16. * @package Zend_Db
  17. * @subpackage UnitTests
  18. * @copyright Copyright (c) 2005-2015 Zend Technologies USA Inc. (http://www.zend.com)
  19. * @license http://framework.zend.com/license/new-bsd New BSD License
  20. * @version $Id$
  21. */
  22. /**
  23. * @see Zend_Db_TestUtil_Pdo_Common
  24. */
  25. require_once 'Zend/Db/TestUtil/Pdo/Common.php';
  26. /**
  27. * @category Zend
  28. * @package Zend_Db
  29. * @subpackage UnitTests
  30. * @copyright Copyright (c) 2005-2015 Zend Technologies USA Inc. (http://www.zend.com)
  31. * @license http://framework.zend.com/license/new-bsd New BSD License
  32. */
  33. class Zend_Db_TestUtil_Pdo_Oci extends Zend_Db_TestUtil_Pdo_Common
  34. {
  35. public function setUp(Zend_Db_Adapter_Abstract $db)
  36. {
  37. $this->_db = $db;
  38. $this->createSequence('zfbugs_seq');
  39. $this->createSequence('zfproducts_seq');
  40. parent::setUp($db);
  41. }
  42. public function getParams(array $constants = array())
  43. {
  44. $constants = array (
  45. 'host' => 'TESTS_ZEND_DB_ADAPTER_ORACLE_HOSTNAME',
  46. 'username' => 'TESTS_ZEND_DB_ADAPTER_ORACLE_USERNAME',
  47. 'password' => 'TESTS_ZEND_DB_ADAPTER_ORACLE_PASSWORD',
  48. 'dbname' => 'TESTS_ZEND_DB_ADAPTER_ORACLE_SID'
  49. );
  50. return parent::getParams($constants);
  51. }
  52. public function getSqlType($type)
  53. {
  54. if (preg_match('/VARCHAR(.*)/', $type, $matches)) {
  55. return 'VARCHAR2' . $matches[1];
  56. }
  57. if ($type == 'IDENTITY') {
  58. return 'NUMBER(11) PRIMARY KEY';
  59. }
  60. if ($type == 'INTEGER') {
  61. return 'NUMBER(11)';
  62. }
  63. if ($type == 'DATETIME') {
  64. return 'TIMESTAMP';
  65. }
  66. return $type;
  67. }
  68. protected function _getSqlCreateTable($tableName)
  69. {
  70. $tableList = $this->_db->fetchCol('SELECT UPPER(TABLE_NAME) FROM ALL_TABLES '
  71. . $this->_db->quoteInto(' WHERE UPPER(TABLE_NAME) = UPPER(?)', $tableName)
  72. );
  73. if (in_array(strtoupper($tableName), $tableList)) {
  74. return null;
  75. }
  76. return 'CREATE TABLE ' . $this->_db->quoteIdentifier($tableName, true);
  77. }
  78. protected function _getSqlDropTable($tableName)
  79. {
  80. $tableList = $this->_db->fetchCol('SELECT UPPER(TABLE_NAME) FROM ALL_TABLES '
  81. . $this->_db->quoteInto(' WHERE UPPER(TABLE_NAME) = UPPER(?)', $tableName)
  82. );
  83. if (in_array(strtoupper($tableName), $tableList)) {
  84. return 'DROP TABLE ' . $this->_db->quoteIdentifier($tableName, true);
  85. }
  86. return null;
  87. }
  88. protected function _getSqlCreateSequence($sequenceName)
  89. {
  90. $seqList = $this->_db->fetchCol('SELECT UPPER(SEQUENCE_NAME) FROM ALL_SEQUENCES '
  91. . $this->_db->quoteInto(' WHERE UPPER(SEQUENCE_NAME) = UPPER(?)', $sequenceName)
  92. );
  93. if (in_array(strtoupper($sequenceName), $seqList)) {
  94. return null;
  95. }
  96. return 'CREATE SEQUENCE ' . $this->_db->quoteIdentifier($sequenceName, true);
  97. }
  98. protected function _getSqlDropSequence($sequenceName)
  99. {
  100. $seqList = $this->_db->fetchCol('SELECT UPPER(SEQUENCE_NAME) FROM ALL_SEQUENCES '
  101. . $this->_db->quoteInto(' WHERE UPPER(SEQUENCE_NAME) = UPPER(?)', $sequenceName)
  102. );
  103. if (in_array(strtoupper($sequenceName), $seqList)) {
  104. return 'DROP SEQUENCE ' . $this->_db->quoteIdentifier($sequenceName, true);
  105. }
  106. return null;
  107. }
  108. protected function _getDataBugs()
  109. {
  110. $data = parent::_getDataBugs();
  111. foreach ($data as &$row) {
  112. $row['bug_id'] = new Zend_Db_Expr($this->_db->quoteIdentifier('zfbugs_seq', true).'.NEXTVAL');
  113. $row['created_on'] = new Zend_Db_Expr($this->_db->quoteInto('DATE ?', $row['created_on']));
  114. $row['updated_on'] = new Zend_Db_Expr($this->_db->quoteInto('DATE ?', $row['updated_on']));
  115. }
  116. return $data;
  117. }
  118. protected function _getDataDocuments()
  119. {
  120. $data = parent::_getDataDocuments();
  121. foreach ($data as &$row) {
  122. $quoted = $this->_db->quote($row['doc_clob']);
  123. $hex = bin2hex($row['doc_clob']);
  124. $row['doc_clob'] = new Zend_Db_Expr("TO_CLOB($quoted)");
  125. $row['doc_blob'] = new Zend_Db_Expr("TO_BLOB(HEXTORAW('$hex'))");
  126. }
  127. return $data;
  128. }
  129. protected function _getDataProducts()
  130. {
  131. $data = parent::_getDataProducts();
  132. foreach ($data as &$row) {
  133. $row['product_id'] = new Zend_Db_Expr($this->_db->quoteIdentifier('zfproducts_seq', true).'.NEXTVAL');
  134. }
  135. return $data;
  136. }
  137. protected function _getSqlCreateView($viewName)
  138. {
  139. return 'CREATE OR REPLACE VIEW ' . $this->_db->quoteIdentifier($viewName, true);
  140. }
  141. /**
  142. * ZF-4330: schemas on Oracle are specifics:
  143. * "A schema is owned by a database user and has the same name as that user."
  144. * http://download-east.oracle.com/docs/cd/B19306_01/server.102/b14220/intro.htm#sthref69
  145. * @return string
  146. */
  147. public function getSchema()
  148. {
  149. $param = $this->getParams();
  150. return $param['username'];
  151. }
  152. }