生成update SQL
@access public
@param Query     $query  查询对象
@return string
687
public function update(Query $query)
    {
        $options = $query->getOptions();

        $table = $this->parseTable($query, $options['table']);
        $data  = $this->parseData($query, $options['data']);

        if (empty($data)) {
            return '';
        }

        foreach ($data as $key => $val) {
            $set[] = $key . ' = ' . $val;
        }

        return str_replace(
            ['%TABLE%', '%SET%', '%JOIN%', '%WHERE%', '%ORDER%', '%LIMIT%', '%LOCK%', '%COMMENT%'],
            [
                $this->parseTable($query, $options['table']),
                implode(' , ', $set),
                $this->parseJoin($query, $options['join']),
                $this->parseWhere($query, $options['where']),
                $this->parseOrder($query, $options['order']),
                $this->parseLimit($query, $options['limit']),
                $this->parseLock($query, $options['lock']),
                $this->parseComment($query, $options['comment']),
            ],
            $this->updateSql);
    }
369336
public function pdo(Query $query)
    {
        // 分析查询表达式
        $options = $query->getOptions();

        // 生成查询SQL
        $sql = $this->builder->select($query);

        $bind = $query->getBind();

        if (!empty($options['fetch_sql'])) {
            // 获取实际执行的SQL语句
            return $this->getRealSql($sql, $bind);
        }

        // 执行查询操作
        return $this->query($sql, $bind, $options['master'], true);
    }
600717
public function run(Query $query)
    {
        return $this->getDisconnectRetry()->run(function () use ($query) {
            $statement = $this->prepare($query);
            $query->getValueBinder()->attachTo($statement);
            $statement->execute();

            return $statement;
        });
    }
106037
public function update(Query $query)
    {
        $options = $query->getOptions();

        $data  = $this->parseSet($query, $options['data']);
        $where = $this->parseWhere($query, $options['where']);

        if (1 == $options['limit']) {
            $updateOptions = ['multi' => false];
        } else {
            $updateOptions = ['multi' => true];
        }

        if (isset($options['upsert']) && $options['upsert'] == true) {
            $updateOptions['upsert'] = true;
        }

        $bulk = new BulkWrite;

        $bulk->update($where, $data, $updateOptions);

        $this->log('update', $data, $where);

        return $bulk;
    }
135595
public function buildUpdate(Query $query) {
        return $this->renderStatement(Query::UPDATE, [
            'fields' => $this->formatFields($query),
            'table' => $this->formatTable($query->getTable(), $query->getAlias()),
            'joins' => $this->formatJoins($query->getJoins()),
            'where' => $this->formatWhere($query->getWhere()),
            'orderBy' => $this->formatOrderBy($query->getOrderBy()),
            'limit' => $this->formatLimit($query->getLimit()),
        ] + $this->formatAttributes($query->getAttributes()));
    }
1095699
public function selectInsert(Query $query, $fields, $table)
    {
        // 分析查询表达式
        $options = $query->getOptions();

        // 生成SQL语句
        $table = $this->parseSqlTable($table);

        $sql = $this->builder->selectInsert($query, $fields, $table);

        $bind = $query->getBind();

        if (!empty($options['fetch_sql'])) {
            // 获取实际执行的SQL语句
            return $this->getRealSql($sql, $bind);
        }
        // 执行操作
        return $this->execute($sql, $bind, $query);
    }
889856
public function runQuery(Query $query): Result {
        $query = $query->getQuery();

        echo self::$debugSparql ? $query . "\n" : '';

        return $this->runSparql($query);
    }
335350
protected function _bulk(Query $query = null)
    {
        $field = $this->getConfig('field');
        $expression = [new QueryExpression(sprintf('%1$s= NOT %1$s', $field))];
        $query->update()->set($expression);
        $statement = $query->execute();
        $statement->closeCursor();

        return (bool)$statement->rowCount();
    }
1338232
public function count(Query $query)
    {
        $options = $query->getOptions();

        $cmd['count'] = $options['table'];
        $cmd['query'] = $this->parseWhere($query, $options['where']);

        foreach (['hint', 'limit', 'maxTimeMS', 'skip'] as $option) {
            if (isset($options[$option])) {
                $cmd[$option] = $options[$option];
            }
        }

        $command = new Command($cmd);
        $this->log('cmd', 'count', $cmd);

        return $command;
    }
183773
public function getCursor(Query $query)
    {
        // 分析查询表达式
        $options = $query->getOptions();

        // 生成MongoQuery对象
        $mongoQuery = $this->builder->select($query);

        // 执行查询操作
        $readPreference = isset($options['readPreference']) ? $options['readPreference'] : null;

        return $this->query($options['table'], $mongoQuery, $readPreference, true, $options['typeMap']);
    }
139928
private function cloneQuery(Query $query)
    {
        /* @var $cloneQuery Query */
        $cloneQuery = clone $query;
        $cloneQuery->setParameters($query->getParameters());
        foreach ($query->getHints() as $name => $value) {
            $cloneQuery->setHint($name, $value);
        }

        return $cloneQuery;
    }
508785
public function update($query)
    {
        $resources = $query->getRepository()->getResources();

        foreach ($resources as $resource) {
            $names[] = $query->getPrefix().$resource->getName().' AS '.$this->_store->quoteName($resource->getAlias());
            //only join update if there are no order			
            if (!empty($query->order)) {
                break;
            }
        }

        $operation = $query->operation['value'];

        if (is_array($query->operation['value'])) {
            $operation = array();
            foreach ($query->operation['value'] as $key => $value) {
                $operation[] = is_numeric($key) ? $value : '@col('.$key.')='.$this->_store->quoteValue($value);
            }
            $operation = implode(',', $operation);
        }

        //only join update if there are no order
        if (empty($query->order)) {
            $resources = $query->getRepository()->getResources();

            foreach ($resources->getLinks() as $link) {
                $query->where($link->child, '=', $link->parent);
            }
        }

        $clause = 'UPDATE '.implode($names, ', ').' SET '.$operation;

        return $clause;
    }
646594
public function delete(Query $query)
    {
        $options = $query->getOptions();

        return str_replace(
            ['%TABLE%', '%USING%', '%JOIN%', '%WHERE%', '%ORDER%', '%LIMIT%', '%LOCK%', '%COMMENT%'],
            [
                $this->parseTable($query, $options['table']),
                !empty($options['using']) ? ' USING ' . $this->parseTable($query, $options['using']) . ' ' : '',
                $this->parseJoin($query, $options['join']),
                $this->parseWhere($query, $options['where']),
                $this->parseOrder($query, $options['order']),
                $this->parseLimit($query, $options['limit']),
                $this->parseLock($query, $options['lock']),
                $this->parseComment($query, $options['comment']),
            ],
            $this->deleteSql);
    }
756797
protected function buildUpdateQuery(SQLUpdate $query, array &$parameters)
    {
        $sql  = $this->buildUpdateFragment($query, $parameters);
        $sql .= $this->buildWhereFragment($query, $parameters);
        return $sql;
    }
750742
public function cursor(Query $query)
    {
        // 分析查询表达式
        $options = $query->getOptions();

        // 生成查询SQL
        $sql = $this->builder->select($query);

        $bind = $query->getBind();

        $condition = isset($options['where']['AND']) ? $options['where']['AND'] : null;
        $relation  = isset($options['relaltion']) ? $options['relation'] : null;

        // 执行查询操作
        return $this->getCursor($sql, $bind, $options['master'], $query->getModel(), $condition, $relation);
    }
116044
public static function exec($query)
    {
        $ret = false;

        $res = self::query($query);

        if ($res) {
            $ret = self::connection()->sql_affected_rows();
            self::free($res);
        }

        return $ret;
    }
1109973
public function prepareQuery(Query $query)
    {
        $parameters = new Parameters($this->driver);

        if ($this->pdo === null)
            $this->connect();

        $sql = $this->driver->toSQL($parameters, $query);

        $statement = $this->prepare($sql);
        $parameters->bindParameters($statement);
        return $statement;
    }