本文整理匯總了PHP中Propel\Runtime\ActiveQuery\Criteria::setDistinct方法的典型用法代碼示例。如果您正苦於以下問題:PHP Criteria::setDistinct方法的具體用法?PHP Criteria::setDistinct怎麽用?PHP Criteria::setDistinct使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類Propel\Runtime\ActiveQuery\Criteria
的用法示例。
在下文中一共展示了Criteria::setDistinct方法的4個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的PHP代碼示例。
示例1: testMultipleFunctionInCriteria
/**
* @link http://propel.phpdb.org/trac/ticket/425
*/
public function testMultipleFunctionInCriteria()
{
$db = Propel::getServiceContainer()->getAdapter(BookTableMap::DATABASE_NAME);
try {
$c = new Criteria();
$c->setDistinct();
if ($db instanceof PgsqlAdapter) {
$c->addSelectColumn("substring(" . BookTableMap::TITLE . " from position('Potter' in " . BookTableMap::TITLE . ")) AS col");
} else {
$this->markTestSkipped('Configured database vendor is not PostgreSQL');
}
$obj = BookQuery::create(null, $c)->find();
} catch (PropelException $x) {
$this->fail("Paring of nested functions failed: " . $x->getMessage());
}
}
示例2: testCreateSelectSqlPartSelectModifier
public function testCreateSelectSqlPartSelectModifier()
{
$db = Propel::getServiceContainer()->getAdapter(BookTableMap::DATABASE_NAME);
$c = new Criteria();
$c->addSelectColumn(BookTableMap::COL_ID);
$c->addAsColumn('book_id', BookTableMap::COL_ID);
$c->setDistinct();
$fromClause = [];
$selectSql = $db->createSelectSqlPart($c, $fromClause);
$this->assertEquals('SELECT DISTINCT book.id, book.id AS book_id', $selectSql, 'createSelectSqlPart() includes the select modifiers in the SELECT clause');
$this->assertEquals(['book'], $fromClause, 'createSelectSqlPart() adds the tables from the select columns to the from clause');
}
示例3: testAddSelectModifier
public function testAddSelectModifier()
{
$c = new Criteria();
$c->setDistinct();
$c->addSelectModifier('SQL_CALC_FOUND_ROWS');
$this->assertEquals(array(Criteria::DISTINCT, 'SQL_CALC_FOUND_ROWS'), $c->getSelectModifiers(), 'addSelectModifier() adds a select modifier to the Criteria');
$c->addSelectModifier('SQL_CALC_FOUND_ROWS');
$this->assertEquals(array(Criteria::DISTINCT, 'SQL_CALC_FOUND_ROWS'), $c->getSelectModifiers(), 'addSelectModifier() adds a select modifier only once');
$params = array();
$result = $c->createSelectSql($params);
$this->assertEquals('SELECT DISTINCT SQL_CALC_FOUND_ROWS FROM ', $result, 'addSelectModifier() adds a modifier to the final query');
}
示例4: testMergeWithSelectModifiers
public function testMergeWithSelectModifiers()
{
$c1 = new Criteria();
$c1->setDistinct();
$c2 = new Criteria();
$c1->mergeWith($c2);
$this->assertEquals(array(Criteria::DISTINCT), $c1->getSelectModifiers(), 'mergeWith() does not remove an existing select modifier');
$c1 = new Criteria();
$c2 = new Criteria();
$c2->setDistinct();
$c1->mergeWith($c2);
$this->assertEquals(array(Criteria::DISTINCT), $c1->getSelectModifiers(), 'mergeWith() merges the select modifiers');
$c1 = new Criteria();
$c1->setDistinct();
$c2 = new Criteria();
$c2->setDistinct();
$c1->mergeWith($c2);
$this->assertEquals(array(Criteria::DISTINCT), $c1->getSelectModifiers(), 'mergeWith() does not duplicate select modifiers');
$c1 = new Criteria();
$c1->setAll();
$c2 = new Criteria();
$c2->setDistinct();
$c1->mergeWith($c2);
$this->assertEquals(array(Criteria::ALL), $c1->getSelectModifiers(), 'mergeWith() does not merge the select modifiers in case of conflict');
}