Insert a new item in the database.
@return Item
768037
public function insert()
    {
        Observer::dispatch(Observer::EVENT_ITEM_INSERT_BEFORE, array(
            'item' => $this
        ));

        $this->{static::DATEADDFIELD} = DateData::now();
        $insert = new Insert($this->_dbContainer);
        $insert->addFields($this->_fields);
        $insert->commit();
        $this->setId($insert->getId());
        $this->_origFields = $this->_fields;

        Observer::dispatch(Observer::EVENT_ITEM_INSERT_AFTER, array(
            'item' => $this
        ));

        return $this;
    }
159238
public function insert()
    {
        $result = $this->connection()->post($this->getEndpoint(), $this->jsonWithNamespace());

        return $this->selfFromResponse($result);
    }
1230454
protected function create()
	{
		// Only allow creation with new object, otherwise: clone first, create later
		if ( ! $this->is_new())
		{
			return false;
		}

		$this->observe('before_insert');

		// Set all current values
		$query = Query::forge(get_called_class(), static::connection(true));
		$primary_key = static::primary_key();
		$properties  = array_keys(static::properties());
		foreach ($properties as $p)
		{
			if ( ! (in_array($p, $primary_key) and is_null($this->{$p})))
			{
				$query->set($p, $this->{$p});
			}
		}

		// Insert!
		$id = $query->insert();

		// when there's one PK it might be auto-incremented, get it and set it
		if (count($primary_key) == 1 and $id !== false)
		{
			$pk = reset($primary_key);
			// only set it if it hasn't been set manually
			is_null($this->{$pk}) and $this->{$pk} = $id;
		}

		// update the original properties on creation and cache object for future retrieval in this request
		$this->_is_new = false;
		$this->_original = $this->_data;
		static::$_cached_objects[get_class($this)][static::implode_pk($this)] = $this;

		$this->observe('after_insert');

		return $id !== false;
	}
256093
public function insert()
    {
        if( !$this->tableName ) {
            throw new LogicException('No table name specified');
        }
        return $this->database->insert()
                ->table($this->tableName);
    }
319164
function save()
    {
        if ($this->id != false || $this->id != 0) {
            return $this->update();
        } else {
            return $this->insert();
        }
    }
569848
public function newId() {
        $ids = [];
        $cnt = $this->count();
        if ($cnt === false) {
            if ($this->exception instanceof \PDOException) {
                $this->error = $this->exception->getMessage();
            }
            log_error($this->error . '[' . $this->getSqlString() . ']', 'sql.err');

            return 0;
        } else if ($this instanceof InsertSQL) {
            $ids = $this->lastInsertIds();
        }

        return $ids ? $ids[0] : 0;
    }
909944
public function add()
    {
        $role = $this->Roles->newEntity();
        if ($this->request->is('post')) {
            $data = (array)$this->request->getData();
            /**
             * @var \RolesCapabilities\Model\Entity\Role $role
             */
            $role = $this->Roles->patchEntity($role, $data);
            // prepare associated capability records for creation
            if (!empty($data['capabilities'])) {
                $role->capabilities = $this->Roles->prepareCapabilities(
                    json_decode($data['capabilities'], true)
                );
            }

            if ($this->Roles->save($role)) {
                $this->Flash->success((string)__('The role has been saved.'));

                return $this->redirect(['action' => 'index']);
            } else {
                $this->Flash->error((string)__('The role could not be saved. Please, try again.'));
            }
        }
        $groups = $this->Roles->Groups->find('list', ['limit' => 200]);

        $capabilities = $this->formatCapabilities(Utils::getAllCapabilities());

        $this->set(compact('role', 'groups', 'capabilities'));
        $this->set('_serialize', ['role']);
    }
899737
public static function insert($table = null)
    {
        $query = new Insert();

        if ($table) {
            $query->into($table);
        }

        return $query;
    }
455547
public function insert()
    {
        self::$instance->reset();
        $this->sql('INSERT INTO ' . $this->oosql_table);

        $arg_list = func_get_args();
        $numargs = func_num_args();

        if ($numargs > 0) {
            $this->oosql_numargs = $numargs;
            $this->sql(' (');

            $this->sql(implode(',', $arg_list));

            $this->sql(')');
        }
        $this->oosql_insert = true;
        return $this;
    }
970558
public function insert($table = null)
    {
        $this->type = self::TYPE_INSERT;
        if ($table) {
            $this->table($table);
        }

        return $this;
    }
1354684
protected function _insert()
    {
        // set oxinsert
        $sNow = date('Y-m-d H:i:s', \OxidEsales\Eshop\Core\Registry::getUtilsDate()->getTime());
        $this->oxarticles__oxinsert = new \OxidEsales\Eshop\Core\Field($sNow);
        if (!is_object($this->oxarticles__oxsubclass) || $this->oxarticles__oxsubclass->value == '') {
            $this->oxarticles__oxsubclass = new \OxidEsales\Eshop\Core\Field('oxarticle');
        }

        return parent::_insert();
    }
455089
private function getPreparedInsert()
    {
        if (is_null($this->preparedInsert)) {
            $this->preparedInsert = $this->getServer()
                ->insert($this->tableName, true)
                ->set($this->keyColumnName, ':id')
                ->set($this->valueColumnName, ':value')
                ->set($this->expireColumnName, ':expire');
        }

        return $this->preparedInsert;
    }
971886
public function insert()
    {
        $this->SQLTemplate('insert')->execute();

        return
            $this->hasInsertOption('ignore') ? null :
            $this->owner->lastID();
    }
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;
    }
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();
        }
    }
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();
    }
1089525
public function insert($insert)
    {
        $this->type = self::INSERT;

        $this->from($insert);

        return $this;
    }