2
0

SqliteTest.php 6.1 KB

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