本文整理汇总了PHP中Criteria::isUseTransaction方法的典型用法代码示例。如果您正苦于以下问题:PHP Criteria::isUseTransaction方法的具体用法?PHP Criteria::isUseTransaction怎么用?PHP Criteria::isUseTransaction使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Criteria
的用法示例。
在下文中一共展示了Criteria::isUseTransaction方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: doCount
/**
* Executes a COUNT query using either a simple SQL rewrite or, for more complex queries, a
* sub-select of the SQL created by createSelectSql() and returns the statement.
*
* @param Criteria $criteria A Criteria.
* @param PropelPDO $con A PropelPDO connection to use.
* @return PDOStatement The resultset statement.
* @throws PropelException
* @see createSelectSql()
*/
public static function doCount(Criteria $criteria, PropelPDO $con = null)
{
$dbMap = Propel::getDatabaseMap($criteria->getDbName());
$db = Propel::getDB($criteria->getDbName());
if ($con === null) {
$con = Propel::getConnection($criteria->getDbName(), Propel::CONNECTION_READ);
}
$stmt = null;
if ($criteria->isUseTransaction()) {
$con->beginTransaction();
}
$needsComplexCount = $criteria->getGroupByColumns() || $criteria->getOffset() || $criteria->getLimit() || $criteria->getHaving() || in_array(Criteria::DISTINCT, $criteria->getSelectModifiers());
try {
$params = array();
if ($needsComplexCount) {
if (self::needsSelectAliases($criteria)) {
if ($criteria->getHaving()) {
throw new PropelException('Propel cannot create a COUNT query when using HAVING and duplicate column names in the SELECT part');
}
self::turnSelectColumnsToAliases($criteria);
}
$selectSql = self::createSelectSql($criteria, $params);
$sql = 'SELECT COUNT(*) FROM (' . $selectSql . ') propelmatch4cnt';
} else {
// Replace SELECT columns with COUNT(*)
$criteria->clearSelectColumns()->addSelectColumn('COUNT(*)');
$sql = self::createSelectSql($criteria, $params);
}
$stmt = $con->prepare($sql);
self::populateStmtValues($stmt, $params, $dbMap, $db);
$stmt->execute();
if ($criteria->isUseTransaction()) {
$con->commit();
}
} catch (Exception $e) {
if ($stmt !== null) {
$stmt = null;
}
if ($criteria->isUseTransaction()) {
$con->rollBack();
}
Propel::log($e->getMessage(), Propel::LOG_ERR);
throw new PropelException(sprintf('Unable to execute COUNT statement [%s]', $sql), $e);
}
return $stmt;
}
示例2: doSelect
/**
* Executes query build by createSelectSql() and returns ResultSet.
*
* @param Criteria $criteria A Criteria.
* @param Connection $con A connection to use.
* @return ResultSet The resultset.
* @throws PropelException
* @see createSelectSql()
*/
public static function doSelect(Criteria $criteria, $con = null)
{
$arrTables = array_keys($criteria->getTablesColumns());
if (sizeof($arrTables) > 1) {
$arrJoins = array();
foreach ($criteria->getJoins() as $objJoin) {
if (false) {
$objJoin = new Join();
}
$arrJoins[] = $objJoin->getLeftTableName();
$arrJoins[] = $objJoin->getRightTableName();
}
array_unique($arrJoins);
$arrMissedJoinsWhatever = array_diff($arrTables, $arrJoins);
}
// endif
$dbMap = Propel::getDatabaseMap($criteria->getDbName());
if ($con === null) {
$con = Propel::getConnection($criteria->getDbName());
}
$stmt = null;
try {
// Transaction support exists for (only?) Postgres, which must
// have SELECT statements that include bytea columns wrapped w/
// transactions.
if ($criteria->isUseTransaction()) {
$con->begin();
}
$params = array();
$sql = self::createSelectSql($criteria, $params);
$stmt = $con->prepareStatement($sql);
$stmt->setLimit($criteria->getLimit());
$stmt->setOffset($criteria->getOffset());
self::populateStmtValues($stmt, $params, $dbMap);
$rs = $stmt->executeQuery(ResultSet::FETCHMODE_NUM);
if ($criteria->isUseTransaction()) {
$con->commit();
}
} catch (Exception $e) {
if ($stmt) {
$stmt->close();
}
if ($criteria->isUseTransaction()) {
$con->rollback();
}
Propel::log($e->getMessage(), Propel::LOG_ERR);
throw new PropelException($e);
}
if (isset($arrMissedJoinsWhatever) && sizeof($arrMissedJoinsWhatever)) {
$strBody = "The probable error, a lack of joins tables " . var_export($arrMissedJoinsWhatever, true) . " in query: \n\n" . $sql;
// $strBody .= "\n\n".sfContext::getInstance()->getRequest()->getUri();
throw new Exception($strBody);
}
// endif
return $rs;
}
示例3: doSelect
/**
* Executes query build by createSelectSql() and returns ResultSet.
*
* @param Criteria $criteria A Criteria.
* @param Connection $con A connection to use.
* @return ResultSet The resultset.
* @throws PropelException
* @see createSelectSql()
*/
public static function doSelect(Criteria $criteria, $con = null)
{
$dbMap = Propel::getDatabaseMap($criteria->getDbName());
if ($con === null) {
$con = Propel::getConnection($criteria->getDbName());
}
$stmt = null;
try {
// Transaction support exists for (only?) Postgres, which must
// have SELECT statements that include bytea columns wrapped w/
// transactions.
if ($criteria->isUseTransaction()) {
$con->begin();
}
$params = array();
$sql = self::createSelectSql($criteria, $params);
$stmt = $con->prepareStatement($sql);
$stmt->setLimit($criteria->getLimit());
$stmt->setOffset($criteria->getOffset());
self::populateStmtValues($stmt, $params, $dbMap);
$rs = $stmt->executeQuery(ResultSet::FETCHMODE_NUM);
if ($criteria->isUseTransaction()) {
$con->commit();
}
} catch (Exception $e) {
if ($stmt) {
$stmt->close();
}
if ($criteria->isUseTransaction()) {
$con->rollback();
}
Propel::log($e->getMessage(), Propel::LOG_ERR);
throw new PropelException($e);
}
return $rs;
}
示例4: doCount
/**
* Executes a COUNT query using either a simple SQL rewrite or, for more complex queries, a
* sub-select of the SQL created by createSelectSql() and returns the statement.
*
* @param Criteria $criteria A Criteria.
* @param PropelPDO $con A PropelPDO connection to use.
* @return PDOStatement The resultset statement.
* @throws PropelException
* @see createSelectSql()
*/
public static function doCount(Criteria $criteria, PropelPDO $con = null)
{
$dbMap = Propel::getDatabaseMap($criteria->getDbName());
$db = Propel::getDB($criteria->getDbName());
if ($con === null) {
$con = Propel::getConnection($criteria->getDbName(), Propel::CONNECTION_READ);
}
$stmt = null;
if ($criteria->isUseTransaction()) {
$con->beginTransaction();
}
$needsComplexCount = $criteria->getGroupByColumns() || $criteria->getOffset() || $criteria->getLimit() || $criteria->getHaving() || in_array(Criteria::DISTINCT, $criteria->getSelectModifiers());
try {
$params = array();
if ($needsComplexCount) {
$selectSql = self::createSelectSql($criteria, $params);
$sql = 'SELECT COUNT(*) FROM (' . $selectSql . ') AS propelmatch4cnt';
} else {
// Replace SELECT columns with COUNT(*)
$criteria->clearSelectColumns()->addSelectColumn('COUNT(*)');
$sql = self::createSelectSql($criteria, $params);
}
$stmt = $con->prepare($sql);
self::populateStmtValues($stmt, $params, $dbMap, $db);
$stmt->execute();
if ($criteria->isUseTransaction()) {
$con->commit();
}
} catch (Exception $e) {
if ($stmt) {
$stmt = null;
}
// close
if ($criteria->isUseTransaction()) {
$con->rollBack();
}
Propel::log($e->getMessage(), Propel::LOG_ERR);
throw new PropelException($e);
}
return $stmt;
}