本文整理匯總了PHP中Propel\Runtime\ActiveQuery\Criteria::doUpdate方法的典型用法代碼示例。如果您正苦於以下問題:PHP Criteria::doUpdate方法的具體用法?PHP Criteria::doUpdate怎麽用?PHP Criteria::doUpdate使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類Propel\Runtime\ActiveQuery\Criteria
的用法示例。
在下文中一共展示了Criteria::doUpdate方法的4個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的PHP代碼示例。
示例1: testDoUpdate
public function testDoUpdate()
{
try {
$c1 = new Criteria();
$c1->setPrimaryTableName(BookTableMap::TABLE_NAME);
$c1->add(BookTableMap::ID, 12, ' BAD SQL');
$c2 = new Criteria();
$c2->add(BookTableMap::TITLE, 'Foo');
$c1->doUpdate($c2, Propel::getServiceContainer()->getWriteConnection(BookTableMap::DATABASE_NAME));
$this->fail('Missing expected exception on BAD SQL');
} catch (PropelException $e) {
$this->assertContains($this->getSql('[UPDATE `book` SET `TITLE`=:p1 WHERE book.ID BAD SQL:p2]'), $e->getMessage(), 'SQL query is written in the exception message');
}
}
示例2: testCommentDoUpdate
public function testCommentDoUpdate()
{
$c1 = new Criteria();
$c1->setPrimaryTableName(BookTableMap::TABLE_NAME);
$c1->setComment('Foo');
$c2 = new Criteria();
$c2->add(BookTableMap::COL_TITLE, 'Updated Title');
$con = Propel::getServiceContainer()->getConnection(BookTableMap::DATABASE_NAME);
$c1->doUpdate($c2, $con);
$expected = $this->getSql('UPDATE /* Foo */ `book` SET `TITLE`=\'Updated Title\'');
$this->assertEquals($expected, $con->getLastExecutedQuery(), 'Criteria::setComment() adds a comment to update queries');
}
示例3: shiftLevel
/**
* Adds $delta to level for nodes having left value >= $first and right value <= $last.
* '$delta' can also be negative.
*
* @param int $delta Value to be shifted by, can be negative
* @param int $first First node to be shifted
* @param int $last Last node to be shifted
* @param ConnectionInterface $con Connection to use.
*/
public static function shiftLevel($delta, $first, $last, ConnectionInterface $con = null)
{
if ($con === null) {
$con = Propel::getServiceContainer()->getWriteConnection(CategoryTableMap::DATABASE_NAME);
}
$whereCriteria = new Criteria(CategoryTableMap::DATABASE_NAME);
$whereCriteria->add(ChildCategory::LEFT_COL, $first, Criteria::GREATER_EQUAL);
$whereCriteria->add(ChildCategory::RIGHT_COL, $last, Criteria::LESS_EQUAL);
$valuesCriteria = new Criteria(CategoryTableMap::DATABASE_NAME);
$valuesCriteria->add(ChildCategory::LEVEL_COL, array('raw' => ChildCategory::LEVEL_COL . ' + ?', 'value' => $delta), Criteria::CUSTOM_EQUAL);
$whereCriteria->doUpdate($valuesCriteria, $con);
}
示例4: sortableShiftRank
/**
* Adds $delta to all Rank values that are >= $first and <= $last.
* '$delta' can also be negative.
*
* @param int $delta Value to be shifted by, can be negative
* @param int $first First node to be shifted
* @param int $last Last node to be shifted
* @param ConnectionInterface $con Connection to use.
*/
public static function sortableShiftRank($delta, $first, $last = null, ConnectionInterface $con = null)
{
if (null === $con) {
$con = Propel::getServiceContainer()->getWriteConnection(WorkTableMap::DATABASE_NAME);
}
$whereCriteria = new Criteria(WorkTableMap::DATABASE_NAME);
$criterion = $whereCriteria->getNewCriterion(WorkTableMap::RANK_COL, $first, Criteria::GREATER_EQUAL);
if (null !== $last) {
$criterion->addAnd($whereCriteria->getNewCriterion(WorkTableMap::RANK_COL, $last, Criteria::LESS_EQUAL));
}
$whereCriteria->add($criterion);
$valuesCriteria = new Criteria(WorkTableMap::DATABASE_NAME);
$valuesCriteria->add(WorkTableMap::RANK_COL, array('raw' => WorkTableMap::RANK_COL . ' + ?', 'value' => $delta), Criteria::CUSTOM_EQUAL);
$whereCriteria->doUpdate($valuesCriteria, $con);
WorkTableMap::clearInstancePool();
}