Mysqli.php 4.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156
  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_Common
  24. */
  25. require_once 'Zend/Db/TestUtil/Common.php';
  26. /**
  27. * @category Zend
  28. * @package Zend_Db
  29. * @subpackage Table
  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_Mysqli extends Zend_Db_TestUtil_Common
  34. {
  35. public function getParams(array $constants = array())
  36. {
  37. $constants = array(
  38. 'host' => 'TESTS_ZEND_DB_ADAPTER_MYSQL_HOSTNAME',
  39. 'username' => 'TESTS_ZEND_DB_ADAPTER_MYSQL_USERNAME',
  40. 'password' => 'TESTS_ZEND_DB_ADAPTER_MYSQL_PASSWORD',
  41. 'dbname' => 'TESTS_ZEND_DB_ADAPTER_MYSQL_DATABASE',
  42. 'port' => 'TESTS_ZEND_DB_ADAPTER_MYSQL_PORT'
  43. );
  44. return parent::getParams($constants);
  45. }
  46. public function getSqlType($type)
  47. {
  48. if ($type == 'IDENTITY') {
  49. return 'INTEGER NOT NULL PRIMARY KEY AUTO_INCREMENT';
  50. }
  51. if ($type == 'CLOB') {
  52. return 'TEXT';
  53. }
  54. return $type;
  55. }
  56. protected function _getSqlCreateTable($tableName)
  57. {
  58. return 'CREATE TABLE IF NOT EXISTS ' . $this->_db->quoteIdentifier($tableName);
  59. }
  60. protected function _getSqlCreateTableType()
  61. {
  62. return ' ENGINE=InnoDB';
  63. }
  64. protected function _getSqlDropTable($tableName)
  65. {
  66. return 'DROP TABLE IF EXISTS ' . $this->_db->quoteIdentifier($tableName);
  67. }
  68. protected function _rawQuery($sql)
  69. {
  70. $mysqli = $this->_db->getConnection();
  71. $retval = $mysqli->query($sql);
  72. if (!$retval) {
  73. $e = $mysqli->error;
  74. require_once 'Zend/Db/Exception.php';
  75. throw new Zend_Db_Exception("SQL error for \"$sql\": $e");
  76. }
  77. }
  78. /**
  79. * Test that describeTable() returns correct float type
  80. * @group ZF-3624
  81. */
  82. protected function _getColumnsPrice()
  83. {
  84. return array(
  85. 'product_id' => 'INTEGER NOT NULL',
  86. 'price_name' => 'VARCHAR(100)',
  87. 'price' => 'FLOAT(10,8)',
  88. 'price_total' => 'DECIMAL(10,2) NOT NULL',
  89. 'PRIMARY KEY' => 'product_id'
  90. );
  91. }
  92. /**
  93. * Test that describeTable() returns correct float type
  94. * @group ZF-3624
  95. */
  96. protected function _getDataPrice()
  97. {
  98. return array(
  99. array(
  100. 'product_id' => 1,
  101. 'price_name' => 'Price 1',
  102. 'price_total' => 200.45
  103. )
  104. );
  105. }
  106. public function setUp(Zend_Db_Adapter_Abstract $db)
  107. {
  108. parent::setUp($db);
  109. $this->_createTestProcedure();
  110. }
  111. public function tearDown()
  112. {
  113. $this->_dropTestProcedure();
  114. parent::tearDown();
  115. }
  116. protected function _createTestProcedure()
  117. {
  118. $this->_tryRawQuery('DROP PROCEDURE IF EXISTS zf_test_procedure');
  119. $this->_tryRawQuery('CREATE PROCEDURE zf_test_procedure(IN param1 INTEGER) BEGIN SELECT * FROM zfproducts WHERE product_id = param1; END');
  120. }
  121. protected function _dropTestProcedure()
  122. {
  123. $this->_tryRawQuery('DROP PROCEDURE IF EXISTS zf_test_procedure');
  124. }
  125. protected function _getSqlCreateView($viewName)
  126. {
  127. return 'CREATE OR REPLACE VIEW ' . $this->_db->quoteIdentifier($viewName, true);
  128. }
  129. protected function _getSqlDropView($viewName)
  130. {
  131. return 'DROP VIEW IF EXISTS ' . $this->_db->quoteIdentifier($viewName, true);
  132. }
  133. }