本文整理匯總了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;
}