Return table indexes - everything lowercased
@param string $table The table we want to get indexes from.
@return array of arrays
321597
public function get_indexes($table) {
        $indexes = array();
        $sql = 'PRAGMA index_list('.$this->prefix.$table.')';
        if ($this->debug) {
            $this->debug_query($sql);
        }
        $rsindexes = $this->pdb->query($sql);
        foreach($rsindexes as $index) {
            $unique = (boolean)$index['unique'];
            $index = $index['name'];
            $sql = 'PRAGMA index_info("'.$index.'")';
            if ($this->debug) {
                $this->debug_query($sql);
            }
            $rscolumns = $this->pdb->query($sql);
            $columns = array();
            foreach($rscolumns as $row) {
                $columns[] = strtolower($row['name']);
            }
            $index = strtolower($index);
            $indexes[$index]['unique'] = $unique;
            $indexes[$index]['columns'] = $columns;
        }
        return $indexes;
    }
242630
protected function loadColumnListForTable($table)
    {
        if ($this->getDatabaseDriver() === 'sqlite') {
            $statement = "PRAGMA table_info(`{$table}`)";
        } else {
            $statement = "SHOW columns FROM `{$table}`";
        }

        $columnResults = DB::select($statement);
        $columns       = [];

        foreach ($columnResults as $columnObject) {

            $columns[] = array_get(array_values((array) $columnObject), '0');
        }

        return $columns;
    }
883283
public function getResetSequenceSQL($table) {

        if ($table instanceof xmldb_table) {
            $tablename = $table->getName();
        } else {
            $tablename = $table;
        }

        // From http://dev.mysql.com/doc/refman/5.0/en/alter-table.html
        $value = (int)$this->mdb->get_field_sql('SELECT MAX(id) FROM {'.$tablename.'}');
        $value++;
        return array("ALTER TABLE $this->prefix$tablename AUTO_INCREMENT = $value");
    }
437039
public function indexList($table)
    {
        $indexes = $this->query("EXEC sp_helpindex '$table';");
        $indexList = array();

        // Enumerate all basic indexes
        foreach ($indexes as $index) {
            if (strpos($index['index_description'], 'unique') !== false) {
                $indexType = 'unique ';
            } else {
                $indexType = 'index ';
            }

            // Extract name from index
            $baseIndexName = $this->buildMSSQLIndexName($table, '');
            $indexName = substr($index['index_name'], strlen($baseIndexName));

            // Extract columns
            $columns = $this->quoteColumnSpecString($index['index_keys']);
            $indexList[$indexName] = $this->parseIndexSpec($indexName, array(
                'name' => $indexName,
                'value' => $columns,
                'type' => $indexType
            ));
        }

        // Now we need to check to see if we have any fulltext indexes attached to this table:
        if ($this->database->fullTextEnabled()) {
            $result = $this->query('EXEC sp_help_fulltext_columns;');

            // Extract columns from this fulltext definition
            $columns = array();
            foreach ($result as $row) {
                if ($row['TABLE_NAME'] == $table) {
                    $columns[] = $row['FULLTEXT_COLUMN_NAME'];
                }
            }

            if (!empty($columns)) {
                $indexList['SearchFields'] = $this->parseIndexSpec('SearchFields', array(
                    'name' => 'SearchFields',
                    'value' => $this->implodeColumnList($columns),
                    'type' => 'fulltext'
                ));
            }
        }

        return $indexList;
    }
788076
protected function getPrimaryKeys(array $table): array
    {
        $primaryKeys = [];
        foreach ($table['columns'] as $column) {
            $columnName = $column['COLUMN_NAME'];
            $columnKey = $column['COLUMN_KEY'];
            if ($columnKey !== 'PRI') {
                continue;
            }
            $primaryKeys[] = $columnName;
        }

        return $primaryKeys;
    }
682895
public function getTableSequences($table)
	{
		$this->connect();

		// To check if table exists and prevent SQL injection
		$tableList = $this->getTableList();

		if (\in_array($table, $tableList, true))
		{
			$name = array('s.relname', 'n.nspname', 't.relname', 'a.attname', 'info.data_type',
				'info.minimum_value', 'info.maximum_value', 'info.increment', 'info.cycle_option',
			);
			$as = array('sequence', 'schema', 'table', 'column', 'data_type',
				'minimum_value', 'maximum_value', 'increment', 'cycle_option',
			);

			if (version_compare($this->getVersion(), '9.1.0') >= 0)
			{
				$name[] .= 'info.start_value';
				$as[] .= 'start_value';
			}

			// Get the details columns information.
			$query = $this->getQuery(true);
			$query->select($this->quoteName($name, $as))
				->from('pg_class AS s')
				->leftJoin("pg_depend d ON d.objid=s.oid AND d.classid='pg_class'::regclass AND d.refclassid='pg_class'::regclass")
				->leftJoin('pg_class t ON t.oid=d.refobjid')
				->leftJoin('pg_namespace n ON n.oid=t.relnamespace')
				->leftJoin('pg_attribute a ON a.attrelid=t.oid AND a.attnum=d.refobjsubid')
				->leftJoin('information_schema.sequences AS info ON info.sequence_name=s.relname')
				->where("s.relkind='S' AND d.deptype='a' AND t.relname=" . $this->quote($table));
			$this->setQuery($query);

			return $this->loadObjectList();
		}

		return false;
	}
609559
public function MetaColumns($table)
    {
        $sm = $this->getSchemaManager();
        $schemaColumns = $sm->listTableColumns($table);

        return $schemaColumns;
    }
543481
public function columns($table)
    {
        return Cache::remember("{$table}_columns", $this->lifetime(), function () use ($table) {
            $columns = $this->manager->listTableColumns($table);
            $keys = array_keys($columns);
            $vals = array_values($columns);

            $keys = array_map(function ($key) {
                return trim(str_replace(['`', '"'], '', $key));
            }, $keys);

            return array_combine($keys, $vals);
        });
    }
142797
public function getTableForeignKeys( $table )
    {
        $query = 'SELECT CONSTRAINT_SCHEMA, CONSTRAINT_NAME, TABLE_NAME, COLUMN_NAME,
                  REFERENCED_TABLE_SCHEMA, REFERENCED_TABLE_NAME, REFERENCED_COLUMN_NAME
                  FROM information_schema.KEY_COLUMN_USAGE WHERE CONSTRAINT_SCHEMA = ?
                  AND TABLE_NAME = ? AND REFERENCED_COLUMN_NAME IS NOT NULL;';

        $params = [ $this->name, $table ];

        $statement = $this->database->prepare( $query );
        $statement->execute( $params );

        $results = $statement->fetchAll();

        $keys = [ ];

        if ( !empty( $results ) )
        {
            foreach ( $results as $result )
            {
                $record                          = [ ];
                $record[ 'database' ]            = $result[ 'CONSTRAINT_SCHEMA' ];
                $record[ 'key_name' ]            = $result[ 'CONSTRAINT_NAME' ];
                $record[ 'table' ]               = $result[ 'TABLE_NAME' ];
                $record[ 'column' ]              = $result[ 'COLUMN_NAME' ];
                $record[ 'referenced_database' ] = $result[ 'REFERENCED_TABLE_SCHEMA' ];
                $record[ 'referenced_table' ]    = $result[ 'REFERENCED_TABLE_NAME' ];
                $record[ 'referenced_column' ]   = $result[ 'REFERENCED_COLUMN_NAME' ];

                $keys[ ] = $record;
            }
        }

        return $keys;
    }
124391
protected function _getFields(Table $table)
    {
        $fields = explode(',', $this->args[1]);
        foreach ($fields as $field) {
            if (!$table->hasField($field)) {
                $this->abort(sprintf('Table `%s` is missing the field `%s`.', $table->table(), $field));
            }
        }

        return $fields;
    }
1158288
public function list_cols($table)
    {
        $q = $this->query('SELECT COLUMN_NAME FROM INFORMATION_SCHEMA.COLUMNS WHERE TABLE_NAME = ?',
            array($table));

        if ($q) {
            return $q->fetchAll(PDO::FETCH_COLUMN, 0);
        }

        return array();
    }
691263
public function getTableKeys($table)
	{
		$this->connect();

		/** @var OracleQuery $query */
		$query = $this->getQuery(true);

		$fieldCasing = $this->getOption(\PDO::ATTR_CASE);

		$this->setOption(\PDO::ATTR_CASE, \PDO::CASE_UPPER);

		$table = strtoupper($table);
		$query->select('*');
		$query->from('ALL_CONSTRAINTS');
		$query->where('table_name = :tableName');

		$query->bind(':tableName', $table);

		$this->setQuery($query);
		$keys = $this->loadObjectList();

		$this->setOption(\PDO::ATTR_CASE, $fieldCasing);

		return $keys;
	}
350994
public function get_columns($table) {
		$result = $this->get_table_definition($table);

		$columns = [];
		foreach ($result as $row) {
			$columns[] = &$row['Field'];
		}

		return $columns;
	}
83931
public function getColumns($table)
    {
        //Argument 1 must be a string
        Argument::i()->test(1, 'string');
        
        $query = $this->utility()->showColumns($table);
        $results = $this->query($query, $this->getBinds());
        
        $columns = array();
        foreach ($results as $column) {
            $key = null;
            if ($column['pk'] == 1) {
                $key = 'PRI';
            }
            
            $columns[] = array(
                'Field'     => $column['name'],
                'Type'      => $column['type'],
                'Default'   => $column['dflt_value'],
                'Null'      => $column['notnull'] != 1,
                'Key'       => $key);
        }
        
        return $columns;
    }
1127213
public function getTableColumns($table, $allColumns = false)
    {
        $tableColumns = Schema::getColumnListing($table);

        $tableTypeColumns = [];
        $badColumns = ['id', 'created_at', 'updated_at'];

        if ($allColumns) {
            $badColumns = [];
        }

        foreach ($tableColumns as $column) {
            if (!in_array($column, $badColumns)) {
                $type = DB::connection()->getDoctrineColumn($table, $column)->getType()->getName();
                $tableTypeColumns[$column]['type'] = $type;
            }
        }

        return $tableTypeColumns;
    }
864560
protected function getAlterTableInfo($table)
    {
        $columns = $table->getColumns();
        $indexes = $table->getIndexes();
        $name    = $table->getName();

        $databaseService = new DatabaseService($this->config, $this->files);
        $upMigrations    = [
            'columns' => [
                'add'  => [],
                'drop' => [],
            ],
            'indexes' => [
                'add'  => [],
                'drop' => [],
            ],
        ];
        $downMigrations  = [
            'columns' => [
                'add'  => [],
                'drop' => [],
            ],
            'indexes' => [
                'add'  => [],
                'drop' => [],
            ],
        ];

        $updated = false;

        $currentColumns = $databaseService->getTableColumns($name);
        $newColumnNames = array_map(function ($column) {
            return $column->getName();
        }, $columns);
        $oldColumnNames = array_map(function ($column) {
            return $column->getName();
        }, $currentColumns);

        $mustHaveColumns = ['created_at', 'updated_at'];
        foreach ($mustHaveColumns as $column) {
            if (!in_array($column, $newColumnNames)) {
                $newColumnNames[] = $column;
            }
            if (!in_array($column, $oldColumnNames)) {
                $oldColumnNames[] = $column;
            }
        }

        $addedColumns   = array_diff($newColumnNames, $oldColumnNames);
        $removedColumns = array_diff($oldColumnNames, $newColumnNames);

        $previousColumnName = '';
        foreach ($columns as $column) {
            if (in_array($column->getName(), $addedColumns)) {
                $columnObject = new Column($column);

                $upMigrations['columns']['add'][]    = $columnObject->generateAddMigration($previousColumnName).';';
                $downMigrations['columns']['drop'][] = $columnObject->generateDropMigration().';';
                $updated                             = true;
            }
            $previousColumnName = $column->getName();
        }

        $previousColumnName = '';
        foreach ($currentColumns as $column) {
            if (in_array($column->getName(), $removedColumns)) {
                $columnObject = new Column($column);

                $upMigrations['columns']['drop'][]  = $columnObject->generateDropMigration().';';
                $downMigrations['columns']['add'][] = $columnObject->generateAddMigration($previousColumnName).';';
                $updated                            = true;
            }
            $previousColumnName = $column->getName();
        }

        $currentIndexes = $databaseService->getTableIndexes($name);
        $newIndexNames  = array_map(function ($index) {
            return $index->getName();
        }, $indexes);
        $oldIndexNames  = array_map(function ($index) {
            return $index->getName();
        }, $currentIndexes);

        $addedIndexes   = array_diff($newIndexNames, $oldIndexNames);
        $removedIndexes = array_diff($oldIndexNames, $newIndexNames);

        foreach ($indexes as $index) {
            if (in_array($index->getName(), $addedIndexes)) {
                $indexObject = new Index($index);

                $upMigrations['indexes']['add'][]    = $indexObject->generateAddMigration().';';
                $downMigrations['indexes']['drop'][] = $indexObject->generateDropMigration().';';
                $updated                             = true;
            }
        }

        foreach ($currentIndexes as $index) {
            if (in_array($index->getName(), $removedIndexes)) {
                $indexObject = new Index($index);

                $upMigrations['indexes']['drop'][]  = $indexObject->generateDropMigration().';';
                $downMigrations['indexes']['add'][] = $indexObject->generateAddMigration().';';
                $updated                            = true;
            }
        }

        if (!$updated) {
            return false;
        }

        return [
            'upMigrations'   => $upMigrations,
            'downMigrations' => $downMigrations,
        ];
    }
1265773
public function getPrimaryKeys($table)
    {
        $pk = [];
        $cols = $this->getColumns($table);
        if ($cols) {
            foreach ($cols as $key => $val){
                if(isset($val['is_primary']) && $val['is_primary']) {
                    $pk[] = $key;
                }
            }
        }
        
        return $pk;
    }