FirebirdTest.php 5.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174
  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/Table/Select/TestCommon.php';
  22. PHPUnit_Util_Filter::addFileToFilter(__FILE__);
  23. class ZendX_Db_Table_Select_FirebirdTest extends Zend_Db_Table_Select_TestCommon
  24. {
  25. public function testSelectWhereWithTypeFloat()
  26. {
  27. $this->markTestIncomplete($this->getDriver() . ' (setlocale bugging subsequent tests)');
  28. }
  29. public function testSelectFromSelectObject ()
  30. {
  31. $select = $this->_selectFromSelectObject();
  32. $query = $select->assemble();
  33. $cmp = 'SELECT ' . $this->_db->quoteIdentifier('t') . '.* FROM (SELECT '
  34. . $this->_db->quoteIdentifier('subqueryTable') . '.* FROM '
  35. . $this->_db->quoteIdentifier('subqueryTable') . ') '
  36. . $this->_db->quoteIdentifier('t');
  37. $this->assertEquals($query, $cmp);
  38. }
  39. /**
  40. * Test the UNION statement for a Zend_Db_Select object.
  41. */
  42. protected function _selectUnionString()
  43. {
  44. $bugs = $this->_db->quoteIdentifier('zfbugs');
  45. $bug_id = $this->_db->quoteIdentifier('bug_id');
  46. $bug_status = $this->_db->quoteIdentifier('bug_status');
  47. $products = $this->_db->quoteIdentifier('zfproducts');
  48. $product_id = $this->_db->quoteIdentifier('product_id');
  49. $product_name = $this->_db->quoteIdentifier('product_name');
  50. $id = $this->_db->quoteIdentifier('id');
  51. $name = $this->_db->quoteIdentifier('name');
  52. $sql1 = "SELECT $bug_id AS $id, $bug_status AS $name FROM $bugs";
  53. $sql2 = "SELECT $product_id AS $id, $product_name AS $name FROM $products";
  54. $select = $this->_db->select()
  55. ->union(array($sql1, $sql2))
  56. ->order(new Zend_Db_Expr('1'));
  57. return $select;
  58. }
  59. protected function _selectColumnWithColonQuotedParameter()
  60. {
  61. $product_id = $this->_db->quoteIdentifier('product_id');
  62. $select = $this->_db->select()
  63. ->from('zfproducts')
  64. ->where("'as''as:xX'" . ' = ?', $this->_db->quote("as'as:x"));
  65. return $select;
  66. }
  67. protected function _selectOrderByAutoExpr()
  68. {
  69. $products = $this->_db->quoteIdentifier('zfproducts');
  70. $product_id = $this->_db->quoteIdentifier('product_id');
  71. $select = $this->_db->select()
  72. ->from('zfproducts')
  73. ->order("UPPER($products.$product_id)");
  74. return $select;
  75. }
  76. protected function _selectGroupByAutoExpr()
  77. {
  78. $thecount = $this->_db->quoteIdentifier('thecount');
  79. $bugs_products = $this->_db->quoteIdentifier('zfbugs_products');
  80. $bug_id = $this->_db->quoteIdentifier('bug_id');
  81. $select = $this->_db->select()
  82. ->from('zfbugs_products', array('bug_id'=>"UPPER($bugs_products.$bug_id)", new Zend_Db_Expr("COUNT(*) AS $thecount")))
  83. ->group("UPPER($bugs_products.$bug_id)")
  84. ->order("UPPER($bugs_products.$bug_id)");
  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. }