Mssql.php 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127
  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_Mssql extends Zend_Db_TestUtil_Pdo_Common
  34. {
  35. public function getParams(array $constants = array())
  36. {
  37. $constants = array (
  38. 'host' => 'TESTS_ZEND_DB_ADAPTER_PDO_MSSQL_HOSTNAME',
  39. 'username' => 'TESTS_ZEND_DB_ADAPTER_PDO_MSSQL_USERNAME',
  40. 'password' => 'TESTS_ZEND_DB_ADAPTER_PDO_MSSQL_PASSWORD',
  41. 'dbname' => 'TESTS_ZEND_DB_ADAPTER_PDO_MSSQL_DATABASE',
  42. 'port' => 'TESTS_ZEND_DB_ADAPTER_PDO_MSSQL_PORT',
  43. 'pdoType' => 'TESTS_ZEND_DB_ADAPTER_PDO_MSSQL_PDOTYPE',
  44. 'charset' => 'TESTS_ZEND_DB_ADAPTER_PDO_MSSQL_CHARSET',
  45. );
  46. return parent::getParams($constants);
  47. }
  48. public function getSqlType($type)
  49. {
  50. if ($type == 'IDENTITY') {
  51. return 'INT NOT NULL IDENTITY PRIMARY KEY';
  52. }
  53. return $type;
  54. }
  55. protected function _getColumnsDocuments()
  56. {
  57. return array(
  58. 'doc_id' => 'INTEGER NOT NULL',
  59. 'doc_clob' => 'VARCHAR(8000)',
  60. 'doc_blob' => 'VARCHAR(8000)',
  61. 'PRIMARY KEY' => 'doc_id'
  62. );
  63. }
  64. protected function _getColumnsBugs()
  65. {
  66. return array(
  67. 'bug_id' => 'IDENTITY',
  68. 'bug_description' => 'VARCHAR(100) NULL',
  69. 'bug_status' => 'VARCHAR(20) NULL',
  70. 'created_on' => 'DATETIME NULL',
  71. 'updated_on' => 'DATETIME NULL',
  72. 'reported_by' => 'VARCHAR(100) NULL',
  73. 'assigned_to' => 'VARCHAR(100) NULL',
  74. 'verified_by' => 'VARCHAR(100) NULL'
  75. );
  76. }
  77. protected function _getSqlCreateTable($tableName)
  78. {
  79. $sql = "exec sp_tables @table_name = " . $this->_db->quoteIdentifier($tableName, true);
  80. $stmt = $this->_db->query($sql);
  81. $tableList = $stmt->fetchAll(Zend_Db::FETCH_ASSOC);
  82. if (count($tableList) > 0 && $tableName == $tableList[0]['TABLE_NAME']) {
  83. return null;
  84. }
  85. return 'CREATE TABLE ' . $this->_db->quoteIdentifier($tableName);
  86. }
  87. private function _getSqlDropElement($elementName, $typeElement = 'TABLE')
  88. {
  89. $sql = "exec sp_tables @table_name = " . $this->_db->quoteIdentifier($elementName, true);
  90. $stmt = $this->_db->query($sql);
  91. $elementList = $stmt->fetchAll(Zend_Db::FETCH_ASSOC);
  92. if (count($elementList) > 0 && $elementName == $elementList[0]['TABLE_NAME']) {
  93. return "DROP $typeElement " . $this->_db->quoteIdentifier($elementName);
  94. }
  95. return null;
  96. }
  97. protected function _getSqlDropTable($tableName)
  98. {
  99. return $this->_getSqlDropElement($tableName);
  100. }
  101. protected function _getSqlDropView($viewName)
  102. {
  103. return $this->_getSqlDropElement($viewName, 'VIEW');
  104. }
  105. public function createView()
  106. {
  107. parent::dropView();
  108. parent::createView();
  109. }
  110. }