2
0

Oci.php 5.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170
  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-2009 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. PHPUnit_Util_Filter::addFileToFilter(__FILE__);
  27. /**
  28. * @category Zend
  29. * @package Zend_Db
  30. * @subpackage UnitTests
  31. * @copyright Copyright (c) 2005-2009 Zend Technologies USA Inc. (http://www.zend.com)
  32. * @license http://framework.zend.com/license/new-bsd New BSD License
  33. */
  34. class Zend_Db_TestUtil_Pdo_Oci extends Zend_Db_TestUtil_Pdo_Common
  35. {
  36. public function setUp(Zend_Db_Adapter_Abstract $db)
  37. {
  38. $this->_db = $db;
  39. $this->createSequence('zfbugs_seq');
  40. $this->createSequence('zfproducts_seq');
  41. parent::setUp($db);
  42. }
  43. public function getParams(array $constants = array())
  44. {
  45. $constants = array (
  46. 'host' => 'TESTS_ZEND_DB_ADAPTER_ORACLE_HOSTNAME',
  47. 'username' => 'TESTS_ZEND_DB_ADAPTER_ORACLE_USERNAME',
  48. 'password' => 'TESTS_ZEND_DB_ADAPTER_ORACLE_PASSWORD',
  49. 'dbname' => 'TESTS_ZEND_DB_ADAPTER_ORACLE_SID'
  50. );
  51. return parent::getParams($constants);
  52. }
  53. public function getSqlType($type)
  54. {
  55. if (preg_match('/VARCHAR(.*)/', $type, $matches)) {
  56. return 'VARCHAR2' . $matches[1];
  57. }
  58. if ($type == 'IDENTITY') {
  59. return 'NUMBER(11) PRIMARY KEY';
  60. }
  61. if ($type == 'INTEGER') {
  62. return 'NUMBER(11)';
  63. }
  64. if ($type == 'DATETIME') {
  65. return 'TIMESTAMP';
  66. }
  67. return $type;
  68. }
  69. protected function _getSqlCreateTable($tableName)
  70. {
  71. $tableList = $this->_db->fetchCol('SELECT UPPER(TABLE_NAME) FROM ALL_TABLES '
  72. . $this->_db->quoteInto(' WHERE UPPER(TABLE_NAME) = UPPER(?)', $tableName)
  73. );
  74. if (in_array(strtoupper($tableName), $tableList)) {
  75. return null;
  76. }
  77. return 'CREATE TABLE ' . $this->_db->quoteIdentifier($tableName, true);
  78. }
  79. protected function _getSqlDropTable($tableName)
  80. {
  81. $tableList = $this->_db->fetchCol('SELECT UPPER(TABLE_NAME) FROM ALL_TABLES '
  82. . $this->_db->quoteInto(' WHERE UPPER(TABLE_NAME) = UPPER(?)', $tableName)
  83. );
  84. if (in_array(strtoupper($tableName), $tableList)) {
  85. return 'DROP TABLE ' . $this->_db->quoteIdentifier($tableName, true);
  86. }
  87. return null;
  88. }
  89. protected function _getSqlCreateSequence($sequenceName)
  90. {
  91. $seqList = $this->_db->fetchCol('SELECT UPPER(SEQUENCE_NAME) FROM ALL_SEQUENCES '
  92. . $this->_db->quoteInto(' WHERE UPPER(SEQUENCE_NAME) = UPPER(?)', $sequenceName)
  93. );
  94. if (in_array(strtoupper($sequenceName), $seqList)) {
  95. return null;
  96. }
  97. return 'CREATE SEQUENCE ' . $this->_db->quoteIdentifier($sequenceName, true);
  98. }
  99. protected function _getSqlDropSequence($sequenceName)
  100. {
  101. $seqList = $this->_db->fetchCol('SELECT UPPER(SEQUENCE_NAME) FROM ALL_SEQUENCES '
  102. . $this->_db->quoteInto(' WHERE UPPER(SEQUENCE_NAME) = UPPER(?)', $sequenceName)
  103. );
  104. if (in_array(strtoupper($sequenceName), $seqList)) {
  105. return 'DROP SEQUENCE ' . $this->_db->quoteIdentifier($sequenceName, true);
  106. }
  107. return null;
  108. }
  109. protected function _getDataBugs()
  110. {
  111. $data = parent::_getDataBugs();
  112. foreach ($data as &$row) {
  113. $row['bug_id'] = new Zend_Db_Expr($this->_db->quoteIdentifier('zfbugs_seq', true).'.NEXTVAL');
  114. $row['created_on'] = new Zend_Db_Expr($this->_db->quoteInto('DATE ?', $row['created_on']));
  115. $row['updated_on'] = new Zend_Db_Expr($this->_db->quoteInto('DATE ?', $row['updated_on']));
  116. }
  117. return $data;
  118. }
  119. protected function _getDataDocuments()
  120. {
  121. $data = parent::_getDataDocuments();
  122. foreach ($data as &$row) {
  123. $quoted = $this->_db->quote($row['doc_clob']);
  124. $hex = bin2hex($row['doc_clob']);
  125. $row['doc_clob'] = new Zend_Db_Expr("TO_CLOB($quoted)");
  126. $row['doc_blob'] = new Zend_Db_Expr("TO_BLOB(HEXTORAW('$hex'))");
  127. }
  128. return $data;
  129. }
  130. protected function _getDataProducts()
  131. {
  132. $data = parent::_getDataProducts();
  133. foreach ($data as &$row) {
  134. $row['product_id'] = new Zend_Db_Expr($this->_db->quoteIdentifier('zfproducts_seq', true).'.NEXTVAL');
  135. }
  136. return $data;
  137. }
  138. protected function _getSqlCreateView($viewName)
  139. {
  140. return 'CREATE OR REPLACE VIEW ' . $this->_db->quoteIdentifier($viewName, true);
  141. }
  142. /**
  143. * ZF-4330: schemas on Oracle are specifics:
  144. * "A schema is owned by a database user and has the same name as that user."
  145. * http://download-east.oracle.com/docs/cd/B19306_01/server.102/b14220/intro.htm#sthref69
  146. * @return string
  147. */
  148. public function getSchema()
  149. {
  150. $param = $this->getParams();
  151. return $param['username'];
  152. }
  153. }