[insert description]
@return [type] [description]
329594
private function insert()
    {
        $db = new Db();

        //Pegando um ID válido
        $id = $db->query('SELECT MAX(id)id FROM article');
        $this->id = $id[0]->get('id')+1;

                //Insert into content table
        $row = $db->query('INSERT INTO articlecontent
                            SET article = :article,
                                editdate = :editdate,
                                content = :content',
                        [':article' => $this->id,
                         ':editdate' => $this->editdate,
                         ':content' => $this->content]);

        //check insert
        if (!$row) {
            //TODO: insert a ROWBACK if not inserted.

            return false;
        }
        
        //Insert into article table
        $row = $db->query('INSERT INTO article
                            SET id = :id,
                                category = :category,
                                author = :author,
                                pubdate = :pubdate,
                                editdate = :editdate,
                                link = :link,
                                tags = :tags,
                                status = :status,
                                title = :title,
                                media = :media,
                                resume = :resume ',
                        [':id'=>$this->id,
                         ':category' => $this->category,
                         ':author' => $this->author,
                         ':pubdate' => $this->pubdate,
                         ':editdate' => $this->editdate,
                         ':link' => $this->link,
                         ':tags' => $this->tags,
                         ':status' => $this->status,
                         ':title' => $this->title,
                         ':media' => $this->media,
                         ':resume' => $this->resume
                        ]);

        return $row;
    }
567713
public function insert() {
        $sql = new Sql();
        $queryFields = '';
        $queryValues = '';
        $manyToMany = null;
        $transaction = Database::instance()->db()->inTransaction();

        if (!$transaction) {
            Database::instance()->db()->beginTransaction();
        }

        /** @var $fieldsInsertOneToMany \Gcs\Framework\Core\Orm\Entity\Entity[] */
        $fieldsInsertOneToMany = [];
        /** @var $fieldsUpdateOneToMany \Gcs\Framework\Core\Orm\Entity\Entity[] */
        $fieldsUpdateOneToMany = [];

        /** @var $fieldsInsertOneToMany \Gcs\Framework\Core\Orm\Entity\Entity[] */
        $fieldsInsertManyToMany = [];
        /** @var $fieldsUpdateOneToMany \Gcs\Framework\Core\Orm\Entity\Entity[] */
        $fieldsUpdateManyToMany = [];

        /** @var $field \Gcs\Framework\Core\Orm\Entity\Field */
        foreach ($this->_fields as $field) {
            if ($field->primary == false) {
                if ($field->foreign != null) {
                    switch ($field->foreign->type()) {
                        case ForeignKey::ONE_TO_ONE :
                            if (gettype($field->value) != 'object') {
                                if ($field->foreign->belong() == ForeignKey::COMPOSITION) {
                                    throw new MissingEntityException('The field "' . $field->name . '" in "' . $this->_name . '" must be an Entity');
                                }
                            }
                            if (!preg_match('#Orm\\\Entity\\\#isU', get_class($field->value))) {
                                throw new MissingEntityException('The foreign key "' . $field->name . '" in "' . $this->_name . '" must be an Entity object');
                            }

                            if ($field->value == null) {
                                throw new MissingEntityException('The field "' . $field->name . '" in "' . $this->_name . '" can\'t be null');
                            }
                            else {
                                $field->value->insert();
                                $queryFields .= $field->name . ', ';
                                $queryValues .= ':' . $field->name . ', ';
                                $sql->vars($field->name, $field->value->get($field->foreign->referenceField()));
                            }
                            break;

                        case ForeignKey::MANY_TO_ONE :
                            if (gettype($field->value) != 'object') {
                                if ($field->foreign->belong() == ForeignKey::COMPOSITION) {
                                    throw new MissingEntityException('The field "' . $field->name . '" in "' . $this->_name . '" must be an Entity');
                                }
                            }
                            if (!preg_match('#Orm\\\Entity\\\#isU', get_class($field->value))) {
                                //throw new MissingEntityException('The foreign key "'.$field->name.'" in "'.$this->_name.'" must be an Entity object');
                            }

                            if ($field->value == null) {
                                if ($field->beNull == false) {
                                    throw new MissingEntityException('The field "' . $field->name . '" in "' . $this->_name . '" can\'t be null');
                                }
                                else {
                                    $sql->vars($field->name, null);
                                    $queryFields .= $field->name . ', ';
                                    $queryValues .= ':' . $field->name . ', ';
                                }
                            }
                            else {
                                if ($field->value->get($field->value->primary()) == null) {
                                    $field->value->insert();
                                }

                                $sql->vars($field->name, $field->value->get($field->foreign->referenceField()));
                                $queryFields .= $field->name . ', ';
                                $queryValues .= ':' . $field->name . ', ';
                            }
                            break;

                        case ForeignKey::ONE_TO_MANY :
                            /** If we insert a new line and the are already sub-objects, we have to insert or update them */
                            if ($field->value != null) {
                                if (gettype($field->value) != 'object') {
                                    if ($field->foreign->belong() == ForeignKey::COMPOSITION) {
                                        throw new MissingEntityException('The field "' . $field->name . '" in "' . $this->_name . '" must be a Collection');
                                    }
                                }
                                if (get_class($field->value) != 'System\Collection\Collection') {
                                    throw new MissingEntityException('The field "' . $field->name . '" in "' . $this->_name . '" must be a Collection');
                                }

                                /** @var $entity \Gcs\Framework\Core\Orm\Entity\Entity */
                                foreach ($field->value as $entity) {
                                    if ($entity != null) {
                                        /** the field is not in database yet, so after the insert of the Entity, we will do an insert for it */
                                        if ($entity->get($entity->primary()) == null) {
                                            array_push($fieldsInsertOneToMany, $entity);
                                        }
                                        /** the field is already in database, so after the insert of the Entity, we will do an update for it */
                                        else if ($entity->get($entity->primary()) != null) {
                                            array_push($fieldsUpdateOneToMany, $entity);
                                        }
                                    }
                                    else {
                                        if ($field->foreign->belong() == ForeignKey::COMPOSITION) {
                                            throw new MissingEntityException('The Collection field "' . $field->name . '" in "' . $this->_name . '" can\'t have a null item because the relation is a composition');
                                        }
                                    }
                                }
                            }
                            else if ($field->beNull == false) {
                                throw new MissingEntityException('The field "' . $field->name . '" in "' . $this->_name . '" can\'t be null');
                            }
                            break;

                        case ForeignKey::MANY_TO_MANY :
                            /** If we insert a new line and the are already sub-objects, we have to insert or update them */
                            if ($field->value != null) {
                                if (gettype($field->value) != 'object') {
                                    throw new MissingEntityException('The field "' . $field->name . '" in "' . $this->_name . '" must be a Collection');
                                }
                                if (get_class($field->value) != 'System\Collection\Collection') {
                                    throw new MissingEntityException('The field "' . $field->name . '" in "' . $this->_name . '" must be a Collection');
                                }

                                $manyToMany = $field;

                                /** @var $entity \Gcs\Framework\Core\Orm\Entity\Entity */
                                foreach ($field->value as $entity) {
                                    if ($entity != null) {
                                        /** the field is not in database yet, so after the insert of the Entity, we will do an insert for it */
                                        if ($entity->get($entity->primary()) == null) {
                                            array_push($fieldsInsertManyToMany, $entity);
                                        }
                                        else {
                                            array_push($fieldsUpdateManyToMany, $entity);
                                        }
                                    }
                                    else {
                                        throw new MissingEntityException('The Entity "' . get_class($entity) . '" in "' . $this->_name . '" can\'t be null');
                                    }
                                }
                            }
                            else if ($field->beNull == false) {
                                throw new MissingEntityException('The field "' . $field->name . '" in "' . $this->_name . '" can\'t be null');
                            }
                            break;
                    }
                }
                else {
                    if ($field->value == null && $field->beNull == false && $field->default == '') {
                        throw new MissingEntityException('The field "' . $field->name . '" in "' . $this->_name . '" can\'t be null');
                    }

                    if ($field->value == null) {
                        $field->value = $field->default;
                    }

                    if (gettype($field->value) != 'object') {
                        if (in_array($field->type, [Field::INCREMENT, Field::INT, Field::FLOAT])) {
                            $sql->vars($field->name, [$field->value, Sql::PARAM_INT]);
                        }
                        else if (in_array($field->type, [Field::CHAR, Field::TEXT, Field::STRING, Field::DATE, Field::DATETIME, Field::TIMESTAMP])) {
                            $sql->vars($field->name, [$field->value, Sql::PARAM_STR]);
                        }
                        else if (in_array($field->type, [Field::BOOL])) {
                            $sql->vars($field->name, [$field->value, Sql::PARAM_BOOL]);
                        }
                        else {
                            $sql->vars($field->name, $field->value);
                        }
                    }
                    elseif (in_array($field->type, [Field::DATETIME, Field::TIMESTAMP])) {
                        $sql->vars($field->name, [$field->value->format("Y-m-d H:i:s"), Sql::PARAM_STR]);
                    }
                    elseif (in_array($field->type, [Field::DATE])) {
                        $sql->vars($field->name, [$field->value->format("Y-m-d"), Sql::PARAM_STR]);
                    }
                    else if (in_array($field->type, [Field::FILE])) {
                        $sql->vars($field->name, $field->value->value());
                        $field->value->save();
                    }

                    $queryFields .= $field->name . ', ';
                    $queryValues .= ':' . $field->name . ', ';
                }
            }
        }

        /** Execution of the query */
        $queryFields = substr(trim($queryFields, ','), 0, strlen($queryFields) - 2);
        $queryValues = substr(trim($queryValues, ','), 0, strlen($queryValues) - 2);

        $query = 'INSERT INTO ' . $this->_name . '(' . $queryFields . ') VALUES(' . $queryValues . ')';

        $sql->query('insert_' . $this->_name . '_' . $this->_token, $query);
        $sql->fetch('insert_' . $this->_name . '_' . $this->_token, Sql::PARAM_FETCHINSERT);

        /** Update primary key */
        $this->_fields[$this->_primary]->value = Database::instance()->db()->lastInsertId();

        /** ######################################################################## */
        /** One to many and many to many need more queries after the principal query */

        /** @var $field \Gcs\Framework\Core\Orm\Entity\Field */
        foreach ($fieldsInsertOneToMany as $fields) {
            $relation = '';

            /** @var $relationFields \Gcs\Framework\Core\Orm\Entity\Field */
            foreach ($fields->fields() as $relationFields) {
                if ($relationFields->foreign != null) {
                    if ($relationFields->foreign->referenceEntity() == ucfirst(strtolower($this->_name))) {
                        $relation = $relationFields->foreign->field();
                    }
                }
            }

            $fields->set($relation, $this);
            $fields->insert();
        }

        foreach ($fieldsUpdateOneToMany as $fields) {
            $relation = '';

            /** @var $relationFields \Gcs\Framework\Core\Orm\Entity\Field */
            foreach ($fields->fields() as $relationFields) {
                if ($relationFields->foreign != null) {
                    if ($relationFields->foreign->referenceEntity() == ucfirst(strtolower($this->_name))) {
                        $relation = $relationFields->foreign->field();
                    }
                }
            }

            $fields->set($relation, $this);
            $fields->update();
        }

        if ($manyToMany != null) {
            $currentEntity = $manyToMany->foreign->entity();
            $currentField = $manyToMany->foreign->field();
            $referenceEntity = $manyToMany->foreign->referenceEntity();
            $referenceField = $manyToMany->foreign->referenceField();

            $current = strtolower($currentEntity . $currentField);
            $reference = strtolower($referenceEntity . $referenceField);
            $table = [$current, $reference];
            sort($table, SORT_STRING);
            $table = ucfirst($table[0] . $table[1]);

            $class = '\Orm\Entity\\' . $manyToMany->foreign->referenceEntity();
            /** @var $referencedEntity \Gcs\Framework\Core\Orm\Entity\Entity */
            $referencedEntity = new $class();

            $sql = new Sql();
            $sql->query('orm-delete-many', 'DELETE FROM ' . $table . ' WHERE ' . $this->name() . '_' . $manyToMany->foreign->referenceField() . ' = ' . $this->_fields[$this->_primary]->value);
            $sql->fetch('orm-delete-many');

            /** @var $fields \Gcs\Framework\Core\Orm\Entity\Entity */
            foreach ($fieldsInsertManyToMany as $fields) {
                $fields->set($manyToMany->foreign->field(), $this);
                $fields->insert();

                $sql->query('orm-insert-many', 'INSERT INTO ' . $table . '(' . $this->name() . '_' . $manyToMany->foreign->referenceField() . ', ' . $referencedEntity->name() . '_' . $manyToMany->foreign->field() . ') VALUES (\'' . $this->_fields[$this->_primary]->value . '\', \'' . $fields->get($manyToMany->foreign->field()) . '\')');
                $sql->fetch('orm-insert-many');
            }

            /** @var $fields \Gcs\Framework\Core\Orm\Entity\Entity */
            foreach ($fieldsUpdateManyToMany as $fields) {
                $sql->query('orm-update-many', 'INSERT INTO ' . $table . '(' . $this->name() . '_' . $manyToMany->foreign->referenceField() . ', ' . $referencedEntity->name() . '_' . $manyToMany->foreign->field() . ') VALUES (\'' . $this->_fields[$this->_primary]->value . '\', \'' . $fields->get($manyToMany->foreign->field()) . '\')');
                $sql->fetch('orm-update-many');
            }
        }

        if (!$transaction) {
            Database::instance()->db()->commit();
        }
    }
159238
public function insert()
    {
        $result = $this->connection()->post($this->getEndpoint(), $this->jsonWithNamespace());

        return $this->selfFromResponse($result);
    }
1261261
protected function _insert()
    {
        $result = parent::_insert();

        if ($result) {
            //also insert to multilang tables if it is separate
            foreach ($this->_getLanguageSetTables() as $table) {
                $sql = "insert into $table set " . $this->_getUpdateFieldsForTable($table, $this->getUseSkipSaveFields());

                $result = $result && (bool) $this->executeDatabaseQuery($sql);
            }
        }

        return $result;
    }
185725
protected function insertNode()
    {
        $descendant = $this->getKey();
        $ancestor = (isset($this->parent_id) ? $this->parent_id : $descendant);

        $this->closure->insertNode($ancestor, $descendant);
    }
970558
public function insert($table = null)
    {
        $this->type = self::TYPE_INSERT;
        if ($table) {
            $this->table($table);
        }

        return $this;
    }
64118
protected function buildValuesForInsert()
    {
        return ' (' . $this->indentCsv(array_keys($this->col_values)) . ') VALUES (' .
        $this->indentCsv(array_values($this->col_values)) . ')';
    }
489150
public function dbInsert() {
		BLog::addToLog('[Items.Item.' . $this->tableName . ']: Inserting data...');
		if (!$db = \Brilliant\BFactory::getDBO()) {
			return false;
		}
		//Forming query...
		$this->modified = new \Brilliant\BDateTime();
		//For import we need ability to set `created`
		if (empty($this->created)) {
			$this->created = new \Brilliant\BDateTime();
		}
		$qr = $this->dbInsertQuery();
		//Running query...
		$q = $db->query($qr);
		if (empty($q)) {
			return false;
		}
		$this->{$this->primaryKeyName} = $db->insertId();
		$this->isNew = false;
		//Updating cache...
		$this->updateCache();
		//Return result
		return true;
	}
603457
protected function _insert()
    {
        $myConfig = \OxidEsales\Eshop\Core\Registry::getConfig();
        $myUtils = \OxidEsales\Eshop\Core\Registry::getUtils();

        // let's get a new ID
        if (!$this->getId()) {
            $this->setId();
        }

        $idKey = $myUtils->getArrFldName($this->getCoreTableName() . '.oxid');
        $this->$idKey = new Field($this->getId(), Field::T_RAW);
        $insertSql = "Insert into {$this->getCoreTableName()} set ";

        $shopIdField = $myUtils->getArrFldName($this->getCoreTableName() . '.oxshopid');

        if ($this->isPropertyLoaded($shopIdField)
            && (!$this->isPropertyField($shopIdField) || !$this->$shopIdField->value)
        ) {
            $this->$shopIdField = new Field(
                $myConfig->getShopId(),
                Field::T_RAW
            );
        }

        $insertSql .= $this->_getUpdateFields($this->getUseSkipSaveFields());

        return $result = (bool) $this->executeDatabaseQuery($insertSql);
    }
1321840
public function insert($tables = null)
    {
        if (null !== $tables) {
            $this->tables($tables);
        }
        $this->action = 'insert';
        return $this;
    }
147339
function insert() {
		if ($this->id)
			return $this->update();
		$db=$this->db;
		$now=microtime(TRUE);
		while (($id=uniqid(NULL,TRUE)) &&
			($data=&$db->read($this->file)) && isset($data[$id]) &&
			!connection_aborted())
			usleep(mt_rand(0,100));
		$this->id=$id;
		$pkey=['_id'=>$this->id];
		if (isset($this->trigger['beforeinsert']) &&
			\Base::instance()->call($this->trigger['beforeinsert'],
				[$this,$pkey])===FALSE)
			return $this->document;
		$data[$id]=$this->document;
		$db->write($this->file,$data);
		$db->jot('('.sprintf('%.1f',1e3*(microtime(TRUE)-$now)).'ms) '.
			$this->file.' [insert] '.json_encode($this->document));
		if (isset($this->trigger['afterinsert']))
			\Base::instance()->call($this->trigger['afterinsert'],
				[$this,$pkey]);
		$this->load(['@_id=?',$this->id]);
		return $this->document;
	}
1300716
protected function _insert()
    {
        $this->lang = \Mmi\App\FrontController::getInstance()->getRequest()->lang;
        return parent::_insert();
    }
54823
private function internalInsert()
    {
        if ($this->triggerEvent(self::EVENT_NAME_BEFORE_INSERT)->isCancelled()) {
            return;
        }

        $document = $this->toArray();

        // try write document
        try {
            $this
                ->collection
                ->getMongoCollection()
                ->insert($document);
        } catch (\Exception $e) {
            throw new WriteException(
                $e->getMessage(),
                $e->getCode(),
                $e
            );
        }

        // set id
        $this->defineId($document['_id']);

        // after insert event
        $this->triggerEvent(self::EVENT_NAME_AFTER_INSERT);
    }
1005637
protected function parseInsertStmt(){
		$cols = array();
		foreach($this->escapeValue($this->stmt->getValues()) as $col => $value){
			$cols[] = $this->parseFieldName($col);
			$values[] = $value;
		}
		$data = ' (' . implode(', ', $cols) . ")\nVALUES (" . implode(', ', $values). ')';

		return 'INSERT INTO ' . $this->clauses[0] . $data;
	}
763957
function insert($data)
    {
        $field = "";
        $values = "";

        foreach($data as $key => $value)
        {
            $value = $this->db->quote($value);
            $field = $field . "`$key`,";
            $values = $values . "'$value',";
        }

        $field = substr($field, 0, -1);
        $values = substr($values, 0, -1);
        return $this->db->query("insert into {$this->table} ($field) values($values)");
    }
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();
        }
    }
489228
private function insertFile()
    {
        $fileDocument = [
            '_id' => $this->_documentId,
            'uploadDate' => new UTCDateTime(round(microtime(true) * 1000)),
        ];
        if ($this->filename === null) {
            $fileDocument['filename'] = $this->_documentId . '.dat';
        } else {
            $fileDocument['filename'] = $this->filename;
        }

        $fileDocument = array_merge(
            $fileDocument,
            $this->document,
            [
                'chunkSize' => $this->chunkSize,
                'length' => $this->length,
                'md5' => hash_final($this->_hashContext),
            ]
        );

        $this->collection->insert($fileDocument);
        return $fileDocument;
    }