Insert records in chunks.

Note: can be used only from insert_records().

@param string $table
@param array $chunk
@param database_column_info[] $columns
336953
protected function insert_chunk($table, array $chunk, array $columns) {
        $fieldssql = '('.implode(',', array_keys($columns)).')';

        $valuessql = '('.implode(',', array_fill(0, count($columns), '?')).')';
        $valuessql = implode(',', array_fill(0, count($chunk), $valuessql));

        $params = array();
        foreach ($chunk as $dataobject) {
            foreach ($columns as $field => $column) {
                $params[] = $this->normalise_value($column, $dataobject[$field]);
            }
        }

        $sql = "INSERT INTO {$this->prefix}$table $fieldssql VALUES $valuessql";

        list($sql, $params, $type) = $this->fix_sql_params($sql, $params);
        $rawsql = $this->emulate_bound_params($sql, $params);

        $this->query_start($sql, $params, SQL_QUERY_INSERT);
        $result = $this->mysqli->query($rawsql);
        $this->query_end($result);
    }
321035
public function setColumns(array $columns)
    {
        $useColumns = [];

        foreach ($columns as $col) {
            $col = $this->createColumn($col);
            $useColumns[$col->getUniqueId()] = $col;
        }

        $this->columns = $useColumns;
    }
579848
public function insert($table, $data, $statements)
    {
        $input = [
            'columns' => '',
            'values' => ''
        ];

        $query = 'INSERT INTO `' . $table . '` ';

        foreach ($data as $column => $value) {
            $input['columns'] .= $column . ', ';

            $value = (is_null($statements) && is_string($value)) ? "'$value'" : $value;

            $input['values'] .= $value . ', ';
        }

        $query .= '(' . rtrim(trim($input['columns']), ',') . ') ';

        $query .= 'VALUES (' . rtrim(trim($input['values']), ',') . ')';

        return $this->query($query, 'INSERT');
    }
996321
public function from($table, $columns = null)
    {
        $this->table($table);
        if( !empty($columns) ) {
            $this->columns($columns);
        }
        return $this;
    }
1172644
public static function insert(string $table, array $fields, array $values = null): string
    {
        // Compare $fields and $values arrays for equality
        if (isset($values)) {
            if (count($values) !== count($fields)) {
                echo "Fields count is not equal to Values count!" . PHP_EOL;
                exit;
            }
        }

        // Generate SQL statement
        $sql  = "INSERT INTO `$table` (";
        $sql .= "`" . implode('`, `', $fields) . "`";
        $sql .= ") VALUES (";

        $sql_fields = '';
        if (!isset($values)) {
            // If $value array  is not set, generate prepared SQL statement
            foreach ($fields as $field) {
                $sql_fields .= ":$field, ";
            }
        } else {
            // Otherwise use $values fields' values
            foreach ($values as $field) {
                $sql_fields .= "'$field', ";
            }
        }
        $sql .= rtrim($sql_fields, ' ,') . ")";
        return $sql;
    }
332887
public function add($chunk, $fileInfo = null, $index = 0, $mapLines = null){
		$this->strs[] = $chunk;
	}
900883
public function insert($columns) {
        // Check if array is associative
        if (Arr::is_assoc($columns)) {
            // Get array keys
            $arr_keys = array_keys($columns);

            // Get array values
            $arr_values = array_values($columns);

            $values = '';
            $fields = '';
            $insert  = [];

            // Build up the insert query
            $this->q->apd('INSERT INTO ' . $this->table_name . '(');

            for ($ii = 0; $ii < count($arr_keys); $ii++) {
                if ($ii != count($arr_keys) -1) {
                    $fields .= $arr_keys[$ii] . ', ';

                    if (!$this->is_SQL_function($arr_values[$ii])) {
                        $values .= ':' . $arr_keys[$ii] . ', ';
                        $insert[':' . $arr_keys[$ii]] = $arr_values[$ii];
                    } else {
                        $values .= $arr_values[$ii] . ', ';
                    }
                } else {
                    $fields .= $arr_keys[$ii] . ') VALUES (';

                    if (!$this->is_SQL_function($arr_values[$ii])) {
                        $values .= ':' . $arr_keys[$ii] . ')';
                        $insert[':' . $arr_keys[$ii]] = $arr_values[$ii];
                    } else {
                        $values .= $arr_values[$ii] . ')';
                    }
                }
            }

            // Finalize query
            $this->q->apd($fields . $values);

            try {
                $query = $this->db->prepare($this->q->get());
                $query->execute($insert);
                $this->clear();

                // Set last inserted id
                $this->lastInsertId = $this->db->lastInsertId();

                return true;
            } catch (\PDOException $e) {
                $this->setError('d', $e->getMessage());
                return false;
            }
        } else {
            echo 'Wrong array format';
            return false;
        }
    }
419079
public function chunk($count, $callback, $column = null)
    {
        $options = $this->getOptions();
        if (isset($options['table'])) {
            $table = is_array($options['table']) ? key($options['table']) : $options['table'];
        } else {
            $table = '';
        }
        $column    = $column ?: $this->getPk($table);
        if (isset($options['order'])) {
            unset($options['order']);
        }
        $bind      = $this->bind;
        $resultSet = $this->options($options)->limit($count)->order($column, 'asc')->select();
        if (strpos($column, '.')) {
            list($alias, $key) = explode('.', $column);
            unset($alias);
        } else {
            $key = $column;
        }

        while (!empty($resultSet)) {
            if (false === call_user_func($callback, $resultSet)) {
                return false;
            }

            $end    = end($resultSet);
            $lastId    = is_array($end) ? $end[$key] : $end->$key;
            $resultSet = $this->options($options)
                ->limit($count)
                ->bind($bind)
                ->where($column, '>', $lastId)
                ->order($column, 'asc')
                ->select();
        }
        return true;
    }
1160190
private function insertChunk($fileId, $data, $chunkNumber)
    {
        $chunk = [
            'files_id' => $fileId,
            'n' => $chunkNumber,
            'data' => new MongoBinData($data),
        ];

        $result = $this->chunks->insert($chunk);

        if (! $this->isOKResult($result)) {
            throw new \MongoException('error inserting chunk');
        }

        return $result;
    }
1321840
public function insert($tables = null)
    {
        if (null !== $tables) {
            $this->tables($tables);
        }
        $this->action = 'insert';
        return $this;
    }
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

    }
1374311
public void insertData(String table, Map<String, Object> fields) {
        String query = this.cassandraqueryUtils.insertData(table, fields);
        LOGGER.debug(query);
        executeQuery(query);
    }
57260
public function insertMany($table, array $columns, array $values)
    {
        $collection = array();

        foreach ($values as $index => $data) {
            foreach ($data as $key) {
                $collection[$index][] = $this->createUniqPlaceholder($key);
            }
        }

        $this->queryBuilder->insertMany($table, $columns, $collection);
        return $this;
    }
490414
public function addColumns(array $columns) : Table
    {
        foreach ($columns as $column => $definition) {
            if (is_numeric($column) && is_string($definition)) {
                $this->addColumn($definition, []);
            } else {
                $this->addColumn($column, $definition);
            }
        }
        return $this;
    }
1150814
public function update($table, $columns, $condition = [], array $params = [])
    {
        $request = $this->db->getQueryBuilder()->update($table, $columns, $condition, $params);

        return $this->setRequest($request);
    }
553610
public function declareCreation(string $table, array $columns)
    {
        $source = $this->method('up')->getSource();

        $source->addLine("\$this->table('{$table}')");
        foreach ($columns as $name => $type) {
            $source->addLine("    ->addColumn('{$name}', '{$type}')");
        }

        $source->addLine("    ->create();");

        $this->method('down')->getSource()->addString("\$this->table('{$table}')->drop();");
    }
357871
public function inserts($table, $rows)
	{
        if (!$rows) {
            return false;
        }

		$holds = array();

		$feilds = array_keys(reset($rows));

        $hold = '('.implode(',', array_fill(0, count($feilds), '?')).')';
		$holds = implode(",\n", array_fill(0, count($rows), $hold));
		$feilds = implode("`,`", $feilds);

        $vals = [];
        foreach ($rows as $row) {
            $vals = array_merge($vals, array_values($row));
        }

		$sql = "INSERT INTO `{$table}` (`{$feilds}`)\n VALUES {$holds}";

        $stmt = $this->prepare($sql);
        return $stmt ? $stmt->execute($vals) : false;
	}