public function testMergeWithHavingConditions()
 {
     $c1 = new Criteria();
     $cton = $c1->getNewCriterion(BookPeer::TITLE, 'foo', Criteria::EQUAL);
     $c1->addHaving($cton);
     $c2 = new Criteria();
     $c1->mergeWith($c2);
     $sql = 'SELECT  FROM  HAVING book.TITLE=:p1';
     $this->assertCriteriaTranslation($c1, $sql, 'mergeWith() does not remove an existing having condition');
     $c1 = new Criteria();
     $c2 = new Criteria();
     $cton = $c2->getNewCriterion(BookPeer::TITLE, 'foo', Criteria::EQUAL);
     $c2->addHaving($cton);
     $c1->mergeWith($c2);
     $sql = 'SELECT  FROM  HAVING book.TITLE=:p1';
     $this->assertCriteriaTranslation($c1, $sql, 'mergeWith() merges having condition to an empty having');
     $c1 = new Criteria();
     $cton = $c1->getNewCriterion(BookPeer::TITLE, 'foo', Criteria::EQUAL);
     $c1->addHaving($cton);
     $c2 = new Criteria();
     $cton = $c2->getNewCriterion(BookPeer::TITLE, 'bar', Criteria::EQUAL);
     $c2->addHaving($cton);
     $c1->mergeWith($c2);
     $sql = 'SELECT  FROM  HAVING (book.TITLE=:p1 AND book.TITLE=:p2)';
     $this->assertCriteriaTranslation($c1, $sql, 'mergeWith() combines having with AND');
 }
Exemple #2
0
 public function testHavingRaw()
 {
     $c = new Criteria();
     $c->addSelectColumn(BookPeer::TITLE);
     $c->addAsColumn("isb_n", BookPeer::ISBN);
     $c->addHaving('isb_n = ?', '1234567890123', PDO::PARAM_STR);
     $expected = 'SELECT book.TITLE, book.ISBN AS isb_n FROM book HAVING isb_n = :p1';
     $params = array();
     $result = BasePeer::createSelectSql($c, $params);
     $this->assertEquals($expected, $result);
     BasePEer::doSelect($c, $this->con);
     $expected = 'SELECT book.TITLE, book.ISBN AS isb_n FROM book HAVING isb_n = \'1234567890123\'';
     $this->assertEquals($expected, $this->con->getLastExecutedQuery());
 }
 /**
  * Tests including aliases in criterion objects.
  * @link       http://propel.phpdb.org/trac/ticket/636
  */
 public function testAliasInCriterion()
 {
     $c = new Criteria();
     $c->addAsColumn("column_alias", "tbl.COL1");
     $crit = $c->getNewCriterion("column_alias", "FOO");
     $this->assertNull($crit->getTable());
     $this->assertEquals("column_alias", $crit->getColumn());
     $c->addHaving($crit);
     // produces invalid SQL referring to '.olumn_alias'
 }