Ibm.php 5.4 KB

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