SqliteTest.php 6.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207
  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. /**
  23. * @see Zend_Db_Adapter_Pdo_TestCommon
  24. */
  25. require_once 'Zend/Db/Adapter/Pdo/TestCommon.php';
  26. PHPUnit_Util_Filter::addFileToFilter(__FILE__);
  27. /**
  28. * @category Zend
  29. * @package Zend_Db
  30. * @subpackage UnitTests
  31. * @copyright Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com)
  32. * @license http://framework.zend.com/license/new-bsd New BSD License
  33. * @group Zend_Db
  34. * @group Zend_Db_Adapter
  35. */
  36. class Zend_Db_Adapter_Pdo_SqliteTest extends Zend_Db_Adapter_Pdo_TestCommon
  37. {
  38. protected $_numericDataTypes = array(
  39. Zend_Db::INT_TYPE => Zend_Db::INT_TYPE,
  40. Zend_Db::BIGINT_TYPE => Zend_Db::BIGINT_TYPE,
  41. Zend_Db::FLOAT_TYPE => Zend_Db::FLOAT_TYPE,
  42. 'INTEGER' => Zend_Db::BIGINT_TYPE,
  43. 'REAL' => Zend_Db::FLOAT_TYPE
  44. );
  45. /**
  46. * Test AUTO_QUOTE_IDENTIFIERS option
  47. * Case: Zend_Db::AUTO_QUOTE_IDENTIFIERS = true
  48. *
  49. * SQLite actually allows delimited identifiers to remain
  50. * case-insensitive, so this test overrides its parent.
  51. */
  52. public function testAdapterAutoQuoteIdentifiersTrue()
  53. {
  54. $params = $this->_util->getParams();
  55. $params['options'] = array(
  56. Zend_Db::AUTO_QUOTE_IDENTIFIERS => true
  57. );
  58. $db = Zend_Db::factory($this->getDriver(), $params);
  59. $db->getConnection();
  60. $select = $this->_db->select();
  61. $select->from('zfproducts');
  62. $stmt = $this->_db->query($select);
  63. $result1 = $stmt->fetchAll();
  64. $this->assertEquals(1, $result1[0]['product_id']);
  65. $select = $this->_db->select();
  66. $select->from('ZFPRODUCTS');
  67. try {
  68. $stmt = $this->_db->query($select);
  69. $result2 = $stmt->fetchAll();
  70. } catch (Zend_Exception $e) {
  71. $this->assertType('Zend_Db_Statement_Exception', $e,
  72. 'Expecting object of type Zend_Db_Statement_Exception, got '.get_class($e));
  73. $this->fail('Unexpected exception '.get_class($e).' received: '.$e->getMessage());
  74. }
  75. $this->assertEquals($result1, $result2);
  76. }
  77. public function testAdapterConstructInvalidParamDbnameException()
  78. {
  79. $this->markTestSkipped($this->getDriver() . ' does not throw exception on missing dbname');
  80. }
  81. public function testAdapterConstructInvalidParamUsernameException()
  82. {
  83. $this->markTestSkipped($this->getDriver() . ' does not support login credentials');
  84. }
  85. public function testAdapterConstructInvalidParamPasswordException()
  86. {
  87. $this->markTestSkipped($this->getDriver() . ' does not support login credentials');
  88. }
  89. public function testAdapterInsertSequence()
  90. {
  91. $this->markTestSkipped($this->getDriver() . ' does not support sequences');
  92. }
  93. /**
  94. * Used by:
  95. * - testAdapterOptionCaseFoldingNatural()
  96. * - testAdapterOptionCaseFoldingUpper()
  97. * - testAdapterOptionCaseFoldingLower()
  98. */
  99. protected function _testAdapterOptionCaseFoldingSetup(Zend_Db_Adapter_Abstract $db)
  100. {
  101. $db->getConnection();
  102. $this->_util->setUp($db);
  103. }
  104. /**
  105. * Test that quote() takes an array and returns
  106. * an imploded string of comma-separated, quoted elements.
  107. */
  108. public function testAdapterQuoteArray()
  109. {
  110. $array = array("it's", 'all', 'right!');
  111. $value = $this->_db->quote($array);
  112. $this->assertEquals("'it''s', 'all', 'right!'", $value);
  113. }
  114. /**
  115. * test that quote() escapes a double-quote
  116. * character in a string.
  117. */
  118. public function testAdapterQuoteDoubleQuote()
  119. {
  120. $value = $this->_db->quote('St John"s Wort');
  121. $this->assertEquals("'St John\"s Wort'", $value);
  122. }
  123. /**
  124. * test that quote() escapes a single-quote
  125. * character in a string.
  126. */
  127. public function testAdapterQuoteSingleQuote()
  128. {
  129. $string = "St John's Wort";
  130. $value = $this->_db->quote($string);
  131. $this->assertEquals("'St John''s Wort'", $value);
  132. }
  133. /**
  134. * test that quoteInto() escapes a double-quote
  135. * character in a string.
  136. */
  137. public function testAdapterQuoteIntoDoubleQuote()
  138. {
  139. $value = $this->_db->quoteInto('id=?', 'St John"s Wort');
  140. $this->assertEquals("id='St John\"s Wort'", $value);
  141. }
  142. /**
  143. * test that quoteInto() escapes a single-quote
  144. * character in a string.
  145. */
  146. public function testAdapterQuoteIntoSingleQuote()
  147. {
  148. $value = $this->_db->quoteInto('id = ?', 'St John\'s Wort');
  149. $this->assertEquals("id = 'St John''s Wort'", $value);
  150. }
  151. public function testAdapterTransactionAutoCommit()
  152. {
  153. $this->markTestSkipped($this->getDriver() . ' does not support transactions or concurrency');
  154. }
  155. public function testAdapterTransactionCommit()
  156. {
  157. $this->markTestSkipped($this->getDriver() . ' does not support transactions or concurrency');
  158. }
  159. public function testAdapterTransactionRollback()
  160. {
  161. $this->markTestSkipped($this->getDriver() . ' does not support transactions or concurrency');
  162. }
  163. /**
  164. * @return void
  165. * @see http://framework.zend.com/issues/browse/ZF-2293
  166. */
  167. public function testAdapterSupportsLengthInTableMetadataForVarcharFields()
  168. {
  169. $metadata = $this->_db->describeTable('zfbugs');
  170. $this->assertEquals(100, $metadata['bug_description']['LENGTH']);
  171. $this->assertEquals(20, $metadata['bug_status']['LENGTH']);
  172. }
  173. public function getDriver()
  174. {
  175. return 'Pdo_Sqlite';
  176. }
  177. }