2
0

Db2Test.php 4.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136
  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. require_once 'Zend/Db/Statement/TestCommon.php';
  23. PHPUnit_Util_Filter::addFileToFilter(__FILE__);
  24. /**
  25. * @category Zend
  26. * @package Zend_Db
  27. * @subpackage UnitTests
  28. * @copyright Copyright (c) 2005-2009 Zend Technologies USA Inc. (http://www.zend.com)
  29. * @license http://framework.zend.com/license/new-bsd New BSD License
  30. * @group Zend_Db
  31. * @group Zend_Db_Statement
  32. */
  33. class Zend_Db_Statement_Db2Test extends Zend_Db_Statement_TestCommon
  34. {
  35. public function testStatementErrorCodeKeyViolation()
  36. {
  37. $this->markTestIncomplete($this->getDriver() . ' does not return error codes correctly.');
  38. }
  39. public function testStatementErrorInfoKeyViolation()
  40. {
  41. $this->markTestIncomplete($this->getDriver() . ' does not return error codes correctly.');
  42. }
  43. public function testStatementColumnCountForSelect()
  44. {
  45. $select = $this->_db->select()
  46. ->from('zfproducts');
  47. $stmt = $this->_db->prepare($select->__toString());
  48. $n = $stmt->columnCount();
  49. // DB2 returns the column count once the query has been prepared
  50. // while PDO returns it only after it has been executed
  51. $this->assertEquals(2, $n);
  52. $stmt->execute();
  53. $n = $stmt->columnCount();
  54. $stmt->closeCursor();
  55. $this->assertType('integer', $n);
  56. $this->assertEquals(2, $n);
  57. }
  58. public function testStatementBindParamByPosition()
  59. {
  60. $this->markTestIncomplete($this->getDriver() . ' is having trouble with binding params');
  61. }
  62. public function testStatementBindParamByName()
  63. {
  64. $products = $this->_db->quoteIdentifier('zfproducts');
  65. $product_id = $this->_db->quoteIdentifier('product_id');
  66. $product_name = $this->_db->quoteIdentifier('product_name');
  67. $productIdValue = 4;
  68. $productNameValue = 'AmigaOS';
  69. try {
  70. $stmt = $this->_db->prepare("INSERT INTO $products ($product_id, $product_name) VALUES (:id, :name)");
  71. // test with colon prefix
  72. $this->assertTrue($stmt->bindParam(':id', $productIdValue), 'Expected bindParam(\':id\') to return true');
  73. // test with no colon prefix
  74. $this->assertTrue($stmt->bindParam('name', $productNameValue), 'Expected bindParam(\'name\') to return true');
  75. $this->fail('Expected to catch Zend_Db_Statement_Exception');
  76. } catch (Zend_Exception $e) {
  77. $this->assertType('Zend_Db_Statement_Exception', $e,
  78. 'Expecting object of type Zend_Db_Statement_Exception, got '.get_class($e));
  79. $this->assertEquals("Invalid bind-variable name ':id'", $e->getMessage());
  80. }
  81. }
  82. public function testStatementBindValueByPosition()
  83. {
  84. $this->markTestIncomplete($this->getDriver() . ' is having trouble with binding params');
  85. }
  86. public function testStatementBindValueByName()
  87. {
  88. $products = $this->_db->quoteIdentifier('zfproducts');
  89. $product_id = $this->_db->quoteIdentifier('product_id');
  90. $product_name = $this->_db->quoteIdentifier('product_name');
  91. $productIdValue = 4;
  92. $productNameValue = 'AmigaOS';
  93. try {
  94. $stmt = $this->_db->prepare("INSERT INTO $products ($product_id, $product_name) VALUES (:id, :name)");
  95. // test with colon prefix
  96. $this->assertTrue($stmt->bindParam(':id', $productIdValue), 'Expected bindParam(\':id\') to return true');
  97. // test with no colon prefix
  98. $this->assertTrue($stmt->bindParam('name', $productNameValue), 'Expected bindParam(\'name\') to return true');
  99. $this->fail('Expected to catch Zend_Db_Statement_Exception');
  100. } catch (Zend_Exception $e) {
  101. $this->assertType('Zend_Db_Statement_Exception', $e,
  102. 'Expecting object of type Zend_Db_Statement_Exception, got '.get_class($e));
  103. $this->assertEquals("Invalid bind-variable name ':id'", $e->getMessage());
  104. }
  105. }
  106. public function testStatementGetColumnMeta()
  107. {
  108. $this->markTestIncomplete($this->getDriver() . ' has not implemented getColumnMeta() yet [ZF-1424]');
  109. }
  110. public function getDriver()
  111. {
  112. return 'Db2';
  113. }
  114. }