OciTest.php 9.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267
  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-2010 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/Adapter/Pdo/TestCommon.php';
  23. PHPUnit_Util_Filter::addFileToFilter(__FILE__);
  24. /**
  25. * @category Zend
  26. * @package Zend_Db
  27. * @subpackage UnitTests
  28. * @copyright Copyright (c) 2005-2010 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_Adapter
  32. */
  33. class Zend_Db_Adapter_Pdo_OciTest extends Zend_Db_Adapter_Pdo_TestCommon
  34. {
  35. protected $_numericDataTypes = array(
  36. Zend_Db::INT_TYPE => Zend_Db::INT_TYPE,
  37. Zend_Db::BIGINT_TYPE => Zend_Db::BIGINT_TYPE,
  38. Zend_Db::FLOAT_TYPE => Zend_Db::FLOAT_TYPE,
  39. 'BINARY_DOUBLE' => Zend_Db::FLOAT_TYPE,
  40. 'BINARY_FLOAT' => Zend_Db::FLOAT_TYPE,
  41. 'NUMBER' => Zend_Db::FLOAT_TYPE
  42. );
  43. public function testAdapterDescribeTablePrimaryAuto()
  44. {
  45. $this->markTestSkipped('Oracle does not support auto-increment');
  46. }
  47. public function testAdapterDescribeTablePrimaryKeyColumn()
  48. {
  49. $desc = $this->_db->describeTable('zfproducts');
  50. $this->assertEquals('zfproducts', $desc['product_id']['TABLE_NAME']);
  51. $this->assertEquals('product_id', $desc['product_id']['COLUMN_NAME']);
  52. $this->assertEquals(1, $desc['product_id']['COLUMN_POSITION']);
  53. $this->assertEquals('', $desc['product_id']['DEFAULT']);
  54. $this->assertFalse( $desc['product_id']['NULLABLE']);
  55. $this->assertEquals(0, $desc['product_id']['SCALE']);
  56. // Oracle reports precsion 11 for integers
  57. $this->assertEquals(11, $desc['product_id']['PRECISION']);
  58. $this->assertTrue( $desc['product_id']['PRIMARY'], 'Expected product_id to be a primary key');
  59. $this->assertEquals(1, $desc['product_id']['PRIMARY_POSITION']);
  60. $this->assertFalse( $desc['product_id']['IDENTITY']);
  61. }
  62. public function testAdapterInsert()
  63. {
  64. $row = array (
  65. 'product_id' => new Zend_Db_Expr($this->_db->quoteIdentifier('zfproducts_seq').'.NEXTVAL'),
  66. 'product_name' => 'Solaris',
  67. );
  68. $rowsAffected = $this->_db->insert('zfproducts', $row);
  69. $this->assertEquals(1, $rowsAffected);
  70. $lastInsertId = $this->_db->lastInsertId('zfproducts', null); // implies 'products_seq'
  71. $lastSequenceId = $this->_db->lastSequenceId('zfproducts_seq');
  72. $this->assertType('string', $lastInsertId);
  73. $this->assertType('string', $lastSequenceId);
  74. $this->assertEquals('4', (string) $lastInsertId, 'Expected new id to be 4');
  75. $this->assertEquals('4', (string) $lastSequenceId, 'Expected new id to be 4');
  76. }
  77. public function testAdapterInsertDbExpr()
  78. {
  79. $row = array (
  80. 'product_id' => new Zend_Db_Expr($this->_db->quoteIdentifier('zfproducts_seq').'.NEXTVAL'),
  81. 'product_name' => new Zend_Db_Expr('UPPER(\'Solaris\')')
  82. );
  83. $rowsAffected = $this->_db->insert('zfproducts', $row);
  84. $this->assertEquals(1, $rowsAffected);
  85. $product_id = $this->_db->quoteIdentifier('product_id', true);
  86. $select = $this->_db->select()
  87. ->from('zfproducts')
  88. ->where("$product_id = 4");
  89. $result = $this->_db->fetchAll($select);
  90. $this->assertType('array', $result);
  91. $this->assertEquals('SOLARIS', $result[0]['product_name']);
  92. }
  93. /**
  94. * Used by _testAdapterOptionCaseFoldingNatural()
  95. * DB2 and Oracle return identifiers in uppercase naturally,
  96. * so those test suites will override this method.
  97. */
  98. protected function _testAdapterOptionCaseFoldingNaturalIdentifier()
  99. {
  100. return 'CASE_FOLDED_IDENTIFIER';
  101. }
  102. /**
  103. * Test that quote() takes an array and returns
  104. * an imploded string of comma-separated, quoted elements.
  105. */
  106. public function testAdapterQuoteArray()
  107. {
  108. $array = array("it's", 'all', 'right!');
  109. $value = $this->_db->quote($array);
  110. $this->assertEquals("'it''s', 'all', 'right!'", $value);
  111. }
  112. /**
  113. * test that quote() escapes a double-quote
  114. * character in a string.
  115. */
  116. public function testAdapterQuoteDoubleQuote()
  117. {
  118. $string = 'St John"s Wort';
  119. $value = $this->_db->quote($string);
  120. $this->assertEquals("'St John\"s Wort'", $value);
  121. }
  122. /**
  123. * test that quote() escapes a single-quote
  124. * character in a string.
  125. */
  126. public function testAdapterQuoteSingleQuote()
  127. {
  128. $string = "St John's Wort";
  129. $value = $this->_db->quote($string);
  130. $this->assertEquals("'St John''s Wort'", $value);
  131. }
  132. /**
  133. * test that quoteInto() escapes a double-quote
  134. * character in a string.
  135. */
  136. public function testAdapterQuoteIntoDoubleQuote()
  137. {
  138. $string = 'id=?';
  139. $param = 'St John"s Wort';
  140. $value = $this->_db->quoteInto($string, $param);
  141. $this->assertEquals("id='St John\"s Wort'", $value);
  142. }
  143. /**
  144. * test that quoteInto() escapes a single-quote
  145. * character in a string.
  146. */
  147. public function testAdapterQuoteIntoSingleQuote()
  148. {
  149. $string = 'id = ?';
  150. $param = 'St John\'s Wort';
  151. $value = $this->_db->quoteInto($string, $param);
  152. $this->assertEquals("id = 'St John''s Wort'", $value);
  153. }
  154. /**
  155. * test that quoteTableAs() accepts a string and an alias,
  156. * and returns each as delimited identifiers.
  157. * Oracle does not want the 'AS' in between.
  158. */
  159. public function testAdapterQuoteTableAs()
  160. {
  161. $string = "foo";
  162. $alias = "bar";
  163. $value = $this->_db->quoteTableAs($string, $alias);
  164. $this->assertEquals('"foo" "bar"', $value);
  165. }
  166. /**
  167. * @group ZF-5146
  168. */
  169. public function testAdapterReadClobFetchAll()
  170. {
  171. $documents = $this->_db->quoteIdentifier('zfdocuments');
  172. $document_id = $this->_db->quoteIdentifier('doc_id');
  173. $value = $this->_db->fetchAll("SELECT * FROM $documents WHERE $document_id = 1");
  174. $expected = 'this is the clob that never ends...'.
  175. 'this is the clob that never ends...'.
  176. 'this is the clob that never ends...';
  177. $this->assertEquals($expected, stream_get_contents($value[0]['doc_clob']));
  178. }
  179. /**
  180. * @group ZF-5146
  181. */
  182. public function testAdapterReadClobFetchRow()
  183. {
  184. $documents = $this->_db->quoteIdentifier('zfdocuments');
  185. $document_id = $this->_db->quoteIdentifier('doc_id');
  186. $value = $this->_db->fetchRow("SELECT * FROM $documents WHERE $document_id = 1");
  187. $expected = 'this is the clob that never ends...'.
  188. 'this is the clob that never ends...'.
  189. 'this is the clob that never ends...';
  190. $this->assertEquals($expected, stream_get_contents($value['doc_clob']));
  191. }
  192. /**
  193. * @group ZF-5146
  194. */
  195. public function testAdapterReadClobFetchAssoc()
  196. {
  197. $documents = $this->_db->quoteIdentifier('zfdocuments');
  198. $document_id = $this->_db->quoteIdentifier('doc_id');
  199. $value = $this->_db->fetchAssoc("SELECT * FROM $documents WHERE $document_id = 1");
  200. $expected = 'this is the clob that never ends...'.
  201. 'this is the clob that never ends...'.
  202. 'this is the clob that never ends...';
  203. $this->assertEquals($expected, stream_get_contents($value[1]['doc_clob']));
  204. }
  205. /**
  206. * @group ZF-5146
  207. */
  208. public function testAdapterReadClobFetchCol()
  209. {
  210. $documents = $this->_db->quoteIdentifier('zfdocuments');
  211. $document_id = $this->_db->quoteIdentifier('doc_id');
  212. $document_clob = $this->_db->quoteIdentifier('doc_clob');
  213. $value = $this->_db->fetchCol("SELECT $document_clob FROM $documents WHERE $document_id = 1");
  214. $expected = 'this is the clob that never ends...'.
  215. 'this is the clob that never ends...'.
  216. 'this is the clob that never ends...';
  217. $this->assertEquals($expected, stream_get_contents($value[0]));
  218. }
  219. /**
  220. * @group ZF-5146
  221. */
  222. public function testAdapterReadClobFetchOne()
  223. {
  224. $documents = $this->_db->quoteIdentifier('zfdocuments');
  225. $document_id = $this->_db->quoteIdentifier('doc_id');
  226. $document_clob = $this->_db->quoteIdentifier('doc_clob');
  227. $value = $this->_db->fetchOne("SELECT $document_clob FROM $documents WHERE $document_id = 1");
  228. $expected = 'this is the clob that never ends...'.
  229. 'this is the clob that never ends...'.
  230. 'this is the clob that never ends...';
  231. $this->assertEquals($expected, stream_get_contents($value));
  232. }
  233. /**
  234. * @group ZF-8399
  235. */
  236. public function testLongQueryWithTextField()
  237. {
  238. $this->markTestSkipped($this->getDriver() . ' does not have TEXT field type');
  239. }
  240. public function getDriver()
  241. {
  242. return 'Pdo_Oci';
  243. }
  244. }