Return the list of indexes in a table.
@param string $table The table name.
@return array
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;
    }
987455
public function getTableInfo($table)
    {
        if (!$this->tableExists($table)) {
            return null;
        }
        
        $rtable = static::buildRealTableName($table, true);
        $key = 'db/tableinfo/' . $rtable;
        $data = static::getCache()->get($key);
        
        if (!$data) {
            $data = ['table_name' => $table];
            $data['fields'] = $this->getColumns($table);
            $pk = [];
            foreach ($data['fields'] as $key => $val) {
                if($val['is_primary']) {
                    $pk[] = $key;
                }
            }
            $data['primary_key'] = $pk ? $pk[0] : null;
            
            static::getCache()->set($key, $data);
        }
        
        return $data;
    }
268370
protected function addIndexes(Table $table)
    {
        $stmt = $this->dbh->query("SELECT INDEX_NAME, COLUMN_NAME FROM USER_IND_COLUMNS WHERE TABLE_NAME = '" . $table->getName() . "' ORDER BY COLUMN_NAME");

        $indices = [];
        while ($row = $stmt->fetch(\PDO::FETCH_ASSOC)) {
            $indices[$row['INDEX_NAME']][]= $row['COLUMN_NAME'];
        }

        foreach ($indices as $indexName => $columnNames) {
            $index = new Index($indexName);
            foreach ($columnNames as $columnName) {
                // Oracle deals with complex indices using an internal reference, so...
                // let's ignore this kind of index
                if ($table->hasColumn($columnName)) {
                    $index->addColumn($table->getColumn($columnName));
                }
            }
            // since some of the columns are pruned above, we must only add an index if it has columns
            if ($index->hasColumns()) {
                $table->addIndex($index);
            }
        }
    }
738561
public function getTableSequences($table)
    {
        // To check if table exists and prevent SQL injection
        $tableList = $this->db->getDatabase()->getTables();

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

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

            // Get the details columns information.
            $query = $this->db->getQuery(true);

            $query->select($this->db->quoteName($name))
                ->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->db->quote($table));

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

            $seq = $this->db->loadAll();

            return $seq;
        }

        return false;
    }
1095254
final public function fetchTableDef(string $table) {
        $tableKey = strtolower($table);

        // First check the table cache.
        if (isset($this->tables[$tableKey])) {
            $tableDef = $this->tables[$tableKey];

            if (isset($tableDef['columns'], $tableDef['indexes'])) {
                return $tableDef;
            }
        } elseif ($this->tableNames !== null && !isset($this->tableNames[$tableKey])) {
            return null;
        }

        $tableDef = $this->fetchTableDefDb($table);
        if ($tableDef !== null) {
            $this->fixIndexes($tableDef['name'], $tableDef);
            $this->tables[$tableKey] = $tableDef;
        }

        return $tableDef;
    }
55935
public function getColumns($table)
    {
        $table = $this->prefixTable($table);

        if (empty($this->queriesResultCache[ 'tableColumns' ][ $table ])) {
            $result = $this->query('PRAGMA TABLE_INFO(' . $this->protectIdentifiers($table, true, null, false) . ')');

            if ($result->count()) {
                foreach ($result as $row) {
                    // Do we know from where to get the column's name?
                    if ( ! isset($key)) {
                        if (isset($row[ 'name' ])) {
                            $key = 'name';
                        }
                    }

                    $this->queriesResultCache[ 'tableColumns' ][ $table ][ $row->offsetGet($key) ] = $row;
                }
            }
        }

        return $this->queriesResultCache[ 'tableColumns' ][ $table ];
    }
145563
public function getFields ($table)
		{
			$sql = "SELECT * FROM INFORMATION_SCHEMA.COLUMNS WHERE TABLE_NAME = " . $this->quote($table);

			return $this->query($sql)->fetchColumn('COLUMN_NAME');
		}
752270
protected function _fetchTableIndexes($table)
    {
        $result = array();
        $sql    = $this->quoteName($this->getTableNeedle().$table);

        if ($indexes = $this->show('SHOW INDEX FROM '.$sql, AnDatabase::FETCH_OBJECT_LIST)) {
            foreach ($indexes as $index) {
                $result[$index->Key_name][$index->Seq_in_index] = $index;
            }
        }

        return $result;
    }
26288
public function list_cols($table)
    {
        $q = $this->query('SELECT sql FROM sqlite_master WHERE type = ? AND name = ?',
            array('table', $table));

        $columns = array();

        if ($sql = $this->fetch_array($q)) {
            $sql       = $sql[0];
            $start_pos = strpos($sql, '(');
            $end_pos   = strrpos($sql, ')');
            $sql       = substr($sql, $start_pos+1, $end_pos-$start_pos-1);
            $lines     = explode(',', $sql);

            foreach ($lines as $line) {
                $line = explode(' ', trim($line));

                if ($line[0] && strpos($line[0], '--') !== 0) {
                    $column = $line[0];
                    $columns[] = trim($column, '"');
                }
            }
        }

        return $columns;
    }
1251925
public function columns($table)
	{
		$columns = array();
		$sth = $this->queryColumnInfo($table);

		while (($row = $sth->fetch())) {
			$c = $this->createColumn($row);
			$columns[$c->name] = $c;
		}
		return $columns;
	}
252197
public function getTable($table)
    {
        return array_merge(
            $this->cache['tables'][$table],
            [
                'fields'      => $this->cache['fields'][$table] ?? [],
                'constraints' => $this->cache['constraints'][$table] ?? [],
            ]
        );
    }
148735
public static function describe(string $table) :array {

		// set the cachefile name
		$cache_name = ucfirst($table).'Nulls';

		// check if it has been cached already
		if(Cache::has($cache_name)) {

			// get it from the cache
			return Cache::get($cache_name);

		}
		// else it is not available from the cache
		else {

			// the list of allowed null columns
			$allowed_nulls = [];

			// query the database
			foreach(self::query()
				->query(str_replace('*table*', $table, self::$_config['nulls']['query']))
				->execute() as $column) {

				// populate the list
				$allowed_nulls[$column->get(self::$_config['nulls']['column_for_name'])] = 
					self::$_config['nulls']['true'] == $column->get(self::$_config['nulls']['column_for_value']) ? true : false;

			}

			// save the results in the cache
			Cache::put($cache_name, $allowed_nulls);

			// and finaly return the results
			return $allowed_nulls;

		}

	}
341537
final public function fetchColumnDefs(string $table) {
        $tableKey = strtolower($table);

        if (!empty($this->tables[$tableKey]['columns'])) {
            $this->tables[$tableKey]['columns'];
        } elseif ($this->tableNames !== null && !isset($this->tableNames[$tableKey])) {
            return null;
        }

        $columnDefs = $this->fetchColumnDefsDb($table);
        if ($columnDefs !== null) {
            $this->tables[$tableKey]['columns'] = $columnDefs;
        }
        return $columnDefs;
    }
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();
    }
640225
public function indexedColumns($table)
    {
        return Cache::remember("{$table}_indexed_columns", $this->lifetime(), function () use ($table) {
            $indexedColumns = array_reduce($this->indexes($table), function ($indexedColumns, $index) {
                return array_merge($indexedColumns, $index->getColumns());
            }, []);

            return array_unique($indexedColumns);
        });
    }
114116
public function MetaColumnNames($table)
    {
        $sm = $this->getSchemaManager();
        $columnNames = [];
        $columns = $sm->listTableColumns($table);
        foreach ($columns as $column) {
            $columnNames[] = $column->getName();
        }

        return $columnNames;
    }
608272
public function getFields ($table)
		{
			$sql = "SHOW COLUMNS FROM " . $this->quoteIdentifier($table);

			return $this->query($sql)->fetchColumn('Field');
		}