SqlsrvTest.php 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120
  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. /**
  24. * @category Zend
  25. * @package Zend_Db
  26. * @subpackage UnitTests
  27. * @copyright Copyright (c) 2005-2009 Zend Technologies USA Inc. (http://www.zend.com)
  28. * @license http://framework.zend.com/license/new-bsd New BSD License
  29. */
  30. class Zend_Db_Statement_SqlsrvTest extends Zend_Db_Statement_TestCommon
  31. {
  32. // http://msdn.microsoft.com/en-us/library/cc296197(SQL.90).aspx
  33. protected $_getColumnMetaKeys = array(
  34. 'Name' , 'Type', 'Size', 'Precision', 'Scale', 'Nullable'
  35. );
  36. public function testStatementExecuteWithParams()
  37. {
  38. $products = $this->_db->quoteIdentifier('zfproducts');
  39. // Make IDENTITY column accept explicit value.
  40. // This can be done in only one table in a given session.
  41. sqlsrv_query($this->_db->getConnection(), "SET IDENTITY_INSERT $products ON");
  42. parent::testStatementExecuteWithParams();
  43. sqlsrv_query($this->_db->getConnection(), "SET IDENTITY_INSERT $products OFF");
  44. }
  45. public function testStatementBindParamByName()
  46. {
  47. $this->markTestSkipped($this->getDriver() . ' does not support bind by name.');
  48. }
  49. public function testStatementBindValueByName()
  50. {
  51. $this->markTestSkipped($this->getDriver() . ' does not support bind by name.');
  52. }
  53. public function testStatementBindParamByPosition()
  54. {
  55. $this->markTestSkipped($this->getDriver() . ' does not support bind by position.');
  56. }
  57. public function testStatementBindValueByPosition()
  58. {
  59. $this->markTestSkipped($this->getDriver() . ' does not support bind by position.');
  60. }
  61. public function testStatementNextRowset()
  62. {
  63. $products = $this->_db->quoteIdentifier('zfproducts');
  64. $product_id = $this->_db->quoteIdentifier('product_id');
  65. $query = "SELECT * FROM $products WHERE $product_id > 1 ORDER BY $product_id ASC";
  66. $stmt = $this->_db->query($query . ';' . $query);
  67. $result1 = $stmt->fetchAll();
  68. $stmt->nextRowset();
  69. $result2 = $stmt->fetchAll();
  70. $this->assertEquals(count($result1), count($result2));
  71. $this->assertEquals($result1, $result2);
  72. $stmt->closeCursor();
  73. }
  74. public function testStatementErrorInfo()
  75. {
  76. $products = $this->_db->quoteIdentifier('zfproducts');
  77. $product_id = $this->_db->quoteIdentifier('product_id');
  78. $query = "INVALID SELECT * FROM INVALID TABLE WHERE $product_id > 1 ORDER BY $product_id ASC";
  79. $stmt = new Zend_Db_Statement_Sqlsrv($this->_db, $query);
  80. try {
  81. $stmt->fetchAll();
  82. $this->fail("Invalid query should have throw an error");
  83. } catch (Zend_Db_Statement_Sqlsrv_Exception $e) {
  84. // Exception is thrown, nothing to worry about
  85. $this->assertEquals(-11, $e->getCode());
  86. }
  87. $this->assertNotSame(false, $stmt->errorCode());
  88. $this->assertEquals(-11, $stmt->errorCode());
  89. $errors = $stmt->errorInfo();
  90. $this->assertEquals(2, count($errors));
  91. $this->assertEquals($stmt->errorCode(), $errors[0]);
  92. $this->assertType('string', $errors[1]);
  93. }
  94. public function getDriver()
  95. {
  96. return 'Sqlsrv';
  97. }
  98. }