Processes a single insert statement.

@param mixed[]|Query[]|StatementInterface[]|InsertFromSelect $row
@param mixed $context The processing context
@return mixed[]|Query[]|StatementInterface[]|InsertFromSelect
544888
protected function processInsert($row, $context)
    {
        if ($row instanceof InsertFromSelect) {
            return $this->processInsertFromSelect($row, $context);
        }

        $newRow = [];
        foreach ($row as $column => $value) {
            $column = $this->processColumnName($column, $context);
            $newRow[$column] = $this->processValueOrSubQuery($value, $context);
        }

        return $newRow;
    }
1146086
public function addRow(array $row)
    {
        if (is_array($this->fields)) {
            $assoc = $row;
            $row = [];
            foreach ($this->fields as $field) {
                $row[] = isset($assoc[$field]) ? $assoc[$field] : "";
            }
        }

        $this->data[] = $row;

        return $this;
    }
362533
public function addRow(GridRow $row)
    {
        if (!$this->rows->contains($row)) {
            $this->rows->add($row);
            $row->setQuestion($this);
        }
    }
1226469
private function processInsertOperation(array $row): int
    {
        //准备语句
        $this->statement->insert($row);

        //检查是否需要记录数据库日志
        $operationLog = self::logEnabled();

        if (!$operationLog) {
            //不需要记录,直接执行
            $this->execute2();

            // 获取插入的记录的ID,执行后置钩子
            return $this->after('Insert', 'Insert', $this->getInsertedId());
        }

        //执行原始操作
        $this->execute2();

        //获取插入的记录的ID
        $id = $this->getInsertedId();

        //判断插入是否成功
        if ($id) {
            //重新取出插入的数据
            $after = $this->select2('*', $id,null,1);

            //记录日志
            call_user_func($operationLog, $this->tableName, 'insert', ['data' => $row, 'after' => $after]);
        } else {
            //记录日志
            call_user_func($operationLog, $this->tableName, 'insert', ['data' => $row, 'id' => '插入失败']);
        }

        // 获取插入的记录的ID,执行后置钩子
        return $this->after('Insert', 'Insert', $id);
    }
940216
protected function insertDefault( $table, $rows ) {

        $columns = $this->getColumns( $rows );
        if ( empty( $columns ) ) return;

        $query = $this->insertHead( $table, $columns );
        $lists = $this->valueLists( $rows, $columns );

        foreach ( $lists as $list ) {

            $singleQuery = $query . $list;

            $this->onQuery( $singleQuery );

            $statement = $this->prepare( $singleQuery );
            $statement->execute();

        }

        return $statement; // last statement is returned

    }
1293499
public function beforeInsert(Row $row): void
    {
        foreach ($row->values() as $column => $value) {
            if (null !== $value) {
                $row->changeColumnValue($column, $this->parseKeyIfNeeded($value));
            }
        }
    }
175004
public function insert($table, array $row, $pkval=false)
    {
    	$ds = $this->ds();
		list($holders, $values) = SqlHelper::placeholder($row);
        $holders = implode(',', $holders);
        
        $fields = SqlHelper::qfields(array_keys($values));        
        $table = SqlHelper::qtable($table);
		
        $result = Sql::write($ds, Sql::MODE_WRITE_INSERT, [
				SqlHelper::bind($ds, "INSERT INTO {$table} ({$fields}) VALUES ({$holders})", $row),
				$pkval
			]);
		return $result;
	}
214919
protected function _beforeInsert(DatabaseContext $context)
    {
        $mixer = $this->getMixer();
        $table = $mixer instanceof DatabaseRowInterface ?  $mixer->getTable() : $mixer;

        if($this->hasProperty('created_by') && empty($this->created_by)) {
            $this->created_by  = (int) $this->getObject('user')->getId();
        }

        if($this->hasProperty('created_on') && (empty($this->created_on) || $this->created_on == $table->getDefault('created_on'))) {
            $this->created_on  = gmdate('Y-m-d H:i:s');
        }
    }
1037083
def insert(self, row):
        
        self._check_dropped()
        res = self.engine.execute(self.table.insert(row))
        if len(res.inserted_primary_key) > 0:
            return res.inserted_primary_key[0]
991382
private function processReplace(array $row): int
    {
        // 执行具体插入操作
        $this->statement->replace($row);

        //检查是否需要记录数据库日志
        $operationLog = self::logEnabled();

        $before = '';
        //如果需要记录日志,记录操作前数据
        if ($operationLog) {
            $old = clone $this->statement;
            $before = self::select2('*', $row);
            $this->statement = clone $old;
        }

        //执行操作
        self::execute2();

        // 取插入后的记录的ID
        $id = $this->getInsertedId();
        if (!$id) {
            $id = $row['id'];
        }

        //如果需要记录日志,记录操作后数据
        if ($operationLog) {
            $after = self::select2('*', $row);
            call_user_func($operationLog, $this->tableName, 'replace', ['data' => $row, 'before' => $before, 'after' => $after]);
        }

        // 后置钩子
        return $this->after('Insert', 'Replace', $id);
    }
1256825
public function delete(KDatabaseRowInterface $row)
    {
        // Create query object.
        $query = $this->getObject('lib:database.query.delete')
            ->table($this->getBase());

        //Create commandchain context
        $context = $this->getContext();
        $context->table     = $this->getBase();
        $context->data      = $row;
        $context->query     = $query;
        $context->affected  = false;

        if ($this->invokeCommand('before.delete', $context) !== false)
        {
            foreach ($this->getPrimaryKey() as $key => $column)
            {
                $context->query->where($column->name . ' = :' . $column->name)
                    ->bind(array($column->name => $context->data->$key));
            }

            // Execute the delete query.
            $context->affected = $this->getAdapter()->delete($context->query);

            // Set the query in the context.
            if ($context->affected !== false) {
                $context->data->setStatus($context->affected ? KDatabase::STATUS_DELETED : KDatabase::STATUS_FAILED);
            }

            $this->invokeCommand('after.delete', $context);
        }

        return $context->affected;
    }
718667
function insertRow($row, $row_id = 0) {
        array_splice($this->_data, $row_id, 0, array($row));

        $this->_updateRowsCols($row);
    }
743633
public function createDataObject($row)
    {
        // remove any composed fields
        $add = [];

        if ($this->_compositeExtraFields) {
            foreach ($this->_compositeExtraFields as $fieldName => $composed) {
                // convert joined extra fields into their composite field types.
                $value = [];

                foreach ($composed as $subField) {
                    if (isset($row[$fieldName . $subField])) {
                        $value[$subField] = $row[$fieldName . $subField];

                        // don't duplicate data in the record
                        unset($row[$fieldName . $subField]);
                    }
                }

                $obj = Injector::inst()->create($this->extraFields[$fieldName], $fieldName);
                $obj->setValue($value, null, false);
                $add[$fieldName] = $obj;
            }
        }

        $dataObject = parent::createDataObject($row);

        foreach ($add as $fieldName => $obj) {
            $dataObject->$fieldName = $obj;
        }

        return $dataObject;
    }
798490
protected function _afterSelect(DatabaseContext $context)
    {
        if(!$context->query->isCountQuery())
        {
            $rowset = ObjectConfig::unbox($context->data);

            if ($rowset instanceof DatabaseRowsetInterface)
            {
                //Store the nodes
                $this->__nodes    = $rowset;
                $this->__iterator = null;
                $this->__children = array();

                foreach ($this->__nodes as $key => $row)
                {
                    //Force mixin the behavior into each row
                    $row->mixin($this);

                    if($row->isRecursable()) {
                        $parent = (int) $row->getProperty($this->_parent_column);
                    } else {
                        $parent = 0;
                    }

                    //Store the nodes by parent
                    $this->__children[$parent][$key] = $row;
                }

                //Sort the children
                ksort($this->__children);
            }
        }
    }
271877
public function loadCollectionValues(LoadingContext $context, array $rows) : array
    {
        $primaryKey = $this->primaryKeyColumn->getName();
        $ids        = [];

        foreach ($rows as $key => $row) {
            $ids[$key] = $row->getColumn($primaryKey);
        }

        return $ids;
    }
627707
def insert(self, row):
        
        data = self._convert_value(row)
        self._service.InsertRow(data, self._ss.id, self.id)
899483
public function insert(Table $table, $row)
    {
        $end = $this->startCommandTimer();
        $this->writeCommand('insert', [$table->getName()]);
        parent::insert($table, $row);
        $end();
    }