Example #1
0
 public function testCreateSelectSqlPart()
 {
     Propel::setDb('oracle', new DBOracle());
     $db = Propel::getDB();
     $c = new Criteria();
     $c->addSelectColumn(BookPeer::ID);
     $c->addAsColumn('book_ID', BookPeer::ID);
     $fromClause = array();
     $selectSql = $db->createSelectSqlPart($c, $fromClause);
     $this->assertEquals('SELECT book.ID, book.ID AS book_ID', $selectSql, 'createSelectSqlPart() returns a SQL SELECT clause with both select and as columns');
     $this->assertEquals(array('book'), $fromClause, 'createSelectSqlPart() adds the tables from the select columns to the from clause');
 }
Example #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());
 }
 public function testMergeWithSelectColumns()
 {
     $c1 = new Criteria();
     $c1->addSelectColumn(BookPeer::TITLE);
     $c1->addSelectColumn(BookPeer::ID);
     $c2 = new Criteria();
     $c1->mergeWith($c2);
     $this->assertEquals(array(BookPeer::TITLE, BookPeer::ID), $c1->getSelectColumns(), 'mergeWith() does not remove an existing select columns');
     $c1 = new Criteria();
     $c2 = new Criteria();
     $c2->addSelectColumn(BookPeer::TITLE);
     $c2->addSelectColumn(BookPeer::ID);
     $c1->mergeWith($c2);
     $this->assertEquals(array(BookPeer::TITLE, BookPeer::ID), $c1->getSelectColumns(), 'mergeWith() merges the select columns to an empty select');
     $c1 = new Criteria();
     $c1->addSelectColumn(BookPeer::TITLE);
     $c2 = new Criteria();
     $c2->addSelectColumn(BookPeer::ID);
     $c1->mergeWith($c2);
     $this->assertEquals(array(BookPeer::TITLE, BookPeer::ID), $c1->getSelectColumns(), 'mergeWith() merges the select columns after the existing select columns');
     $c1 = new Criteria();
     $c1->addSelectColumn(BookPeer::TITLE);
     $c2 = new Criteria();
     $c2->addSelectColumn(BookPeer::TITLE);
     $c1->mergeWith($c2);
     $this->assertEquals(array(BookPeer::TITLE, BookPeer::TITLE), $c1->getSelectColumns(), 'mergeWith() merges the select columns to an existing select, even if duplicated');
 }
Example #4
0
 public function testCreateSelectSqlPartAliasAll()
 {
     $db = Propel::getDB(BookPeer::DATABASE_NAME);
     $c = new Criteria();
     $c->addSelectColumn(BookPeer::ID);
     $c->addAsColumn('book_ID', BookPeer::ID);
     $fromClause = array();
     $selectSql = $db->createSelectSqlPart($c, $fromClause, true);
     $this->assertEquals('SELECT book.ID AS book_ID_1, book.ID AS book_ID', $selectSql, 'createSelectSqlPart() aliases all columns if passed true as last parameter');
     $this->assertEquals(array(), $fromClause, 'createSelectSqlPart() does not add the tables from an all-aliased list of select columns');
 }
Example #5
0
 public function testCommentDoSelect()
 {
     $c = new Criteria();
     $c->setComment('Foo');
     $c->addSelectColumn(BookPeer::ID);
     $expected = 'SELECT /* Foo */ book.ID FROM `book`';
     $params = array();
     $this->assertEquals($expected, BasePeer::createSelectSQL($c, $params), 'Criteria::setComment() adds a comment to select queries');
 }
Example #6
0
 /**
  * @link       http://propel.phpdb.org/trac/ticket/634
  */
 public function testHasSelectClause()
 {
     $c = new Criteria();
     $c->addSelectColumn("foo");
     $this->assertTrue($c->hasSelectClause());
     $c = new Criteria();
     $c->addAsColumn("foo", "bar");
     $this->assertTrue($c->hasSelectClause());
 }