FirebirdTest.php 5.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175
  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 ZendX
  16. * @package ZendX_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. */
  21. require_once 'Zend/Db/Select/TestCommon.php';
  22. PHPUnit_Util_Filter::addFileToFilter(__FILE__);
  23. class ZendX_Db_Select_FirebirdTest extends Zend_Db_Select_TestCommon
  24. {
  25. public function testSelectWhereWithTypeFloat()
  26. {
  27. $this->markTestIncomplete($this->getDriver() . ' (setlocale bugging subsequent tests)');
  28. }
  29. protected function _selectOrderByAutoExpr()
  30. {
  31. $products = $this->_db->quoteIdentifier('zfproducts');
  32. $product_id = $this->_db->quoteIdentifier('product_id');
  33. $select = $this->_db->select()
  34. ->from('zfproducts')
  35. ->order("UPPER($products.$product_id)");
  36. return $select;
  37. }
  38. protected function _selectColumnWithColonQuotedParameter()
  39. {
  40. $product_id = $this->_db->quoteIdentifier('product_id');
  41. $select = $this->_db->select()
  42. ->from('zfproducts')
  43. ->where("'as''as:xX'" . ' = ?', $this->_db->quote("as'as:x"));
  44. return $select;
  45. }
  46. public function testSelectFromSelectObject ()
  47. {
  48. $select = $this->_selectFromSelectObject();
  49. $query = $select->assemble();
  50. $cmp = 'SELECT ' . $this->_db->quoteIdentifier('t') . '.* FROM (SELECT '
  51. . $this->_db->quoteIdentifier('subqueryTable') . '.* FROM '
  52. . $this->_db->quoteIdentifier('subqueryTable') . ') '
  53. . $this->_db->quoteIdentifier('t');
  54. $this->assertEquals($query, $cmp);
  55. }
  56. protected function _selectGroupByAutoExpr()
  57. {
  58. $thecount = $this->_db->quoteIdentifier('thecount');
  59. $bugs_products = $this->_db->quoteIdentifier('zfbugs_products');
  60. $bug_id = $this->_db->quoteIdentifier('bug_id');
  61. $select = $this->_db->select()
  62. ->from('zfbugs_products', array('bug_id'=>"UPPER($bugs_products.$bug_id)", new Zend_Db_Expr("COUNT(*) AS $thecount")))
  63. ->group("UPPER($bugs_products.$bug_id)")
  64. ->order("UPPER($bugs_products.$bug_id)");
  65. return $select;
  66. }
  67. /**
  68. * Test the UNION statement for a Zend_Db_Select object.
  69. */
  70. protected function _selectUnionString()
  71. {
  72. $bugs = $this->_db->quoteIdentifier('zfbugs');
  73. $bug_id = $this->_db->quoteIdentifier('bug_id');
  74. $bug_status = $this->_db->quoteIdentifier('bug_status');
  75. $products = $this->_db->quoteIdentifier('zfproducts');
  76. $product_id = $this->_db->quoteIdentifier('product_id');
  77. $product_name = $this->_db->quoteIdentifier('product_name');
  78. $id = $this->_db->quoteIdentifier('id');
  79. $name = $this->_db->quoteIdentifier('name');
  80. $sql1 = "SELECT $bug_id AS $id, $bug_status AS $name FROM $bugs";
  81. $sql2 = "SELECT $product_id AS $id, $product_name AS $name FROM $products";
  82. $select = $this->_db->select()
  83. ->union(array($sql1, $sql2))
  84. ->order(new Zend_Db_Expr('1'));
  85. return $select;
  86. }
  87. public function testSelectFromQualified()
  88. {
  89. $this->markTestSkipped($this->getDriver() . ' does not report its schema as we expect.');
  90. }
  91. public function testSelectJoinQualified()
  92. {
  93. $this->markTestSkipped($this->getDriver() . ' does not report its schema as we expect.');
  94. }
  95. public function testSelectJoin()
  96. {
  97. $select = $this->_selectJoin();
  98. $stmt = $this->_db->query($select);
  99. $result = $stmt->fetchAll();
  100. $this->assertEquals(6, count($result));
  101. $this->assertEquals(4, count($result[0]));
  102. }
  103. public function testSelectJoinInner()
  104. {
  105. $select = $this->_selectJoinInner();
  106. $stmt = $this->_db->query($select);
  107. $result = $stmt->fetchAll();
  108. $this->assertEquals(6, count($result));
  109. $this->assertEquals(4, count($result[0]));
  110. }
  111. public function testSelectJoinRight()
  112. {
  113. $select = $this->_selectJoinRight();
  114. $stmt = $this->_db->query($select);
  115. $result = $stmt->fetchAll();
  116. $this->assertEquals(7, count($result));
  117. $this->assertEquals(10, count($result[0]));
  118. $this->assertEquals(3, $result[3]['product_id']);
  119. $this->assertNull($result[6]['product_id']);
  120. }
  121. public function testSelectJoinLeft()
  122. {
  123. $select = $this->_selectJoinLeft();
  124. $stmt = $this->_db->query($select);
  125. $result = $stmt->fetchAll();
  126. $this->assertEquals(7, count($result));
  127. $this->assertEquals(10, count($result[0]));
  128. $this->assertEquals(3, $result[3]['product_id']);
  129. $this->assertNull($result[6]['product_id']);
  130. }
  131. public function testSelectJoinCross()
  132. {
  133. $select = $this->_selectJoinCross();
  134. $stmt = $this->_db->query($select);
  135. $result = $stmt->fetchAll();
  136. $this->assertEquals(18, count($result));
  137. $this->assertEquals(4, count($result[0]));
  138. }
  139. public function testSelectJoinWithCorrelationName()
  140. {
  141. $select = $this->_selectJoinWithCorrelationName();
  142. $stmt = $this->_db->query($select);
  143. $result = $stmt->fetchAll();
  144. $this->assertEquals(1, count($result));
  145. $this->assertEquals(4, count($result[0]));
  146. }
  147. public function getDriver()
  148. {
  149. return 'Firebird';
  150. }
  151. }