Return table indexes - everything lowercased.
@param string $table The table we want to get indexes from.
@return array of arrays
342891
public function get_indexes($table) {
        $indexes = array();
        $tablename = $this->prefix.$table;

        $sql = "SELECT i.*
                  FROM pg_catalog.pg_indexes i
                  JOIN pg_catalog.pg_namespace as ns ON ns.nspname = i.schemaname
                 WHERE i.tablename = '$tablename'
                       AND (i.schemaname = current_schema() OR ns.oid = pg_my_temp_schema())";

        $this->query_start($sql, null, SQL_QUERY_AUX);
        $result = pg_query($this->pgsql, $sql);
        $this->query_end($result);

        if ($result) {
            while ($row = pg_fetch_assoc($result)) {
                // The index definition could be generated schema-qualifying the target table name
                // for safety, depending on the pgsql version (CVE-2018-1058).
                if (!preg_match('/CREATE (|UNIQUE )INDEX ([^\s]+) ON (|'.$row['schemaname'].'\.)'.$tablename.' USING ([^\s]+) \(([^\)]+)\)/i', $row['indexdef'], $matches)) {
                    continue;
                }
                if ($matches[5] === 'id') {
                    continue;
                }
                $columns = explode(',', $matches[5]);
                foreach ($columns as $k=>$column) {
                    $column = trim($column);
                    if ($pos = strpos($column, ' ')) {
                        // index type is separated by space
                        $column = substr($column, 0, $pos);
                    }
                    $columns[$k] = $this->trim_quotes($column);
                }
                $indexes[$row['indexname']] = array('unique'=>!empty($matches[1]),
                                              'columns'=>$columns);
            }
            pg_free_result($result);
        }
        return $indexes;
    }
42493
protected function getAlternatePrimaryKeys($table)
    {
        $alternatePrimaryKey = false;
        $primaryKeys = [];
        foreach ($table['columns'] as $column) {
            $columnName = $column['COLUMN_NAME'];
            $columnKey = $column['COLUMN_KEY'];
            if ($columnKey !== 'PRI') {
                continue;
            }
            if ($columnName !== 'id') {
                $alternatePrimaryKey = true;
            }
            $primaryKeys[] = '"' . $columnName . '"';
        }
        if ($alternatePrimaryKey) {
            return $primaryKeys;
        }

        return null;
    }
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;
	}
179093
protected function getTableFields(Table $table)
	{
		$fileds = [];

		foreach ($table->getColumns() as $column) {
			$fileds[] = [
	            'name' => $column->getName(),
	            'type' => $column->getType()->getName(),
	            'not_null' => $column->getNotnull(),
	            'length' => $column->getLength(),
	            'unsigned' => $column->getUnsigned(),
	            'autoincrement' => $column->getAutoincrement(),
	            'primary_key' => $this->isPrimaryKey($table, $column),
	            'foreign_key' => $this->isForeignKey($table, $column)
			];
		}

		return $fileds;
	}
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;
    }
654590
protected function _fetchTableColumns($table)
    {
        $result = array();
        $sql    = $this->quoteName($this->getTableNeedle().$table);

        if ($columns = $this->show('SHOW FULL COLUMNS FROM '.$sql, AnDatabase::FETCH_OBJECT_LIST)) {
            foreach ($columns as $column) {
                //Set the table name in the raw info (MySQL doesn't add this)
                $column->Table = $table;

                //Parse the column raw schema data
                $column = $this->_parseColumnInfo($column, $table);

                $result[$column->name] = $column;
            }
        }

        return $result;
    }
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;
    }
924909
protected function parseUpdateTable($table)
    {
        $table = $alias = $this->wrapTable($table);

        if (stripos($table, '] as [') !== false) {
            $alias = '['.explode('] as [', $table)[1];
        }

        return [$table, $alias];
    }
1345216
public function getComparators(TableNode $table) {
    $comparators = [];
    $headers = $table->getRow(0);
    foreach ($headers as $header) {
      $comparators[$header] = function ($expected, $actual) {
        if (substr($expected, 0, 1) === "/") {
          return preg_match($expected, $actual);
        } else {
          return $expected === $actual;
        }
      };
    }
    return $comparators;
  }
932744
protected function getTableKey($table) {
        if (empty(static::$tableKeys)) {
            $this->loadTableKeys();
        }

        return isset(static::$tableKeys[$table]) ? static::$tableKeys[$table] : static::$tableKeys['__default__'];
    }
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();
    }
700514
public function PrimaryKeyRange($Table) {
      $Model = $this->CreateModel($Table);
      
      $Data = $this->SQL
         ->Select($Model->PrimaryKey, 'min', 'MinValue')
         ->Select($Model->PrimaryKey, 'max', 'MaxValue')
         ->From($Table)
         ->Get()->FirstRow(DATASET_TYPE_ARRAY);
      
      if ($Data)
         return array($Data['MinValue'], $Data['MaxValue']);
      else
         return array(0, 0);
   }
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;
    }
35050
public function getTableColumns($table)
    {
        $driver = $this->getDriverName();
        $bind = [];
        if ($driver == 'sqlite') {
            $table = $this->quoteIdentifiers($table);
            $sql = 'PRAGMA table_info(' . $table . ');';
            $key = 'name';
        } elseif ($driver == 'mysql') {
            $table = $this->quoteIdentifiers($table);
            $sql = 'DESCRIBE ' . $table . ';';
            $key = 'Field';
        } else {
            $bind[] = $table;
            $sql = 'SELECT column_name FROM information_schema.columns WHERE ';
            if($driver == 'pgsql'){
                $bind = explode('.', $table, 2);
                if(count($bind) == 2){
                    $sql.='table_schema = ? AND ';
                }
            }
            $sql.='table_name = ? ;';
            $key = 'column_name';
        }

        $fields = [];
        if (is_array($list = $this->run($sql, $bind, false))) {
            foreach ($list as $record) {
                $fields[] = $record[$key];
            }
            return $fields;
        }
        return $fields;
    }
1240624
public function describeTable($table)
    {
        if (!$this->connection->expr('show tables like []', [$table])->get()) {
            return []; // no such table
        }

        $result = [];

        foreach ($this->connection->expr('describe {}', [$table]) as $row) {
            $row2 = [];
            $row2['name'] = $row['Field'];
            $row2['pk'] = $row['Key'] == 'PRI';
            $row2['type'] = preg_replace('/\(.*/', '', $row['Type']);

            $result[] = $row2;
        }

        return $result;
    }
1302234
protected function fetchIndexesDb($table = '') {
        $indexes = [];

        $indexInfos = $this->query('pragma index_list('.$this->prefixTable($table).')')->fetchAll(PDO::FETCH_ASSOC);
        foreach ($indexInfos as $row) {
            $indexName = $row['name'];
            if ($row['unique']) {
                $type = Db::INDEX_UNIQUE;
            } else {
                $type = Db::INDEX_IX;
            }

            // Query the columns in the index.
            $columns = $this->query('pragma index_info('.$this->quote($indexName).')')->fetchAll(PDO::FETCH_ASSOC);

            $index = [
                'name' => $indexName,
                'columns' => array_column($columns, 'name'),
                'type' => $type
            ];
            $indexes[] = $index;
        }

        return $indexes;
    }
383329
public function getFields($table)
	{
		if (isset($this->tables[$table])) {
			return new Collection($this->tables[$table]);
		}
	}