Think\Db\Builder::insertAll PHP Метод

insertAll() публичный Метод

生成insertall SQL
public insertAll ( array $dataSet, array $options ) : string
$dataSet array 数据集
$options array 表达式
Результат string
    public function insertAll($dataSet, $options)
    {
        // 获取合法的字段
        if ('*' == $options['field']) {
            $fields = array_keys($this->query->getFieldsType($options));
        } else {
            $fields = $options['field'];
        }
        foreach ($dataSet as &$data) {
            foreach ($data as $key => $val) {
                if (!in_array($key, $fields, true)) {
                    if ($options['strict']) {
                        throw new Exception('fields not exists:[' . $key . ']');
                    }
                    unset($data[$key]);
                } elseif (is_scalar($val)) {
                    $data[$key] = $this->parseValue($val, $key);
                } else {
                    // 过滤掉非标量数据
                    unset($data[$key]);
                }
            }
            $value = array_values($data);
            $values[] = 'SELECT ' . implode(',', $value);
        }
        $fields = array_map([$this, 'parseKey'], array_keys(reset($dataSet)));
        $sql = str_replace(['%TABLE%', '%FIELD%', '%DATA%', '%COMMENT%'], [$this->parseTable($options['table'], $options), implode(' , ', $fields), implode(' UNION ALL ', $values), $this->parseComment($options['comment'])], $this->insertAllSql);
        return $sql;
    }