Retrieves the index information about the given table

@param   string  $table A table name
@return  array   An associative array of indexes by index name
963015
protected function _fetchTableIndexes($table)
    {
        $return = array();
        $query  = $this->getObject('lib:database.query.show')
            ->show('INDEX')
            ->from($table);

        if($indexes = $this->select($query, Database::FETCH_OBJECT_LIST))
        {
            foreach($indexes as $index) {
                $return[$index->Key_name][$index->Seq_in_index] = $index;
            }
        }

        return $return;
    }
208662
public function getTableKeys($table)
	{
		$keys = array();

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

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

		$table = strtoupper($table);

		$this->setQuery('pragma table_info( ' . $table . ')');
		$rows = $this->loadObjectList();

		foreach ($rows as $column)
		{
			if ($column->PK == 1)
			{
				$keys[$column->NAME] = $column;
			}
		}

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

		return $keys;
	}
531301
public function getTableDefinition($table)
    {
        foreach ($this->getTableDefinitions() as $definition) {
            if ($definition->getName() === $table) {
                return $definition;
            }
        }

        return null;
    }
837112
public function PrefixTable($Table) {
      $Prefix = $this->Database->DatabasePrefix;
      
      if ($Prefix != '' && substr($Table, 0, strlen($Prefix)) != $Prefix)
         $Table = $Prefix.$Table;

      return $Table;
   }
758107
public function getColumns($table)
    {
        if (!isset($this->_columns[$table])) {
            $fields = $this->_adapter->select('SHOW COLUMNS FROM #__'.$table, AnDatabase::FETCH_ARRAY_LIST);

            static    $column;

            $columns = array();

            foreach ($fields as $field) {
                list($type, $length, $scope) = $this->_parseColumnType($field['Type']);
                $column = $column ? clone $column : new AnDomainResourceColumn();
                $column->name = $field['Field'];
                $column->type = isset($this->_typemap[$type]) ? $this->_typemap[$type] : 'string';
                $column->default = $field['Default'];
                $column->required = $field['Null'] == 'NO';
                $column->primary = $field['Key'] == 'PRI';
                $column->unique = $field['Key'] == 'UNI';
                $columns[$column->name] = $column;
            }

            $this->_columns[$table] = $columns;
        }

        return $this->_columns[$table];
    }
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;
    }
237288
public function get_indexes($table) {
        $indexes = array();
        $sql = "SHOW INDEXES FROM {$this->prefix}$table";
        $this->query_start($sql, null, SQL_QUERY_AUX);
        $result = $this->mysqli->query($sql);
        try {
            $this->query_end($result);
        } catch (dml_read_exception $e) {
            return $indexes; // table does not exist - no indexes...
        }
        if ($result) {
            while ($res = $result->fetch_object()) {
                if ($res->Key_name === 'PRIMARY') {
                    continue;
                }
                if (!isset($indexes[$res->Key_name])) {
                    $indexes[$res->Key_name] = array('unique'=>empty($res->Non_unique), 'columns'=>array());
                }
                $indexes[$res->Key_name]['columns'][$res->Seq_in_index-1] = $res->Column_name;
            }
            $result->close();
        }
        return $indexes;
    }
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();
    }
469546
public function get_indexes($table) {
        $indexes = array();
        $tablename = strtoupper($this->prefix.$table);

        $sql = "SELECT i.INDEX_NAME, i.UNIQUENESS, c.COLUMN_POSITION, c.COLUMN_NAME, ac.CONSTRAINT_TYPE
                  FROM ALL_INDEXES i
                  JOIN ALL_IND_COLUMNS c ON c.INDEX_NAME=i.INDEX_NAME
             LEFT JOIN ALL_CONSTRAINTS ac ON (ac.TABLE_NAME=i.TABLE_NAME AND ac.CONSTRAINT_NAME=i.INDEX_NAME AND ac.CONSTRAINT_TYPE='P')
                 WHERE i.TABLE_NAME = '$tablename'
              ORDER BY i.INDEX_NAME, c.COLUMN_POSITION";

        $stmt = $this->parse_query($sql);
        $result = oci_execute($stmt, $this->commit_status);
        $this->query_end($result, $stmt);
        $records = null;
        oci_fetch_all($stmt, $records, 0, -1, OCI_FETCHSTATEMENT_BY_ROW);
        oci_free_statement($stmt);

        foreach ($records as $record) {
            if ($record['CONSTRAINT_TYPE'] === 'P') {
                //ignore for now;
                continue;
            }
            $indexname = strtolower($record['INDEX_NAME']);
            if (!isset($indexes[$indexname])) {
                $indexes[$indexname] = array('primary' => ($record['CONSTRAINT_TYPE'] === 'P'),
                                             'unique'  => ($record['UNIQUENESS'] === 'UNIQUE'),
                                             'columns' => array());
            }
            $indexes[$indexname]['columns'][] = strtolower($record['COLUMN_NAME']);
        }

        return $indexes;
    }
879008
private function getIndexes($table, $type = [])
    {
        $unique = $primaryKey = $index = null;
        extract($type);
        $indexes = $this->schemaManager->listTableIndexes($table);
        $keys = [];
        foreach ($indexes as $indexObj) {
            if ($unique && $indexObj->isUnique()) {
                $keys[] = $indexObj;
            }
            if ($primaryKey && $indexObj->isPrimary()) {
                $keys[] = $indexObj;
            }
            if ($index && $indexObj->isSimpleIndex()) {
                $keys[] = $indexObj;
            }
        }

        return $keys;
    }
57538
public function getCreateTable($table)
    {
        $tableName = $this->validTableName($table['table']);
        $sql = '';
        foreach ($table['fields'] as $field => $value) {
            $sql .= ($sql === '') ? '' : ', ';
            $sql .= '`' . $field . '` ' . $value['type'];
            if (isset($value['autoincrement']) && $value['autoincrement']) {
                $sql .= ' AUTO_INCREMENT PRIMARY KEY';
            }
            if (isset($value['primary']) && $value['primary']) {
                $sql .= ' PRIMARY KEY';
            }
        }

        return 'CREATE TABLE ' . $tableName . '(' . $sql . ')';
    }
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;
	}
1250983
public function getColumns( $table ) {
		$table = $this->safeTable($table);
		$columnsRaw = $this->adapter->get("DESCRIBE $table");
		foreach($columnsRaw as $r) {
			$columns[$r['Field']]=$r['Type'];
		}
		return $columns;
	}
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;
    }
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;
    }
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;
    }
586777
public function getColmuns($table)
    {
        $table = self::table($table);
        $columns = [];
        //
        $data = Database::read("select COLUMN_NAME FROM INFORMATION_SCHEMA.COLUMNS WHERE TABLE_SCHEMA = '".Config::get('database.database')."' AND TABLE_NAME = '$table';");
        //
        foreach ($data as $key => $value) {
            $columns[] = $value['COLUMN_NAME'];
        }
        //
        return $columns;
    }