Query to insert new field values.

@param QuerySet $queries
@param array    $changes
@param object   $entity
192712
protected function addToInsertQuery(QuerySet $queries, $changes, $entity)
    {
        foreach ($changes as $fieldValue) {
            $repo = $this->em->getRepository(get_class($fieldValue));
            $field = $this->getFieldType($fieldValue->getFieldname());
            $type = $field->getStorageType();
            $typeCol = 'value_' . $type->getName();

            $fieldValue->$typeCol = $fieldValue->getValue();
            $fieldValue->setFieldtype($this->getFieldTypeName($fieldValue->getFieldname()));
            $fieldValue->setContenttype((string) $entity->getContenttype());

            // This takes care of instances where an entity might be inserted, and thus not
            // have an id. This registers a callback to set the id parameter when available.
            $queries->onResult(
                function ($query, $result, $id) use ($repo, $fieldValue) {
                    if ($result === 1 && $id) {
                        $fieldValue->setContent_id($id);
                        $repo->save($fieldValue, true);
                    }
                }
            );
        }
    }
36629
public function setEntitiesAttribute($entities)
    {
        static::saved(function ($model) use ($entities) {
            $values = [];
            foreach ($entities as $entity) {
                $values[] = ['attribute_id' => $model->id, 'entity_type' => $entity];
            }

            DB::table(config('rinvex.attributable.tables.attribute_entity'))->where('attribute_id', $model->id)->delete();
            DB::table(config('rinvex.attributable.tables.attribute_entity'))->insert($values);
        });
    }
33183
private function processInsert()
    {
        if (empty($this->definition['fields']) && empty($this->definition['field'])) {
            Throw new QueryBuilderException('QueryBuilder need a "field" or "fields" list element to process "INSERT" definition.');
        }
        
        if (! isset($this->definition['params'])) {
            Throw new QueryBuilderException('QueryBuilder need a assoc array param list to process "INSERT" definition.');
        }
        
        $this->processFieldDefinition();
        $this->processParamsDefinition();
    }
1008721
public function insert(array $fields = []) {
        $query = new InsertQuery($this->getTable());
        $query->fields(!empty($fields)? $fields : $this->getFields());
        return $this->connection->exec($query);
    }
1029192
protected function multiQuery(string $queries): void
  {
    if ($this->logQueries)
    {
      $time0 = microtime(true);

      $tmp = $this->mysqli->multi_query($queries);
      if ($tmp===false)
      {
        throw new DataLayerException($this->mysqli->errno, $this->mysqli->error, $queries);
      }

      $this->queryLog[] = ['query' => $queries, 'time' => microtime(true) - $time0];
    }
    else
    {
      $tmp = $this->mysqli->multi_query($queries);
      if ($tmp===false)
      {
        throw new DataLayerException($this->mysqli->errno, $this->mysqli->error, $queries);
      }
    }
  }
69775
public void setEntities(java.util.Collection<AffectedEntity> entities) {
        if (entities == null) {
            this.entities = null;
            return;
        }

        this.entities = new java.util.ArrayList<AffectedEntity>(entities);
    }
555808
public int insertOrUpdate(Connection conn, Entity record, String... keys) throws SQLException {
		final Entity where = record.filter(keys);
		if(MapUtil.isNotEmpty(where) && count(conn, where) > 0) {
			return update(conn, record, where);
		}else {
			return insert(conn, record);
		}
	}
884259
public function insertMany(array $models, array $options = [])
    {
        $data = [];
        foreach ($models as $key => $model) {
            $data[$key] = get_values($model, false);
        }

        $result = $this->collection->insertMany($data, $options);
        if (false == $result->isAcknowledged()) {
            throw new \LogicException('Operation is not acknowledged');
        }

        foreach ($result->getInsertedIds() as $key => $modelId) {
            $this->hydrator->hydrate($data[$key], $models[$key]);
            set_object_id($models[$key], $modelId);

            $this->changesCollector->register($models[$key], $data[$key]);
        }

        return $result;
    }
938651
private function doUpdate(array $changes) {
        $db     = $this->db();
        $entity = $this->dao()->getEntityMapping();
        $table  = $entity->getTableName();

        // collect identity infos
        $identity = $entity->getIdentity();
        $idColumn = $identity->getColumn();
        $idValue  = $identity->convertToDBValue($this->getObjectId(), $db);

        // collect version infos
        $versionMapping = $versionName = $versionColumn = $oldVersion = null;
        //if ($versionMapping = $entity->getVersion()) {
        //    $versionName   = $versionMapping->getName();
        //    $versionColumn = $versionMapping->getColumn();
        //    $oldVersion    = $object->getSnapshot()->$versionName;        // TODO: implement dirty check via snapshot
        //    $oldVersion    = $versionMapping->convertToDBValue($oldVersion, $db);
        //}

        // create SQL
        $sql = 'update '.$table.' set';                                     // update table
        foreach ($changes as $name => $value) {                             //    set ...
            $mapping     = $entity->getProperty($name);                     //        ...
            $columnName  = $mapping->getColumn();                           //        ...
            $columnValue = $mapping->convertToDBValue($value, $db);         //        column1 = value1,
            $sql .= ' '.$columnName.' = '.$columnValue.',';                 //        column2 = value2,
        }                                                                   //        ...
        $sql  = strLeft($sql, -1);                                          //        ...
        $sql .= ' where '.$idColumn.' = '.$idValue;                         //    where id = value
        if ($versionMapping) {                                              //        ...
            $op   = $oldVersion=='null' ? 'is':'=';                         //        ...
            $sql .= ' and '.$versionColumn.' '.$op.' '.$oldVersion;         //      and version = oldVersion
        }

        // execute SQL and check for concurrent modifications
        if ($db->execute($sql)->lastAffectedRows() != 1) {
            if ($versionMapping) {
                $this->reload();
                $msg = 'expected version: '.$oldVersion.', found version: '.$this->$versionName;
            }
            else $msg = 'record not found';
            throw new ConcurrentModificationException('Error updating '.get_class($this).' (oid='.$this->getObjectId().'), '.$msg);
        }
        return true;
    }
1076551
public function setChanges($changes)
    {
        if ($changes instanceof Records) {
            $this->changes = $changes;
        } else {
            if (is_array($changes)) {
                $changes       = new Records($changes);
                $this->changes = $changes;
            }
        }
        return $this;
    }
1029647
public function addQueries(array $queries = array()) {
	    foreach($queries as $queryInfo) {
	        $batchAction = (isset($queryInfo[1])) ? $queryInfo[1] : null;
	        $this->addQuery($queryInfo[0], $batchAction);
	    }
	}
1100215
public function insert($entity)
    {
        $entityId = $this->entityRegistry->getEntityId($entity);

        if (empty($entityId)) {
            $id = 0;

            foreach ($this->gateway->getAll($this->tableName) as $row) {
                $id = max($id, $row['id']);
            }

            $this->entityRegistry->setEntityId($entity, $id + 1);
        }

        $this->gateway->insert($this->tableName, $this->builder->reduce($entity));
        $this->builder->resolve($entity);
    }
1371269
protected function insertRow(AbstractEntity $entity)
    {
        $values  = $entity->getDbValues();
        $columns = array_keys($values);

        if ($this->autoIncrementColumn && ! array_key_exists($this->autoIncrementColumn, $values)) {
            throw new LogicException('auto_increment column ' . $this->autoIncrementColumn . ' not found');
        }

        $query = $this->getSqlObject()
            ->insert()
            ->columns($columns)
            ->values($values);

        $statement = $this->getSqlObject()->prepareStatementForSqlObject($query);
        $result    = $statement->execute();

        if ($this->autoIncrementColumn && ! $values[$this->autoIncrementColumn]) {
            $entity->exchangeArray([
                $this->autoIncrementColumn => $result->getGeneratedValue()
            ]);
        }
    }
845333
protected function patchRow(AbstractEntity $entity)
    {
        $values = $entity->getChangedDbValues();
        if (empty($values)) {
            return;
        }

        $query = $this->getSqlObject()
            ->update()
            ->set($values)
            ->where($this->getPrimaryKeyWheres($entity));

        $this->execute($query);
    }
505563
public function executeInserts(array $options = []) : void
    {
        if (! $this->queuedInserts) {
            return;
        }

        $inserts = [];
        $options = $this->getWriteOptions($options);
        foreach ($this->queuedInserts as $oid => $document) {
            $data = $this->pb->prepareInsertData($document);

            // Set the initial version for each insert
            if ($this->class->isVersioned) {
                $versionMapping = $this->class->fieldMappings[$this->class->versionField];
                $nextVersion    = null;
                if ($versionMapping['type'] === 'int') {
                    $nextVersion = max(1, (int) $this->class->reflFields[$this->class->versionField]->getValue($document));
                    $this->class->reflFields[$this->class->versionField]->setValue($document, $nextVersion);
                } elseif ($versionMapping['type'] === 'date') {
                    $nextVersionDateTime = new DateTime();
                    $nextVersion         = Type::convertPHPToDatabaseValue($nextVersionDateTime);
                    $this->class->reflFields[$this->class->versionField]->setValue($document, $nextVersionDateTime);
                }
                $data[$versionMapping['name']] = $nextVersion;
            }

            $inserts[] = $data;
        }

        if ($inserts) {
            try {
                assert($this->collection instanceof Collection);
                $this->collection->insertMany($inserts, $options);
            } catch (DriverException $e) {
                $this->queuedInserts = [];
                throw $e;
            }
        }

        /* All collections except for ones using addToSet have already been
         * saved. We have left these to be handled separately to avoid checking
         * collection for uniqueness on PHP side.
         */
        foreach ($this->queuedInserts as $document) {
            $this->handleCollections($document, $options);
        }

        $this->queuedInserts = [];
    }
1154255
private function updateOldFieldAceProperty($name, array $changes)
    {
        $currentIds = array();
        foreach ($changes[1] as $field => $new) {
            for ($i = 0, $c = count($new); $i < $c; ++$i) {
                $ace = $new[$i];

                if (null !== $ace->getId()) {
                    $currentIds[$ace->getId()] = true;
                }
            }
        }

        foreach ($changes[0] as $old) {
            for ($i = 0, $c = count($old); $i < $c; ++$i) {
                $ace = $old[$i];

                if (!isset($currentIds[$ace->getId()])) {
                    $this->connection->executeQuery($this->getDeleteAccessControlEntrySql($ace->getId()));
                    unset($this->loadedAces[$ace->getId()]);
                }
            }
        }
    }
1082555
protected function hasChanged($doctrineChangeSet, $entity)
    {
        if (empty($doctrineChangeSet)) {
            return false;
        }

        $metaInformation = $this->metaInformationFactory->loadInformation($entity);

        $documentChangeSet = array();

        /* Check all Solr fields on this entity and check if this field is in the change set */
        foreach ($metaInformation->getFields() as $field) {
            if (array_key_exists($field->name, $doctrineChangeSet)) {
                $documentChangeSet[] = $field->name;
            }
        }

        return count($documentChangeSet) > 0;
    }