Пример #1
0
 /**
  * 减小符合条件的记录的指定字段的值,返回更新的记录总数
  *
  * 该操作不会引发任何事件,也不会处理关联数据。
  *
  * @param mixed $conditions
  * @param string $field
  * @param int $decr
  *
  * @return mixed
  */
 function decrField($conditions, $field, $decr = 1)
 {
     $field = $this->dbo->qfield($field, $this->fullTableName, $this->schema);
     $decr = (int) $decr;
     $row = array();
     $this->_setUpdatedTimeFields($row);
     list($pairs, $values) = $this->dbo->getPlaceholderPair($row, $this->fields);
     $pairs = implode(',', $pairs);
     if ($pairs) {
         $pairs = ', ' . $pairs;
     }
     $whereby = $this->getWhere($conditions, false);
     $sql = "UPDATE {$this->qtableName} SET {$field} = {$field}- {$decr}{$pairs} {$whereby}";
     return $this->dbo->execute($sql, $values);
 }