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'); } }
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'); }
/** * 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); }
/** * 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(); }