修改表中的部分数据

@param array [1] $row <列名>=><值>
@param mixed $where 请参考createWhere
@return mixed
486371
public function update(array $row, $where = null)
    {
        // updated字段是表必备字段,并自动更新
        if ($this->enableAutoField()) {
            $row['updated'] = date('Y-m-d H:i:s');
        }

        // 执行前置钩子
        $ret = $this->before('Update', $row, $where);
        if ($ret === self::INTERRUPT) {
            return null;
        }

        //修正请求参数
        list($row, $where) = $ret;

        // 记录修改操作
        $this->statement->update($row, $where);

        //是否需要记录文本日志
        if (self::logEnabled()) {
            //复制原Statement,因为下面的Count要用.
            $statement = clone $this->statement;

            //查看满足条件的记录数
            $count = $this->count($where);

            //恢复Statement
            $this->statement = $statement;

            //记录日志,如果影响行数过多,则不记录之前,之后的数据
            $result = self::log('update', ['data' => $row, 'where' => $where], '*', $where, $count <= 20, $count <= 20);
        } else {
            $result = $this->execute2();
        }

        // 执行后置钩子
        return $this->after('Update', $result);
    }
132085
public static function count($where)
     {
         $self = self::instance();
         $rows = new ModelArray();
         //
         $sql = 'select count(*) as cnt from '.$self->DBtable." where $where ";
         $data = Database::read($sql, 1);
         //
         return $data[0]['cnt'];
     }
342076
public function countBy(array $where = [])
    {
        $query = $this->make();

        $query = $this->applyWhere($query, $where);

        return $query->count();
    }
475148
public function create($row = array()){
        $class = $this->modelClass;
        $model = new $class($this->db, $row);
        $model->setAttribute('table', $this->table)->setAttribute('pk', $this->pk);
        
        return $model;
    }
981954
public function delete($where, $table = null)
    {
        if (is_array($where)) {
            $pk = $where[$this->getPrimaryKey()];
        } else {
            $pk = (int)$where;
        }

        $row = $this->getPosition($pk);

        $where = new Where;
        $where->between(self::COLUMN_LEFT, $row->getLft(), $row->getRgt());

        $result = parent::delete($where, $table);

        if ($result) {
            $this->updateTree($row->getRgt(), '-', $row->width());
        }

        return $result;
    }
1085897
public static function findCreate(array $where) {
        $item = self::find($where);
        if (!$item) {
            $model = get_called_class();
            /* @var $item Record */
            $item = new $model;
            $item->fromArray($where);
        }
        return $item;
    }
351078
protected function prepare($where)
    {
        if (is_string($where)) {
            return str_replace('{@}', $this->alias, $where);
        }

        if (!is_array($where)) {
            return $where;
        }

        $result = [];
        foreach ($where as $column => $value) {
            if (is_string($column) && !is_int($column)) {
                $column = str_replace('{@}', $this->alias, $column);
            }

            $result[$column] = !is_array($value) ? $value : $this->prepare($value);
        }

        return $result;
    }
78694
public function fetchRow(array $where = null, array $column = null, array $order = null)
    {
        $qp = $this->_fetch($where, $column, $order);

        $row = $this->_fetchRow($qp['query'], $qp['params']);
        $className = $this->_rowClass;
        $class = new $className($this);

        if (!$row) {
            return false;
        }

        $class->setData($row);

        return $class;
    }
1178724
public function delete($where, $table = null)
    {
        $table = ($table) ?: $this->getTable();
        $sql = $this->getSql();
        $delete = $sql->delete($table);

        $delete->where($where);

        $statement = $sql->prepareStatementForSqlObject($delete);
        $result = $statement->execute();

        return $result->getAffectedRows();
    }
18646
private function build_where(array $where_array){
        $where_clause = [];
        $counter = 0;
        foreach( $where_array as list($glue, $where) ){
            if( $counter ){
                $where_clause[] = $glue;
            }
            if( is_array($where) ){
                $where_clause[] = $this->build_where($where_array);
            }else{
                $where_clause[] = sprintf('(%s)', $where);
            }
            $counter++;
        }
        return sprintf('(%s)', implode(' ', $where_clause));
    }
321474
public function getBy(array $where = [], array $with = [])
    {
        $query = $this->make($with);

        $query = $this->applyWhere($query, $where);

        return $query->get();
    }
27695
public static function select($where = null)
    {
        $query = static::parseWhere(static::query(), $where);

        // 查询前
        Event::trigger(static::__getRealClassName() . ':' . ModelEvents::BEFORE_SELECT, [
            'query' => $query,
        ], null, \Imi\Model\Event\Param\BeforeSelectEventParam::class);

        $result = $query->select()->getArray();

        // 查询后
        Event::trigger(static::__getRealClassName() . ':' . ModelEvents::AFTER_SELECT, [
            'result' => &$result,
        ], null, \Imi\Model\Event\Param\AfterSelectEventParam::class);

        return $result;
    }
1117110
public function GetCountWhere($Where = FALSE) {
      if (is_array($Where))
         $this->SQL->Where($Where);
         
      return $this->SQL->Select('CommentID', 'count', 'CountComments')
         ->From('Comment')
         ->Get()
         ->FirstRow()
         ->CountComments;
   }
816555
public function buildQuery(string $table, array $where): SqlParams
    {
        $whereClause = $this->buildWhereClause($where);
        $sql = "DELETE FROM {$table}" . $whereClause->getSql();
        return new SqlParams($sql, $whereClause->getParams());
    }
1117787
public final function inflateFromDB($where) {
        $data = $this->loadFromDb($where);
        if (!$data) {//加载失败时将条件做为数据填充
            $data = $where;
        }

        return $this->inflateByData($data);
    }
949335
public function update(array $data, array $where = [])
    {
        // Prepare query
        $query = $this->genUpdate($data, $where);
        $statement = $this->getInstance()->prepare($query);

        // Bind field values
        foreach ($data as $key => $value) {
            $statement->bindValue(":field_$key", $value, $this->isPdoInt($value));
        }

        // Bind where values
        foreach ($where as $key => $value) {
            $statement->bindValue(":where_$key", $value, $this->isPdoInt($value));
        }

        // Execute operation
        $statement->execute();

        // Return count of affected rows
        return $statement->rowCount();
    }
294587
public function getRows($table, $columns, $where)
    {
        $columns = implode(',', $columns);
        $sql = "SELECT {$columns} FROM {$table}";

        if ($where) {
            $sql .= " WHERE {$where}";
        }

        $stmt = $this->pdo->query($sql);
        while ($row = $stmt->fetch()) {
            yield $row;
        }
    }