Generate main part with name and params.

@param array[]     $columns Columns from table.
@param string|null $spType  Stored procedure type {insert|update|delete|select}.

@return array|null
540395
protected function checkUniqueKeys(array $columns, ?string $spType = null): ?array
  {
    $primaryKeys = MetadataDataLayer::getTablePrimaryKeys($this->dataSchema, $this->tableName);
    $uniqueKeys  = MetadataDataLayer::getTableUniqueKeys($this->dataSchema, $this->tableName);

    $resultColumns = [];

    if (!isset($spType))
    {
      if (empty($uniqueKeys) && empty($primaryKeys))
      {
        return null;
      }
      else
      {
        return $columns;
      }
    }

    if (!empty($primaryKeys))
    {
      foreach ($columns as $column)
      {
        $check = StaticDataLayer::searchInRowSet('Column_name', $column['column_name'], $primaryKeys);
        if (isset($check))
        {
          $resultColumns[] = $column;
        }
      }

      return $resultColumns;
    }
    else
    {
      if (!empty($uniqueKeys))
      {
        reset($uniqueKeys);
        $first = key($uniqueKeys);
        if (count($uniqueKeys)>1)
        {
          $this->io->writeln(sprintf('Table <dbo>%s</dbo> has more than one unique key.', $this->tableName));

          $array = [];
          foreach ($uniqueKeys as $column)
          {
            if (isset($array[$column['Key_name']]))
            {
              $array[$column['Key_name']] .= ',';
              $array[$column['Key_name']] .= $column['Column_name'];
            }
            else
            {
              $array[$column['Key_name']] = $column['Column_name'];
            }
          }

          $tableArray = [];
          foreach ($array as $key => $column)
          {
            $tableArray[] = [$key, $column];
          }

          $table = new Table($this->output);
          $table->setHeaders(['Name', 'Keys']);
          $table->setRows($tableArray);
          $table->render();

          $question   = new Question(sprintf('What unique keys use in statement?(%s): ',
                                             $uniqueKeys[$first]['Key_name']),
                                     $uniqueKeys[$first]['Key_name']);
          $uniqueKeys = $this->helper->ask($this->input, $this->output, $question);
          $uniqueKeys = explode(',', $array[$uniqueKeys]);
          foreach ($uniqueKeys as $column)
          {
            $resultColumns[] = ['column_name' => $column];
          }

          return $resultColumns;
        }
        else
        {
          foreach ($uniqueKeys as $column)
          {
            $resultColumns[] = ['column_name' => $column['Column_name']];
          }

          return $resultColumns;
        }
      }
      else
      {
        return null;
      }
    }
  }
11718
protected function prepareColumn(Column $column)
    {
        /** @var PostgresqlType $typeMapper */
        $typeMapper = $this->getDataType();

        $type = $typeMapper::getType($column->getType());

        $length = $typeMapper::noLength($type) ? null : $column->getLength();

        $column->length($length);

        if ($column->getAutoIncrement()) {
            $column->type(PostgresqlType::SERIAL);
            $options['sequences'][$column->getName()] = $this->getName() . '_' . $column->getName() . '_seq';
        }

        return parent::prepareColumn($column);
    }
1297820
public function updateColumns($itemType, &$columns)
    {
        // Skip single subsite setups
        if (!Subsite::get()->count()) {
            return;
        }

        // Set title
        $mainSiteLabel = _t('SilverStripe\\SiteWideContentReport\\SitewideContentReport.MainSite', 'Main Site');
        if ($itemType !== 'Pages') {
            $mainSiteLabel .= ' '._t(
                'SilverStripe\\SiteWideContentReport\\SitewideContentReport.AccessFromAllSubsites',
                '(accessible by all subsites)'
            );
        }

        // Add subsite name
        $columns['SubsiteName'] = [
            'title' => _t('SilverStripe\\SiteWideContentReport\\SitewideContentReport.Subsite', 'Subsite'),
            'datasource' => function ($item) use ($mainSiteLabel) {
                $subsite = $item->Subsite();

                if ($subsite && $subsite->exists() && $subsite->Title) {
                    return $subsite->Title;
                } else {
                    return $mainSiteLabel;
                }
            },
        ];
    }
115755
public function updateColumns($itemType, &$columns)
    {
        if ($itemType !== 'Pages') {
            return;
        }

        // Check if pages has the tags field
        if (!self::enabled()) {
            return;
        }

        // Set column
        $field = Config::inst()->get(__CLASS__, 'tag_field');
        $columns['Terms'] = [
            'printonly' => true, // Hide on page report
            'title' => _t('SilverStripe\\SiteWideContentReport\\SitewideContentReport.Tags', 'Tags'),
            'datasource' => function ($record) use ($field) {
                $tags = $record->$field()->column('Name');

                return implode(', ', $tags);
            },
        ];
    }
1312102
public function sqlFetchColumn(string $sql, array $params = [], string $column = '0')
    {
        $stmt = $this->prepare($sql, $params);

        if (ctype_digit((string) $column)) {
            return $stmt->fetchColumn($column);
        }

        if ($record = $stmt->fetch()) {
            return array_key_exists($column, $record) ? $record[$column] : null;
        }

        return null;
    }
205526
public function delete(array $columns = null): \PDOStatement
    {
        /* @var $response \PDOStatement */
        $queryObject = $this->getQuery('delete', $columns);

        $this->connection->setLastQuery($queryObject);

        $this->fireEvents(EventHandler::EVENT_BEFORE_DELETE, $queryObject);

        [$response, $executionTime] = $this->statement($queryObject->getSql(), $queryObject->getBindings());
        $this->fireEvents(EventHandler::EVENT_AFTER_DELETE, $queryObject, [
            'execution_time' => $executionTime,
        ]);

        return $response;
    }
980991
protected function createIdentifier(string $type, array $columns): string
    {
        $name = $this->getName() . '_' . $type . '_' . join('_', $columns) . '_' . uniqid();

        if (strlen($name) > 64) {
            //Many DBMS has limitations on identifier length
            $name = md5($name);
        }

        return $name;
    }
344878
public function getAddColumnsDDL($columns)
    {
        $ret = '';
        foreach ($columns as $column) {
            $ret .= $this->getAddColumnDDL($column);
        }

        return $ret;
    }
250198
public function getColumnList($columns, $delim = ',')
    {
        $list = array();
        foreach ($columns as $col) {
            if ($col instanceof Column) {
                $col = $col->getName();
            }
            $list[] = $col;
        }

        return implode($delim, $list);
    }
1014721
public function bindColumn($column, &$param, $type = PDO::PARAM_STR, $maxlen = -1, $driverdata = null) {
		$type = $this->removeBitFlag($$type, PDO::PARAM_INPUT_OUTPUT);
		$ociParamType = $this->pdo2OciParamConst($type);
		// LOBs
		if ($lob_desc = $this->oci_lob_desc($ociParamType)) {
			$this->_lobs[$this->_lobsCount]['type'] = $ociParamType;
			$this->_lobs[$this->_lobsCount]['lob'] = @oci_new_descriptor($this->ociPdoAdapter->getOciConnection(), $lob_desc);
			$res = $this->_lobs[$this->_lobsCount]['lob'];
			$this->checkError($res);
			$res = @oci_define_by_name($this->stmt, $column, $this->_lobs[$this->_lobsCount]['lob'], $ociParamType);
			$this->checkError($res);
			$this->_lobs[$this->_lobsCount]['var'] = $param;
			$this->_lobs[$this->_lobsCount]['input'] = false;

			$this->_lobsCount++;
		}
		else {
			$res = @oci_define_by_name($this->stmt, $column, $param, $ociParamType);
			$this->checkError($res);
		}

		return $res;
	}
981538
public function column($columns, $definition, $type)
    {
        if (is_null($columns)) {
            throw new \BadMethodCallException('Column cannot be empty.');
        }

        if (is_array($columns)) {
            $column = $columnKey = $columnValue = '';
            $i = 0;
            $arrCount = count($columns);

            foreach ($columns as $key => $value) {
                if (trim($type) == 'drop') {
                    $columnKey = '';
                    $columnValue = "`$value`";
                    $column .= strtoupper(trim($type)).' '.$columnKey.' '.$columnValue;
                }

                if (trim($type) == 'add') {
                    $columnKey = $key;
                    $columnValue = strtoupper($value);
                    $column .= strtoupper($type).' ('.$columnKey.' '.$columnValue.')';
                }

                $comma = ($i < $arrCount - 1) ? ',' : '';

                $column .= $comma;

                $i++;
            }

            $this->schema = self::ALTER_TABLE.'`'.$this->database.'`.`'.$this->tableName.'`
            '.$column.';';
        }

        if (is_string($columns)
            && $definition != null
        ) {
            /** @var $definition TYPE_NAME */
            $definition = (trim($type) == 'drop') ? '' : strtoupper($definition);

            $this->schema = self::ALTER_TABLE.'`'.$this->database.'`.`'.$this->tableName.'`
            '.strtoupper($type).' `'.$columns.'` '.$definition.';';
        }

        return $this;
    }
162649
protected function handleSetColumns(array $columns)
    {
        if (empty($columns)) {
            return '';
        }

        $sql = [];

        foreach ($columns as $column) {
            $sql[] = $this->wrap($column['column']) . ' = ' . $this->param($column['value']);
        }

        return ' SET ' . implode(', ', $sql);
    }
1254027
public function replace($table, array $columns = null, array $where = null): ?array
    {
        if (\is_array($table)) {
            $columns = $this->getColumns($table, false);
            $table = $this->getTable($table);
            $where = $table;
        } elseif ($where) {
            $where = [SQL::WHERE => $where];
        }

        if (!\is_array($columns) || empty($columns)) {
            return null;
        }

        $map = [];
        $stack = [];

        foreach ($columns as $column => $replacements) {
            if (\is_array($replacements)) {
                foreach ($replacements as $old => $new) {
                    $mapKey = $this->mapKey();

                    $stack[] = $this->columnQuote($column) . ' = REPLACE(' . $this->columnQuote($column) . ', ' . $mapKey . 'a, ' . $mapKey . 'b)';

                    $map[$mapKey . 'a'] = [$old, PDO::PARAM_STR];
                    $map[$mapKey . 'b'] = [$new, PDO::PARAM_STR];
                }
            }
        }

        if ($stack === []) {
            return null;
        }

        $sql = 'UPDATE ' . $this->tableQuote($table) . ' SET ' .
            \implode(', ', $stack) . $this->suffixClause($where, $map);

        return [$sql, $map];
    }
1094550
protected function prepareColumn(Column $column)
    {
        if ($column->getType() === SqlsrvType::FLOAT && strpos($column->getLength(), ',') !== false) {
            $column->length(24);
        }

        if ($column->getType() === SqlsrvType::DOUBLE && strpos($column->getLength(), ',') !== false) {
            $column->length(53);
        }

        if (in_array($column->getType(), [SqlsrvType::TEXT, SqlsrvType::LONGTEXT], true)) {
            $column->length('max');
        }

        $column = parent::prepareColumn($column);

        if (SqlsrvType::noLength($column->getType())) {
            $column->length(null);
        }

        return $column;
    }
384316
public function get($columns = array('*'))
    {
        $results = parent::get($columns);

        switch($this->returnType) {
            case Builder::RETURN_TYPE_DATAMAPPER:
                return $results->toDatamapperObject();
            case Builder::RETURN_TYPE_ELOQUENT:
                return $results;
        }
    }
453230
public function addIndex($type, $columns = [], $name = null, $comment = null, $options = [])
    {
        if (!$type instanceof Key) {
            if (!$columns) {
                throw new \InvalidArgumentException('No columns given.');
            }

            $columns = (array) $columns;

            $index = new Key($type, $columns, $name, $comment);
        } else {
            $index = $type;
        }

        if ($this->hasIndex($index->getName())) {
            $this->dropIndex($index->getName());
        }

        $query = SqlsrvGrammar::addIndex(
            $this->db->replacePrefix($this->getName()),
            strtolower($index->getType()) === 'key' ? 'INDEX' : $index->getType(),
            $index->getColumns(),
            $index->getName()
        );

        $this->db->execute($query);

        // No index comment now.
//        if ($index->getComment()) {
//            $query = SqlsrvGrammar::comment('INDEX', 'public', $index->getName(), $index->getComment());
//
//            $this->db->setQuery($query)->execute();
//        }

        return $this->reset();
    }
1244749
protected function indexCommand($type, $columns, $index, $algorithm = null)
    {
        $columns = (array) $columns;

        // If no name was specified for this index, we will create one using a basic
        // convention of the table name, followed by the columns, followed by an
        // index type, such as primary or index, which makes the index unique.
        $index = $index ?: $this->createIndexName($type, $columns);

        return $this->addCommand(
            $type, compact('index', 'columns', 'algorithm')
        );
    }