MysqlTest.php 3.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798
  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-2012 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. require_once 'Zend/Db/Statement/Pdo/TestCommon.php';
  23. /**
  24. * @category Zend
  25. * @package Zend_Db
  26. * @subpackage UnitTests
  27. * @copyright Copyright (c) 2005-2012 Zend Technologies USA Inc. (http://www.zend.com)
  28. * @license http://framework.zend.com/license/new-bsd New BSD License
  29. * @group Zend_Db
  30. * @group Zend_Db_Statement
  31. */
  32. class Zend_Db_Statement_Pdo_MysqlTest extends Zend_Db_Statement_Pdo_TestCommon
  33. {
  34. public function testStatementNextRowset()
  35. {
  36. $select = $this->_db->select()
  37. ->from('zfproducts');
  38. $stmt = $this->_db->prepare($select->__toString());
  39. try {
  40. $stmt->nextRowset();
  41. } catch (Zend_Db_Statement_Exception $e) {
  42. $this->assertTrue($e instanceof Zend_Db_Statement_Exception,
  43. 'Expecting object of type Zend_Db_Statement_Exception, got '.get_class($e));
  44. $this->assertEquals('SQLSTATE[HYC00]: Optional feature not implemented', $e->getMessage());
  45. }
  46. $stmt->closeCursor();
  47. }
  48. /**
  49. * Ensures that the character sequence ":0'" is handled properly
  50. *
  51. * @link http://framework.zend.com/issues/browse/ZF-2059
  52. * @return void
  53. */
  54. public function testZF2059()
  55. {
  56. $sql = "SELECT bug_id FROM zfbugs WHERE bug_status != ':0'";
  57. $results = $this->_db->fetchAll($sql);
  58. $this->assertEquals(4, count($results));
  59. $select = $this->_db->select()->from('zfbugs', 'bug_id')
  60. ->where('bug_status != ?', ':0');
  61. $results = $this->_db->fetchAll($select);
  62. $this->assertEquals(4, count($results));
  63. }
  64. /**
  65. * @group ZF-7706
  66. */
  67. public function testStatementCanReturnDriverStatement()
  68. {
  69. $statement = parent::testStatementCanReturnDriverStatement();
  70. $this->assertTrue($statement->getDriverStatement() instanceof PDOStatement);
  71. }
  72. public function testStatementExceptionMessageContainsSqlQuery()
  73. {
  74. $sql = "SELECT * FROM nonexistent";
  75. try {
  76. $stmt = $this->_db->query($sql);
  77. } catch (Zend_Db_Statement_Exception $e) {
  78. $message = $e->getMessage();
  79. $this->assertContains($sql, $message);
  80. return;
  81. }
  82. $this->fail('Expected exception');
  83. }
  84. public function getDriver()
  85. {
  86. return 'Pdo_Mysql';
  87. }
  88. }