插入数据，如果数据已经存在，则替换数据
@see insert()
6263
public function replace($table, $data) {

        $_fileds = '';
        $_values = '';
        $_T_fields = $this->getTableFields($table);
        foreach ( $data as $_key => $_val ) {

            //自动过滤掉不存在的字段
            if ( !in_array( $_key, $_T_fields ) ) continue;

            $_fileds .= ( $_fileds=='' ) ? "`{$_key}`" : ", `{$_key}`";
            if ( is_null($_val) ) {
                $_val = 'NULL';
            } else {
                $_val = "'{$_val}'";
            }
            $_values .= ( $_values=='' ) ? "{$_val}" : ",{$_val}";
        }

        if ( $_fileds != '' ) {
            $_query = "REPLACE INTO {$table}(" . $_fileds . ") VALUES(" . $_values . ")";
            if ( $this->execute($_query) != false ) {
                return true;
            }

        }
        return false;
    }
169083
public function insert()
	{
		$res = \DB::insert(call_user_func($this->model.'::table'), array_keys($this->values))
			->values(array_values($this->values))
			->execute($this->write_connection);

		// Failed to save the new record
		if ($res[1] === 0)
		{
			return false;
		}

		return $res[0];
	}
1142771
protected function _insert()
    {
        // marking basket as not new any more
        $this->_blNewBasket = false;

        if (!isset($this->oxuserbaskets__oxpublic->value)) {
            $this->oxuserbaskets__oxpublic = new \OxidEsales\Eshop\Core\Field(1, \OxidEsales\Eshop\Core\Field::T_RAW);
        }

        $iTime = \OxidEsales\Eshop\Core\Registry::getUtilsDate()->getTime();
        $this->oxuserbaskets__oxupdate = new \OxidEsales\Eshop\Core\Field($iTime);

        return parent::_insert();
    }
502926
public function insert($table)
    {
        $this->type  = 'INSERT';
        $this->table = $this->quoteName($table);
        return $this;
    }
458726
protected function _insert()
    {
        if ($this->oxcategories__oxparentid->value != "oxrootid") {
            // load parent
            $oParent = oxNew(\OxidEsales\Eshop\Application\Model\Category::class);
            //#M317 check if parent is loaded
            if (!$oParent->load($this->oxcategories__oxparentid->value)) {
                return false;
            }

            $sAdd = " and oxshopid = '" . $this->getShopId() . "' ";

            // update existing nodes
            $oDb = \OxidEsales\Eshop\Core\DatabaseProvider::getDb();
            $oDb->execute(
                "UPDATE oxcategories SET OXLEFT = OXLEFT + 2
                                           WHERE  OXROOTID = " . $oDb->quote($oParent->oxcategories__oxrootid->value) . "
                            AND OXLEFT >   " . ((int) $oParent->oxcategories__oxright->value) . "
                            AND OXRIGHT >= " . ((int) $oParent->oxcategories__oxright->value) . $sAdd
            );


            $oDb->execute(
                "UPDATE oxcategories SET OXRIGHT = OXRIGHT + 2
                                           WHERE  OXROOTID = " . $oDb->quote($oParent->oxcategories__oxrootid->value) . "
                            AND OXRIGHT >= " . ((int) $oParent->oxcategories__oxright->value) . $sAdd
            );

            if (!$this->getId()) {
                $this->setId();
            }

            $this->oxcategories__oxrootid = new \OxidEsales\Eshop\Core\Field($oParent->oxcategories__oxrootid->value, \OxidEsales\Eshop\Core\Field::T_RAW);
            $this->oxcategories__oxleft = new \OxidEsales\Eshop\Core\Field($oParent->oxcategories__oxright->value, \OxidEsales\Eshop\Core\Field::T_RAW);
            $this->oxcategories__oxright = new \OxidEsales\Eshop\Core\Field($oParent->oxcategories__oxright->value + 1, \OxidEsales\Eshop\Core\Field::T_RAW);

            return parent::_insert();
        } else {
            // root entry
            if (!$this->getId()) {
                $this->setId();
            }

            $this->oxcategories__oxrootid = new \OxidEsales\Eshop\Core\Field($this->getId(), \OxidEsales\Eshop\Core\Field::T_RAW);
            $this->oxcategories__oxleft = new \OxidEsales\Eshop\Core\Field(1, \OxidEsales\Eshop\Core\Field::T_RAW);
            $this->oxcategories__oxright = new \OxidEsales\Eshop\Core\Field(2, \OxidEsales\Eshop\Core\Field::T_RAW);

            return parent::_insert();
        }
    }
1099812
public function str_insert_i(string $insert, int $position): self
    {
        $insert = $this->inputConv($insert);
        $this->str = \substr_replace($this->str, $insert, $position << 2, 0);

        return $this;
    }
489603
private Single<SingleInsertionResult> insert(String preparedSql, Object[] sqlParams) {
        return Single.fromCallable(() -> {
            PreparedStatement statement = connection0.prepareStatement(preparedSql, PreparedStatement.RETURN_GENERATED_KEYS);
            for (int i = 0; i < sqlParams.length; i++) {
                statement.setObject(i + 1, sqlParams[i]);
            }
            statement.execute();
            ResultSet rs = statement.getGeneratedKeys();
            Integer count = statement.getUpdateCount();
            Long id;
            if (rs.next()) {
                id = rs.getLong(1);
            } else {
                //no id is generated
                id = null;
            }
            rs.close();
            statement.close();
            return new SingleInsertionResult().setCount(count).setId(id).setPreparedSql(preparedSql);
        });
    }
957864
private function createInserts(): string
    {
        //以第一行数据的标题为字段名基准
        list($fields,) = $this->db->createRow($this->row[0]);

        //逐行处理
        $data = $holders = $params = [];
        foreach ($this->row as $row) {
            //本行数据加MYSQL定界符
            list($rowFields, $row) = $this->db->createRow($row);

            //每个字段必须有,没有的为空字符串
            $r = [];
            foreach ($fields as $f) {
                $params[] = $r[] = in_array($f, $rowFields) ? $row[array_search($f, $rowFields)] : '';
            }

            //行数据集
            $data[] = $this->db->markValueArray($r);

            //占位符集合
            $holders[] = $this->createHolder($r);
        }

        $this->sql = $this->db->createInserts($this->table, $fields, $data);
        $this->prepare = $this->db->createInserts($this->table, $fields, $holders);
        $this->params = $params;
        $this->tables = [$this->table];
        return $this->prepare;
    }
461378
protected function _insert()
    {
        $query = $this->_queryClass;
        $table = (new $query)->getTableName();
        $result = DbConnector::getAdapter()->insert($table, $this->_truncateToStructure());
        //odczyt id z sekwencji
        if ($result && property_exists($this, 'id') && $this->getPk() === null) {
            $this->id = DbConnector::getAdapter()->lastInsertId(DbConnector::getAdapter()->prepareSequenceName($table));
        }
        //utrwalanie bieżącego stanu
        $this->clearModified();
        return true;
    }
202168
public function save() {
        $pk = $this->getPkField();
        //主键是id
        if (($pk == 'id' && $this->$pk) || $this->to_updata) {
            $this->update();
        } else {
            if ($this->$pk) {
                $this->checkHas();
            }
            if ($this->to_updata) {
                $this->update();
            } else {
                $this->insert();
            }
        }
    }
1300716
protected function _insert()
    {
        $this->lang = \Mmi\App\FrontController::getInstance()->getRequest()->lang;
        return parent::_insert();
    }
297371
public function insert($values)
    {
        try {
            if (func_num_args() > 0 && !is_array($values)) {
                $this->values = array_merge($this->values, self::sanitizeAV(func_get_args()));
            } else if (is_array($values)) {
                $this->values = self::sanitize($values);
            } else {
                static::$response["status"] = "error";
                static::$response["response"] = "unrecognized parameter options in the insert values";
                static::$response["code"] = 7004;
                return static::terminate(static::$response);
            }
        } catch (Exception $e) {
            static::$response["status"] = "error";
            static::$response["response"] = $e->getMessage();
            static::$response["code"] = $e->getCode();
           return static::terminate(static::$response);
        }

        return $this;
    }
312627
private function add()
    {
        // skip if it's a key
        if ((null !== ($check = $this->tokens->getToken($this->tokens->key() + 1)))
            && ((DocLexer::T_COLON === $check[0])
                || (DocLexer::T_EQUALS === $check[0]))) {
            return;
        }

        $token = $this->tokens->current();
        $value = $this->result->createElement('value');

        if (null !== ($key = $this->key())) {
            $value->setAttribute('key', $key);
        }

        $this->current->appendChild($value);

        $text = null;
        $type = null;

        switch ($token[0]) {
            case DocLexer::T_FALSE:
                $text = '0';
                $type = 'boolean';

                break;
            case DocLexer::T_FLOAT:
                $text = $token[1];
                $type = 'float';

                break;
            case DocLexer::T_IDENTIFIER:
                $text = $token[1];
                $type = 'constant';

                break;
            case DocLexer::T_INTEGER:
                $text = $token[1];
                $type = 'integer';

                break;
            case DocLexer::T_NULL:
                $type = 'null';

                break;
            case DocLexer::T_STRING:
                $text = $token[1];
                $type = 'string';

                break;
            case DocLexer::T_TRUE:
                $text = '1';
                $type = 'boolean';

                break;
        }

        $value->setAttribute('type', $type);

        if (null !== $text) {
            $value->appendChild(new DOMText($text));
        }
    }
369888
private function insert()
    {
        $Eresus = Eresus_CMS::getLegacyKernel();

        $item = array();
        $item['caption'] = arg('caption', 'dbsafe');
        $item['active'] = arg('active', 'int');
        if (arg('section'))
        {
            $item['section'] = '|' . implode('|', arg('section')) . '|';
        }
        $item['block'] = arg('block', 'dbsafe');
        $item['priority'] = arg('priority', 'int');
        $item['showFrom'] = arg('showFrom', 'dbsafe');
        if (arg('showTill'))
        {
            $item['showTill'] = arg('showTill', 'dbsafe');
        }
        $item['showCount'] = arg('showCount', 'int');
        $item['html'] = arg('html', 'dbsafe');
        $item['image'] = arg('image');
        $item['width'] = arg('width', 'int');
        $item['height'] = arg('height', 'int');
        $item['url'] = arg('url', 'dbsafe');
        $item['target'] = arg('target', 'dbsafe');

        $Eresus->db->insert($this->table['name'], $item);

        $item['id'] = $Eresus->db->getInsertedID();
        if (is_uploaded_file($_FILES['image']['tmp_name']))
        {
            $filename = 'banner' . $item['id'] . substr($_FILES['image']['name'],
                    strrpos($_FILES['image']['name'], '.'));
            upload('image', $Eresus->fdata . $this->name . '/' . $filename);
            $item['image'] = $filename;
            $Eresus->db->updateItem($this->table['name'], $item, "`id`='" . $item['id'] . "'");
        }
        HTTP::redirect(arg('submitURL'));
    }
273981
private function getInsertQuery()
    {
        return 'INSERT INTO '.$this->parts['from'][0]['table'].
               ' ('.implode(', ', array_keys($this->parts['set'])).')'.
               ' VALUES'.
               ' ('.implode(', ', $this->parts['set']).')';
    }
185725
protected function insertNode()
    {
        $descendant = $this->getKey();
        $ancestor = (isset($this->parent_id) ? $this->parent_id : $descendant);

        $this->closure->insertNode($ancestor, $descendant);
    }
1130589
protected function doInsert()
    {
        /**
         * Run pre-INSERT logic
         */
        $this->beforeInsert();

        $data = $this->toArray();
        /**
         * Execute validator logic
         * Can throw ValidatorException
         */
        $this->assert($data);

        $table = $this->getTable();

        /**
         * Execute the INSERT (this may throw an exception)
         */
        $primaryKey = $table::insert($data);

        /**
         * Normalize the result to an array indexed by primary key column(s)
         */
        $tempPrimaryKey = $table->getPrimaryKey();
        $newPrimaryKey = [current($tempPrimaryKey) => $primaryKey];

        /**
         * Save the new primary key value in object. The primary key may have
         * been generated by a sequence or auto-increment mechanism, and this
         * merge should be done before the afterInsert() method is run, so the
         * new values are available for logging, etc.
         */
        $this->setFromArray($newPrimaryKey);

        /**
         * Run post-INSERT logic
         */
        $this->afterInsert();

        /**
         * Update the "clean" to reflect that the data has been inserted.
         */
        $this->clean = $this->toArray();

        return $newPrimaryKey;
    }