Inserts the record.

@return $this
517381
public function insert() {
    $this->db()->insert($this->table, $this->record);
    $id = $this->db()->lastInsertId();
    $this->record[$this->id_name] = $id;
    $this->isDirty = FALSE;

    return $this;
  }
903466
public function dbInsert() {
		BLog::addToLog('[Items.ItemTree]: Inserting data...');
		if (!$db = \Brilliant\BFactory::getDBO()) {
			return false;
			}
		$closeTransaction=false;

		if(!$this->isRoot){
			$db->startTransaction();
			$closeTransaction = true;
			//---------------------------------------------------
			// Try to get parent / root element, create root
			// if we does not have root element.
			//---------------------------------------------------
			BLog::addToLog('[Items.ItemTree.'.$this->tableName.']: Try to get parent / root element.');
			$parent = $this->getParentOrRoot();
			if (empty($parent)) {
				$className = get_class($this);
				if(DEBUG_LOG_BITEMS){
					BLog::addToLog('[Items.ItemTree.'.$this->tableName.']: Parent is empty. Need to insert parent element ('.$className.')');
					}
				$parent = new $className();
				$parent->{$this->groupKeyName} = $this->{$this->groupKeyName};
				$parent->{$this->leftKeyName} = 1;
				$parent->{$this->rightKeyName} = 4;
				$parent->{$this->levelKeyName} = 1;
				$parent->isRoot = true;
				$r = $parent->saveToDB();
				if(empty($r)){
					return false;
					}
				//
				$this->{$this->parentKeyName} = $parent->{$this->primaryKeyName};
				$this->{$this->groupKeyName} = $parent->{$this->groupKeyName};
				$this->{$this->leftKeyName} = 2;
				$this->{$this->rightKeyName} = 3;
				$this->{$this->levelKeyName} = 2;
				} else {
				if(DEBUG_LOG_BITEMS){
					BLog::addToLog('[Items.ItemTree.'.$this->tableName.']: Parent is not empty.');
					}
				$this->{$this->parentKeyName} = $parent->{$this->primaryKeyName};
				$this->{$this->groupKeyName} = $parent->{$this->groupKeyName};
				$this->{$this->leftKeyName} = (int)$parent->{$this->rightKeyName};
				$this->{$this->rightKeyName} = (int)$parent->{$this->rightKeyName} + 1;
				$this->{$this->levelKeyName} = (int)$parent->{$this->levelKeyName} + 1;
				$qr = 'UPDATE `' . $this->tableName . '` SET ';
				$qr .= '`' . $this->rightKeyName . '`=`' . $this->rightKeyName . '`+2, ';
				$qr .= '`' . $this->leftKeyName . '` = IF(`' . $this->leftKeyName . '` > ' . $parent->{$this->rightKeyName} . ', `' . $this->leftKeyName . '`+2, `' . $this->leftKeyName . '`)';
				$qr .= ' WHERE ((`' . $this->groupKeyName . '` = ' . $this->{$this->groupKeyName} . ') AND (`' . $this->rightKeyName . '`>=' . $parent->{$this->rightKeyName} . '))';
				$q = $db->query($qr);
				if (empty($q)) {
					$db->rollback();
					return false;
					}
				//Because some elements in our internal cache was changed - need to flush it.
				$collection=$this->getCollection();
				$collection->flushInternalCache();
				}
			}
		//---------------------------------------------------
		//Forming query...
		//---------------------------------------------------
		$this->modified = new \DateTime();
		if(empty($this->created)){
			$this->created=new \DateTime();
			}
		$qr = $this->dbInsertQuery();
		//Running query...
		$q = $db->query($qr);
		if (empty($q)) {
			if ($closeTransaction) {
				$db->rollback();
				}
			return false;
			}
		$this->{$this->primaryKeyName} = $db->insertId();
		if ($closeTransaction) {
			$db->commit();
			}
		//Updating cache...
		$this->updateCache();
		//Return result
		return true;
	}
1164668
protected function _insert()
    {
        $myConfig = \OxidEsales\Eshop\Core\Registry::getConfig();
        $oUtilsDate = \OxidEsales\Eshop\Core\Registry::getUtilsDate();

        //V #M525 orderdate must be the same as it was
        if (!$this->oxorder__oxorderdate || !$this->oxorder__oxorderdate->value) {
            $this->oxorder__oxorderdate = new \OxidEsales\Eshop\Core\Field(date('Y-m-d H:i:s', $oUtilsDate->getTime()), \OxidEsales\Eshop\Core\Field::T_RAW);
        } else {
            $this->oxorder__oxorderdate = new \OxidEsales\Eshop\Core\Field(
                $oUtilsDate->formatDBDate(
                    $this->oxorder__oxorderdate ? $this->oxorder__oxorderdate->value : null,
                    true
                )
            );
        }

        $this->oxorder__oxshopid = new \OxidEsales\Eshop\Core\Field($myConfig->getShopId(), \OxidEsales\Eshop\Core\Field::T_RAW);
        $this->oxorder__oxsenddate = new \OxidEsales\Eshop\Core\Field(
            $oUtilsDate->formatDBDate(
                $this->oxorder__oxsenddate ? $this->oxorder__oxsenddate->value : null,
                true
            )
        );

        $blInsert = parent::_insert();

        return $blInsert;
    }
167597
public function insert(): self
    {
        /** @var self $data */
        $data = $this;

        if(!$this->validate("post", $missing))
        {
            throw new \Exception("[MVQN\REST\Endpoints\Endpoint] Annotations for the '".get_class($this)."' class require valid values be set ".
                "on all of the following properties before attempting an insert():\n> ".implode("\n> ", $missing)."\n");
        }

        /** @var self $endpoint */
        $endpoint = self::post($data);
        return $endpoint;
    }
1155214
protected function insert()
    {
        $aggregate = $this->aggregate;

        $attributes = $aggregate->getRawAttributes();

        $keyName = $aggregate->getEntityMap()->getKeyName();

        // Check if the primary key is defined in the attributes
        if (array_key_exists($keyName, $attributes) && $attributes[$keyName] != null) {
            $this->query->insert($attributes);
        } else {
            // Prevent inserting with a null ID
            if (array_key_exists($keyName, $attributes)) {
                unset($attributes[$keyName]);
            }

            if (isset($attributes['attributes'])) {
                unset($attributes['attributes']);
            }

            $id = $this->query->insertGetId($attributes, $keyName);

            $aggregate->setEntityAttribute($keyName, $id);
        }
    }
102241
public function save()
    {
        $this->hook('beforeSave', array($this->id));

        $is_update = $this->loaded();
        if ($is_update) {
            $source = array();
            foreach ($this->dirty as $name => $junk) {
                $source[$name] = $this->get($name);
            }

            // No save needed, nothing was changed
            if (empty($source)) {
                return $this;
            }

            $this->hook('beforeUpdate', array(&$source));
        } else {

            // Collect all data of a new record
            $source = $this->get();

            $this->hook('beforeInsert', array(&$source));
        }

        if ($this->controller) {
            $this->id = $this->controller->save($this, $this->id, $source);
        }

        if ($is_update) {
            $this->hook('afterUpdate');
        } else {
            $this->hook('afterInsert');
        }

        if ($this->loaded()) {
            $this->dirty = array();
            $this->hook('afterSave', array($this->id));
        }

        return $this;
    }
1073321
private function add()
    {
        $columns = [];
        $values = [];
        //
        if ($this->_tracked) {
            $this->created_at = Time::current();
        }
        //
        foreach ($this->_columns as $value) {
            if ($value != $this->_keyName && isset($this->$value) && !empty($this->$value)) {
                $columns[] = $value;
                $values[] = $this->$value;
            }
        }
        //
        return $this->insert($columns, $values);
    }
159508
public function insert()
    {
        $query = 'insert into '.$this->getTables($this->tables).' ('.$this->columns.') values ('.$this->values.')';
        //
        $this->reset();
        //
        return Database::exec($query);
    }
57868
public function create()
    {
        $menu = $this->handler->add($this->name, $this->getAttribute('position'))
                    ->title($this->getAttribute('title'))
                    ->link($this->getAttribute('link'))
                    ->handles($this->menu['link'] ?? null);

        $this->attachIcon($menu);
        $this->handleNestedMenu();

        return $this;
    }
444124
public function getInsertQuery()
    {
        $sql = 'INSERT INTO ' . $this->getTable();
        $sql .= "\n" . $this->getColumns();
        $sql .= "\nVALUES " . $this->getValues();

        return $sql;
    }
337213
public function save()
	{
		if (empty($this->dirty))
		{
			return;	// Nothing to do
		}

		// Now insert or update depending on $this->primary_key.
		if (isset($this->record[$this->primary_key]))
		{
			// Update this record
			$new_record = $this->update($this->record);
		}
		else
		{
			// Create this record
			$new_record = $this->insert($this->record);
		}

		// Replace the record
		$this->hydrate($new_record);
	}
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;
    }
1316648
public function updateInsertQuery($insert)
    {
        if ($this->relation) {
            $insert = $this->relation->dsql;
        }

        $insert->set(
            $this->actual_field ?: $this->short_name,
            $this->getSQL()
        );

        return $this;
    }
757599
public function add() {
        global $CFG, $USER, $DB;

        unset($this->id);
        $this->module       = 'blog';
        $this->userid       = (empty($this->userid)) ? $USER->id : $this->userid;
        $this->lastmodified = time();
        $this->created      = time();

        // Insert the new blog entry.
        $this->id = $DB->insert_record('post', $this);

        if (!empty($CFG->useblogassociations)) {
            $this->add_associations();
        }

        core_tag_tag::set_item_tags('core', 'post', $this->id, context_user::instance($this->userid), $this->tags);

        // Trigger an event for the new entry.
        $event = \core\event\blog_entry_created::create(array(
            'objectid'      => $this->id,
            'relateduserid' => $this->userid
        ));
        $event->set_blog_entry($this);
        $event->trigger();
    }
1097401
private function insert() {
        if ($this->isPersistent()) throw new RuntimeException('Cannot insert already persistent '.$this);

        // pre-processing hook
        if ($this->beforeInsert() !== true)
            return $this;

        $mapping = $this->dao()->getMapping();

        // collect column values
        $values = [];
        foreach ($mapping['columns'] as $column => $property) {
            $values[$column] = $this->getPhysicalValue($column);
        };

        // perform insertion
        $id = $this->doInsert($values);
        $this->_modified = false;

        // assign the returned identity value
        $idName = $mapping['identity']['name'];
        if ($this->$idName === null)
            $this->$idName = $id;

        // post-processing hook
        $this->afterInsert();
        return $this;
    }
195925
protected function _insert()
    {
        // set oxinsert value
        $this->oxpricealarm__oxinsert = new \OxidEsales\Eshop\Core\Field(date('Y-m-d', \OxidEsales\Eshop\Core\Registry::getUtilsDate()->getTime()));

        return parent::_insert();
    }
829140
protected function insertDayReports()
    {
        foreach ($this->arrays as $recordName => $dataArray) {
            $dataTable = $dataArray->asDataTable();
            $blob = $dataTable->getSerialized(
                $this->maximumRowsInDataTable,
                $this->maximumRowsInSubDataTable,
                $this->columnToSortByBeforeTruncation);
            $this->getProcessor()->insertBlobRecord($recordName, $blob);
        }
    }