生成insert BulkWrite对象
@access public
@param Query     $query 查询对象
@param array     $data 数据
@return BulkWrite
559064
public function insert(Query $query, $replace = false)
    {
        // 分析并处理数据
        $options = $query->getOptions();

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

        $bulk = new BulkWrite;

        if ($insertId = $bulk->insert($data)) {
            $this->insertId = $insertId;
        }

        $this->log('insert', $data, $options);

        return $bulk;
    }
902071
public function execute( $query, array $data = [ ] )
    {
        $result = NULL;

        $statement = $this->database->prepare( $query );

        if ( FALSE === $statement )
        {
            $this->close();

            throw new DatabaseException( 'Failed to create prepared statement.' );
        }

        $result = $statement->execute( $data );

        $this->query = $statement->queryString;

        if ( FALSE !== $result )
        {
            $result = ( int ) $statement->rowCount();
        }

        return $result;
    }
333611
protected function _insert($query, $params)
    {
        $db = $this->db;
        $sth = $db->prepare($query);

        foreach ($params as $key => $val) {
            if (is_int($val)) {
                $sth->bindValue("$key", $val, $db::PARAM_INT);
            } else {
                $sth->bindValue("$key", $val);
            }
        }

        $response = $sth->execute();

        if ($response) {

            $class = $this->_rowClass;
            $row = new $class($this, $db->lastInsertId());

            return $row;
        }
        return false;
    }
1084733
public function delete($query, array $data) {
        $stmt = $this->executeQuery($query, $data);
        
        return $stmt->rowCount();       
    }
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();
    }
1259621
public function queryFromFilter(Query $query, array $data = [])
    {
        //"ID" field
        if (!empty($data['id']) && is_positive($data['id'])) {
            $query->where([sprintf('%s.id', $this->getAlias()) => $data['id']]);
        }

        //"Title" field
        if (!empty($data['title']) && strlen($data['title']) > 2) {
            $query->where([sprintf('%s.title LIKE', $this->getAlias()) => sprintf('%%%s%%', $data['title'])]);
        }

        //"Filename" field
        if (!empty($data['filename']) && strlen($data['filename']) > 2) {
            $query->where([sprintf('%s.filename LIKE', $this->getAlias()) => sprintf('%%%s%%', $data['filename'])]);
        }

        //"User" (author) field
        if (!empty($data['user']) && is_positive($data['user'])) {
            $query->where([sprintf('%s.user_id', $this->getAlias()) => $data['user']]);
        }

        //"Category" field
        if (!empty($data['category']) && is_positive($data['category'])) {
            $query->where([sprintf('%s.category_id', $this->getAlias()) => $data['category']]);
        }

        //"Active" field
        if (!empty($data['active'])) {
            $query->where([sprintf('%s.active', $this->getAlias()) => $data['active'] === I18N_YES]);
        }

        //"Priority" field
        if (!empty($data['priority']) && preg_match('/^[1-5]$/', $data['priority'])) {
            $query->where([sprintf('%s.priority', $this->getAlias()) => $data['priority']]);
        }

        //"Created" field
        if (!empty($data['created']) && preg_match('/^[1-9][0-9]{3}\-[0-1][0-9]$/', $data['created'])) {
            $start = new Time(sprintf('%s-01', $data['created']));
            $end = (new Time($start))->addMonth(1);

            $query->where([
                sprintf('%s.created >=', $this->getAlias()) => $start,
                sprintf('%s.created <', $this->getAlias()) => $end,
            ]);
        }

        return $query;
    }
770818
public function execute($query, ...$data)
    {
        if ($data) {
            $query = $this->merge($query, $data);
        }

        try {
            return $this->pdo->exec($query);
        } catch (PDOException $exception) {
            throw new QueryException($exception, $query);
        }
    }
774264
public function insert($query, $params = array())
    {
        $this->_testQueryStarts($query, 'insert');
        return $this->_executeQuery($query, $params, true);
    }
236683
public function queryFromFilter(Query $query, array $data = [])
    {
        $query = parent::queryFromFilter($query, $data);

        //"Tag" field
        if (!empty($data['tag']) && strlen($data['tag']) > 2) {
            $query->matching('Tags', function (Query $q) use ($data) {
                return $q->where([sprintf('%s.tag', $this->Tags->getAlias()) => $data['tag']]);
            })->distinct();
        }

        return $query;
    }
229720
protected function _bulk(Query $query = null)
    {
        $field = $this->getConfig('field');
        $value = $this->getConfig('value');
        $query->update()->set([$field => $value]);
        $statement = $query->execute();
        $statement->closeCursor();

        return (bool)$statement->rowCount();
    }
351649
public function insert($table, array $data)
    {
        $nameFields = join(',', array_keys($data));
        $preparedValues = $this->prepareValues($data);
        $keyValues = join(",", array_keys($preparedValues));
        $queryString = "INSERT INTO {$table} ({$nameFields}) VALUES ({$keyValues});";

        $this->query($queryString, $preparedValues);

        return $this->getInsertId();
    }
555410
protected function loadData(SelectQuery $query, $bulkCount, $pass)
    {
        $query->limit($bulkCount, $pass * $bulkCount);

        $stmt = $query->prepare();
        $stmt->execute();

        return $stmt->fetchAll(PDO::FETCH_ASSOC);
    }
1197121
public function insert(array $data)
    {
        $params = array();
        $query = "INSERT INTO $this->_name (";

        foreach ($data as $key => $value) {
            $query .= "$key, ";

        }

        $query = substr($query, 0, -2);
        $query .= ") VALUES (";

        $iValue = 0;
        foreach ($data as $key => $value) {
            $query .= ":value$iValue, ";
            $params[":value$iValue"] = $value;
            $iValue++;
        }

        $query = substr($query, 0, -2);
        $query .= ")";

        return $this->_insert($query, $params);
    }
448966
public function buildInsertQuery($table, $data)
    {
        $sql = "INSERT INTO " . $this->quoteSpecialName($table) . " ";

        if (!empty($data['ON DUPLICATE'])) {
            $onDuplicate = $data['ON DUPLICATE'];
            unset($data['ON DUPLICATE']);
        }

        $keys = $values = '';

        foreach ($data as $key => $value) {
            if (!empty($keys)) $keys .= ', ';
            if (!empty($values)) $values .= ', ';

            $keys .= '`' . $key . '`';
            $values .= $this->escapeItem($value);
        }

        $keys = '(' . $keys . ')';
        $values = '(' . $values . ')';

        $sql .= $keys . ' VALUES ' . $values;

        if (!empty($onDuplicate)) {
            $sql .= " ON DUPLICATE KEY UPDATE " . $onDuplicate;
        }

        $sql .= ';';

        return $sql;
    }
378819
public function insert( $query, array $data = [ ] )
    {
        $id = NULL;

        $statement = $this->database->prepare( $query );

        if ( FALSE === $statement )
        {
            $this->close();

            throw new DatabaseException( 'Failed to create prepared statement.' );
        }

        $result = $statement->execute( $data );

        $this->query = $statement->queryString;

        if ( FALSE !== $result )
        {
            $result = ( int ) $this->database->lastInsertId();
        }

        return $result;
    }
1277437
public function insert(array $data, $replace = null, $getLastInsID = false)
    {
        if (empty($data)) {
            throw new Exception('miss data to insert');
        }
        unset($replace);
        // 分析查询表达式
        $options = $this->parseExpress();
        $data    = array_merge($options['data'], $data);
        // 生成bulk对象
        $bulk         = $this->builder->insert($data, $options);
        $writeConcern = isset($options['writeConcern']) ? $options['writeConcern'] : null;
        $writeResult  = $this->execute($options['table'], $bulk, $writeConcern);
        $result       = $writeResult->getInsertedCount();
        if ($result) {
            $lastInsId = $this->getLastInsID();
            if ($lastInsId) {
                $pk        = $this->getPk();
                $data[$pk] = $lastInsId;
            }
            $options['data'] = $data;
            $this->trigger('after_insert', $options);

            if ($getLastInsID) {
                return $lastInsId;
            }
        }
        return $result;
    }
770529
protected function exportInsert(array $data)
    {
        $insertSql = '';
        $insert = new Insert(self::TABLE_NAME);
        foreach ($data as $id => $value) {
            $insertSql .= @$insert
                ->values(array('id' => $id, 'value' => $value))
                ->getSqlString($this->getPlatform()).';'.PHP_EOL;
        }

        return $insertSql;
    }