Db2Test.php 4.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135
  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/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_Db2Test extends Zend_Db_Statement_TestCommon
  33. {
  34. public function testStatementErrorCodeKeyViolation()
  35. {
  36. $this->markTestIncomplete($this->getDriver() . ' does not return error codes correctly.');
  37. }
  38. public function testStatementErrorInfoKeyViolation()
  39. {
  40. $this->markTestIncomplete($this->getDriver() . ' does not return error codes correctly.');
  41. }
  42. public function testStatementColumnCountForSelect()
  43. {
  44. $select = $this->_db->select()
  45. ->from('zfproducts');
  46. $stmt = $this->_db->prepare($select->__toString());
  47. $n = $stmt->columnCount();
  48. // DB2 returns the column count once the query has been prepared
  49. // while PDO returns it only after it has been executed
  50. $this->assertEquals(2, $n);
  51. $stmt->execute();
  52. $n = $stmt->columnCount();
  53. $stmt->closeCursor();
  54. $this->assertTrue(is_int($n));
  55. $this->assertEquals(2, $n);
  56. }
  57. public function testStatementBindParamByPosition()
  58. {
  59. $this->markTestIncomplete($this->getDriver() . ' is having trouble with binding params');
  60. }
  61. public function testStatementBindParamByName()
  62. {
  63. $products = $this->_db->quoteIdentifier('zfproducts');
  64. $product_id = $this->_db->quoteIdentifier('product_id');
  65. $product_name = $this->_db->quoteIdentifier('product_name');
  66. $productIdValue = 4;
  67. $productNameValue = 'AmigaOS';
  68. try {
  69. $stmt = $this->_db->prepare("INSERT INTO $products ($product_id, $product_name) VALUES (:id, :name)");
  70. // test with colon prefix
  71. $this->assertTrue($stmt->bindParam(':id', $productIdValue), 'Expected bindParam(\':id\') to return true');
  72. // test with no colon prefix
  73. $this->assertTrue($stmt->bindParam('name', $productNameValue), 'Expected bindParam(\'name\') to return true');
  74. $this->fail('Expected to catch Zend_Db_Statement_Exception');
  75. } catch (Zend_Exception $e) {
  76. $this->assertTrue($e instanceof Zend_Db_Statement_Exception,
  77. 'Expecting object of type Zend_Db_Statement_Exception, got '.get_class($e));
  78. $this->assertEquals("Invalid bind-variable name ':id'", $e->getMessage());
  79. }
  80. }
  81. public function testStatementBindValueByPosition()
  82. {
  83. $this->markTestIncomplete($this->getDriver() . ' is having trouble with binding params');
  84. }
  85. public function testStatementBindValueByName()
  86. {
  87. $products = $this->_db->quoteIdentifier('zfproducts');
  88. $product_id = $this->_db->quoteIdentifier('product_id');
  89. $product_name = $this->_db->quoteIdentifier('product_name');
  90. $productIdValue = 4;
  91. $productNameValue = 'AmigaOS';
  92. try {
  93. $stmt = $this->_db->prepare("INSERT INTO $products ($product_id, $product_name) VALUES (:id, :name)");
  94. // test with colon prefix
  95. $this->assertTrue($stmt->bindParam(':id', $productIdValue), 'Expected bindParam(\':id\') to return true');
  96. // test with no colon prefix
  97. $this->assertTrue($stmt->bindParam('name', $productNameValue), 'Expected bindParam(\'name\') to return true');
  98. $this->fail('Expected to catch Zend_Db_Statement_Exception');
  99. } catch (Zend_Exception $e) {
  100. $this->assertTrue($e instanceof Zend_Db_Statement_Exception,
  101. 'Expecting object of type Zend_Db_Statement_Exception, got '.get_class($e));
  102. $this->assertEquals("Invalid bind-variable name ':id'", $e->getMessage());
  103. }
  104. }
  105. public function testStatementGetColumnMeta()
  106. {
  107. $this->markTestIncomplete($this->getDriver() . ' has not implemented getColumnMeta() yet [ZF-1424]');
  108. }
  109. public function getDriver()
  110. {
  111. return 'Db2';
  112. }
  113. }