當前位置: 首頁>>代碼示例>>PHP>>正文


PHP Criteria::getComparison方法代碼示例

本文整理匯總了PHP中Propel\Runtime\ActiveQuery\Criteria::getComparison方法的典型用法代碼示例。如果您正苦於以下問題:PHP Criteria::getComparison方法的具體用法?PHP Criteria::getComparison怎麽用?PHP Criteria::getComparison使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在Propel\Runtime\ActiveQuery\Criteria的用法示例。


在下文中一共展示了Criteria::getComparison方法的1個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的PHP代碼示例。

示例1: doUpdate

 /**
  * Method used to update rows in the DB.  Rows are selected based
  * on selectCriteria and updated using values in updateValues.
  * <p>
  * Use this method for performing an update of the kind:
  * <p>
  * WHERE some_column = some value AND could_have_another_column =
  * another value AND so on.
  *
  * @param Criteria            $updateValues A Criteria object containing values used in set clause.
  * @param ConnectionInterface $con          The ConnectionInterface connection object to use.
  *
  * @return int The number of rows affected by last update statement.
  *             For most uses there is only one update statement executed, so this number will
  *             correspond to the number of rows affected by the call to this method.
  *             Note that the return value does require that this information is returned
  *             (supported) by the Propel db driver.
  *
  * @throws PropelException
  */
 public function doUpdate($updateValues, ConnectionInterface $con)
 {
     /** @var PdoAdapter $db */
     $db = Propel::getServiceContainer()->getAdapter($this->getDbName());
     $dbMap = Propel::getServiceContainer()->getDatabaseMap($this->getDbName());
     // Get list of required tables, containing all columns
     $tablesColumns = $this->getTablesColumns();
     if (empty($tablesColumns) && ($table = $this->getPrimaryTableName())) {
         $tablesColumns = [$table => []];
     }
     // we also need the columns for the update SQL
     $updateTablesColumns = $updateValues->getTablesColumns();
     // If no columns are changing values, we may get here with
     // an empty array in $updateTablesColumns.  In that case,
     // there is nothing to do, so we return the rows affected,
     // which is 0.  Fixes a bug in which an UPDATE statement
     // would fail in this instance.
     if (empty($updateTablesColumns)) {
         return 0;
     }
     $affectedRows = 0;
     // initialize this in case the next loop has no iterations.
     foreach ($tablesColumns as $tableName => $columns) {
         $whereClause = [];
         $params = [];
         $stmt = null;
         try {
             $sql = 'UPDATE ';
             $queryComment = $this->getComment();
             if ($queryComment) {
                 $sql .= '/* ' . $queryComment . ' */ ';
             }
             // is it a table alias?
             $realTableName = $this->getTableForAlias($tableName);
             if ($realTableName) {
                 $updateTable = $realTableName . ' ' . $tableName;
                 $tableName = $realTableName;
             } else {
                 $updateTable = $tableName;
             }
             $sql .= $this->quoteIdentifierTable($updateTable);
             $sql .= " SET ";
             $p = 1;
             foreach ($updateTablesColumns[$tableName] as $col) {
                 $updateColumnName = substr($col, strrpos($col, '.') + 1);
                 // add identifiers for the actual database?
                 $updateColumnName = $this->quoteIdentifier($updateColumnName, $tableName);
                 if ($updateValues->getComparison($col) != Criteria::CUSTOM_EQUAL) {
                     $sql .= $updateColumnName . '=:p' . $p++ . ', ';
                 } else {
                     $param = $updateValues->get($col);
                     $sql .= $updateColumnName . ' = ';
                     if (is_array($param)) {
                         if (isset($param['raw'])) {
                             $raw = $param['raw'];
                             $rawcvt = '';
                             // parse the $params['raw'] for ? chars
                             for ($r = 0, $len = strlen($raw); $r < $len; $r++) {
                                 if ($raw[$r] == '?') {
                                     $rawcvt .= ':p' . $p++;
                                 } else {
                                     $rawcvt .= $raw[$r];
                                 }
                             }
                             $sql .= $rawcvt . ', ';
                         } else {
                             $sql .= ':p' . $p++ . ', ';
                         }
                         if (isset($param['value'])) {
                             $updateValues->put($col, $param['value']);
                         }
                     } else {
                         $updateValues->remove($col);
                         $sql .= $param . ', ';
                     }
                 }
             }
             $params = $this->buildParams($updateTablesColumns[$tableName], $updateValues);
             $sql = substr($sql, 0, -2);
             if (!empty($columns)) {
//.........這裏部分代碼省略.........
開發者ID:naldz,項目名稱:cyberden,代碼行數:101,代碼來源:Criteria.php


注:本文中的Propel\Runtime\ActiveQuery\Criteria::getComparison方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。