IbmTest.php 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105
  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-2008 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/Pdo/TestCommon.php';
  22. PHPUnit_Util_Filter::addFileToFilter(__FILE__);
  23. class Zend_Db_Statement_Pdo_IbmTest extends Zend_Db_Statement_Pdo_TestCommon
  24. {
  25. public function getDriver()
  26. {
  27. return 'Pdo_Ibm';
  28. }
  29. /**
  30. * used by testStatementGetColumnMeta()
  31. *
  32. */
  33. protected $_getColumnMetaKeys = array(
  34. 'scale', 'table', 'native_type', 'flags', 'name', 'len', 'precision', 'pdo_type'
  35. );
  36. public function testStatementNextRowset()
  37. {
  38. $select = $this->_db->select()
  39. ->from('zfproducts');
  40. $stmt = $this->_db->prepare($select->__toString());
  41. $result = $stmt->nextRowset();
  42. // there is no next rowset so $result should be false
  43. $this->assertFalse($result);
  44. $stmt->closeCursor();
  45. }
  46. public function testStatementColumnCountForSelect()
  47. {
  48. $select = $this->_db->select()
  49. ->from('zfproducts');
  50. $stmt = $this->_db->prepare($select->__toString());
  51. $n = $stmt->columnCount();
  52. $this->assertEquals(2, $n);
  53. $stmt->execute();
  54. $n = $stmt->columnCount();
  55. $stmt->closeCursor();
  56. $this->assertType('integer', $n);
  57. $this->assertEquals(2, $n);
  58. }
  59. public function testStatementGetSetAttribute()
  60. {
  61. $select = $this->_db->select()
  62. ->from('zfproducts');
  63. $stmt = $this->_db->prepare($select->__toString());
  64. $value = 'value';
  65. try {
  66. $stmt->setAttribute(1234, $value);
  67. } catch (Zend_Exception $e) {
  68. $this->assertContains('This driver doesn\'t support setting attributes', $e->getMessage());
  69. }
  70. try {
  71. $this->assertEquals($value, $stmt->getAttribute(1234), "Expected '$value' #1");
  72. } catch (Zend_Exception $e) {
  73. $this->assertContains('Driver does not support this function: 1 Unknown attribute', $e->getMessage());
  74. return;
  75. }
  76. $valueArray = array('value1', 'value2');
  77. $stmt->setAttribute(1235, $valueArray);
  78. $this->assertEquals($valueArray, $stmt->getAttribute(1235), "Expected array #1");
  79. $this->assertEquals($value, $stmt->getAttribute(1234), "Expected '$value' #2");
  80. $valueObject = new stdClass();
  81. $stmt->setAttribute(1236, $valueObject);
  82. $this->assertSame($valueObject, $stmt->getAttribute(1236), "Expected object");
  83. $this->assertEquals($valueArray, $stmt->getAttribute(1235), "Expected array #2");
  84. $this->assertEquals($value, $stmt->getAttribute(1234), "Expected '$value' #2");
  85. }
  86. }