Db2Test.php 4.6 KB

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