2
0

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