Ibm.php 5.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183
  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_Db2
  24. */
  25. require_once 'Zend/Db/TestUtil/Db2.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_Ibm extends Zend_Db_TestUtil_Db2
  35. {
  36. public function getSchema()
  37. {
  38. $desc = $this->_db->describeTable('zfproducts');
  39. return $desc['product_id']['SCHEMA_NAME'];
  40. }
  41. protected function _getDataProducts()
  42. {
  43. $data = parent::_getDataProducts();
  44. $server = $this->getServer();
  45. if ($server == 'IDS') {
  46. foreach ($data as &$row) {
  47. $row['product_id'] = new Zend_Db_Expr($this->_db->quoteIdentifier('zfproducts_seq', true) . ".NEXTVAL");
  48. }
  49. }
  50. return $data;
  51. }
  52. protected function _getDataDocuments()
  53. {
  54. $server = $this->getServer();
  55. if ($server == 'IDS') {
  56. return array (
  57. array(
  58. 'doc_id' => 1,
  59. 'doc_clob' => 'this is the clob that never ends...'.
  60. 'this is the clob that never ends...'.
  61. 'this is the clob that never ends...',
  62. 'doc_blob' => 'this is the blob that never ends...'.
  63. 'this is the blob that never ends...'.
  64. 'this is the blob that never ends...'
  65. )
  66. );
  67. }
  68. return parent::_getDataDocuments();
  69. }
  70. public function getSqlType($type)
  71. {
  72. $server = $this->getServer();
  73. if ($server == 'IDS') {
  74. if ($type == 'IDENTITY') {
  75. return 'SERIAL(1) PRIMARY KEY';
  76. }
  77. if ($type == 'DATETIME') {
  78. return 'DATE';
  79. }
  80. return $type;
  81. }
  82. return parent::getSqlType($type);
  83. }
  84. protected function _getSqlCreateTable($tableName)
  85. {
  86. $server = $this->getServer();
  87. if ($server == 'IDS') {
  88. $tableList = $this->_db->fetchCol('SELECT T.TABNAME FROM SYSTABLES T '
  89. . $this->_db->quoteInto(' WHERE T.TABNAME = ?', $tableName)
  90. );
  91. if (in_array($tableName, $tableList)) {
  92. return null;
  93. }
  94. return 'CREATE TABLE ' . $this->_db->quoteIdentifier($tableName, true);
  95. }
  96. return parent::_getSqlCreateTable($tableName);
  97. }
  98. protected function _getSqlDropTable($tableName)
  99. {
  100. $server = $this->getServer();
  101. if ($server == 'IDS') {
  102. $tableList = $this->_db->fetchCol('SELECT T.TABNAME FROM SYSTABLES T '
  103. . $this->_db->quoteInto(' WHERE T.TABNAME = ?', $tableName)
  104. );
  105. if (in_array($tableName, $tableList)) {
  106. return 'DROP TABLE ' . $this->_db->quoteIdentifier($tableName, true);
  107. }
  108. return null;
  109. }
  110. return parent::_getSqlDropTable($tableName);
  111. }
  112. protected function _getSqlCreateSequence($sequenceName)
  113. {
  114. $server = $this->getServer();
  115. if ($server == 'IDS') {
  116. $seqList = $this->_db->fetchCol('SELECT S.TABNAME FROM SYSTABLES S '
  117. . $this->_db->quoteInto(' WHERE S.TABNAME = ?', $sequenceName)
  118. . " AND S.TABTYPE = 'Q'"
  119. );
  120. if (in_array($sequenceName, $seqList)) {
  121. return null;
  122. }
  123. return 'CREATE SEQUENCE ' . $this->_db->quoteIdentifier($sequenceName, true) . ' START WITH 1 INCREMENT BY 1 MINVALUE 1';
  124. }
  125. return parent::_getSqlCreateSequence($sequenceName);
  126. }
  127. protected function _getSqlDropSequence($sequenceName)
  128. {
  129. $server = $this->getServer();
  130. if ($server == 'IDS') {
  131. $seqList = $this->_db->fetchCol('SELECT S.TABNAME FROM SYSTABLES S '
  132. . $this->_db->quoteInto(' WHERE S.TABNAME = ?', $sequenceName)
  133. . " AND S.TABTYPE = 'Q'"
  134. );
  135. if (in_array($sequenceName, $seqList)) {
  136. return 'DROP SEQUENCE ' . $this->_db->quoteIdentifier($sequenceName, true);
  137. }
  138. return null;
  139. }
  140. return parent::_getSqlDropSequence($sequenceName);
  141. }
  142. public function getServer()
  143. {
  144. return substr($this->_db->getConnection()->getAttribute(PDO::ATTR_SERVER_INFO), 0, 3);
  145. }
  146. protected function _rawQuery($sql)
  147. {
  148. $conn = $this->_db->getConnection();
  149. $retval = $conn->query($sql);
  150. if (!$retval) {
  151. $e = $conn->error;
  152. require_once 'Zend/Db/Exception.php';
  153. throw new Zend_Db_Exception("SQL error for \"$sql\": $e");
  154. }
  155. }
  156. }