Gets column data information from a table

@param string $column_name Column name.
@param string $table       Table name.

@return array

@since 2.0.0
772153
public static function get_column_data( $column_name, $table ) {

		global $wpdb;

		$column_data = $wpdb->get_results( 'DESCRIBE ' . $table, ARRAY_A );

		foreach ( $column_data as $single_column ) {
			if ( $column_name === $single_column['Field'] ) {
				return $single_column;
			}
		}

		return $column_data;
	}
1094821
protected function getColumns($tableName): array
    {
        $sql = sprintf('SELECT * FROM information_schema.columns
                    WHERE table_schema=database()
                    AND table_name = %s', $this->quote($tableName));

        $rows = $this->queryFetchAll($sql);

        $result = [];
        foreach ($rows as $row) {
            $name = $row['COLUMN_NAME'];
            $result[$name] = $row;
        }

        return $result;
    }
327861
protected function _updateIndexes ($table_name) {
		$this->_indexes[$table_name] = [];
		foreach ($this->query(sprintf('SHOW INDEX FROM %s;', $table_name), \PDO::FETCH_ASSOC) as $index) {
			$this->_indexes[$table_name][$index['Key_name']][] = [
				'table_name'		=> $table_name,
				'temporary'			=> null,
				'unique'			=> !filter_var($index['Non_unique'], \FILTER_VALIDATE_BOOLEAN),
				'if_not_exists'		=> null,
				'key_name'			=> $index['Key_name'],
				'column_name'		=> $index['Column_name'],
				'seq_in_index'		=> $index['Seq_in_index'],
				'collation'			=> $index['Collation'],
				'cardinality'		=> $index['Cardinality'],
				'comment'			=> $index['Comment'],
				'index_comment'		=> $index['Index_comment'],
				'order'				=> null,
				'index_type'		=> $index['Index_type'],
				'sub_part'			=> $index['Sub_part'],
				'raw_data'			=> $index,
			];
		}
	}
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;
    }
793726
protected function getTableFields( $_table ) {

        $_sql = "SHOW COLUMNS FROM {$_table}";
        $_ret = $this->execute( $_sql );
        $_fields = array();
        if ( $_ret != false ) {
            while ( ($_rows = $_ret->fetch()) != false ) {
                $_fields[] = $_rows[0];
            }
        }
        return $_fields;
    }
1120069
public function &getColumn($query_name)
    {
        $retval = null;
        foreach ($this->columns as $col) {
            if ($col->query_name == $query_name) {
                $retval = &$col;
                break;
            }
        }
        return $retval;
    }
330127
public function FetchColumns($Table) {
      $Sql = $this->FetchColumnSql($Table);
      $Data = $this->Query($Sql);
      $Return = array();
      foreach($Data->ResultArray() as $Row) {
         if (isset($Row['COLUMN_NAME']))
            $Return[] = $Row['COLUMN_NAME'];
         else
            $Return[] = current($Row);
      }

      return $Return;
   }
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;
    }
1032012
private function _select($table_name, $columns, $primary_key_value)
	{
		// Get the schema and primary key
		$table_schema      = self::_getTableSchema($table_name);
		$table_primary_key = self::_getTablePrimaryKey($table_name);

		// Get the columns
		$parameter_columns = Validation::validateTableColumns($table_name, $table_schema, $columns);

		// Escape the column names
		$parameter_columns = self::_escapeColumnNames($parameter_columns);

		// Construct the primary key requirement
		$primary_key_value = intval($primary_key_value);

		// Clean the table name
		$table_name = self::_getCleanTableName($table_name);

		// Construct the SELECT sql
		$sql = '
			SELECT ' . implode(', ', $parameter_columns) . '
			FROM ' . $table_name . '
			WHERE ' . $table_primary_key . ' = $1;
		';

		// Sanitize and run the query
		$rows = Utility::pgQueryParams($sql, array($primary_key_value));

		// Validate result, check that primary key is set
		if (empty($rows) || !array_key_exists('0', $rows) || !array_key_exists($table_primary_key, $rows[0]))
		{
			Utility::throwException('Record not found for ' . $table_name . ' with a primary key value of ' . $primary_key_value);
		}

		// Return the only record
		return $rows[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;
    }
1320416
def fetch_column_names(self, table: str) -> List[str]:
        """"""
        return self.flavour.fetch_column_names(self, table)
458885
public function getColumn($name)
    {
        $columnValues = array();
        foreach ($this->getRows() as $row) {
            $columnValues[] = $row->getColumn($name);
        }
        return $columnValues;
    }
724502
protected function _updatePkeys ($table_name) {
		if (isset($this->getIndexes($table_name)['PRIMARY'])) {
			$this->_primaryKeys[$table_name] = [];
			$primary_keys = $this->getIndexes($table_name, true)['PRIMARY'];
			usort($primary_keys, function ($current, $next) {return $current['seq_in_index'] < $next['seq_in_index'];});
			foreach ($primary_keys as $primary_key) {
				$this->_primaryKeys[$table_name][] = $primary_key['column_name'];
			}
		} else {
			$this->_primaryKeys[$table_name] = null;
		}
	}
786114
public function insert ($table_name, $columns) {
		$column_keys = array();
		foreach ($columns as $key => $value) {
			$column_keys[$key] = ":" . $key;
		}

		$query = "INSERT INTO " . $table_name . " (" . implode(", ", array_keys($column_keys)) . ") VALUES (" . implode(", ", array_values($column_keys)) . ")";
		$this -> query($query, $columns, false);
		return $this -> getLastInsertedID();
	}
503154
public function getColumn($name, $use_alias = false)
    {
        if ($use_alias) {
            foreach ($this->columns as $column) {
                if (0 === strcasecmp($name, $column->getName($use_alias))) {
                    return $column;
                }
            }
        } else {
            $key = strtolower($name);
            if (isset($this->columns[$key])) {
                return $this->columns[$key];
            }
        }

        return null;
    }
999274
protected function getIdsInfo($table, $fields_info = null, &$requested_fields = null, $requested_types = null)
    {
        $idsInfo = [];
        if (empty($requested_fields)) {
            $requested_fields = [];
            /** @type ColumnSchema[] $idsInfo */
            $idsInfo = static::getPrimaryKeys($fields_info);
            foreach ($idsInfo as $info) {
                $requested_fields[] = $info->getName(true);
            }
        } else {
            if (false !== $requested_fields = static::validateAsArray($requested_fields, ',')) {
                foreach ($requested_fields as $field) {
                    $ndx = strtolower($field);
                    if (isset($fields_info[$ndx])) {
                        $idsInfo[] = $fields_info[$ndx];
                    }
                }
            }
        }

        return $idsInfo;
    }
56645
protected function _updateColumns ($table_name) {
		$stmt = $this->prepare('SELECT ccu.column_name FROM information_schema.table_constraints tc, information_schema.constraint_column_usage ccu WHERE tc.table_catalog = current_database() AND tc.table_name = ? AND tc.constraint_type = ? AND tc.table_catalog=ccu.table_catalog AND tc.table_schema = ccu.table_schema AND tc.table_name = ccu.table_name AND tc.constraint_name = ccu.constraint_name');
		$stmt->execute([$table_name, 'PRIMARY KEY']);
		$stmt->setFetchMode(\PDO::FETCH_NUM);
		$pkey_column_name = $stmt->fetch();
		$pkey_column_name = isset($pkey_column_name[0]) ? $pkey_column_name : null;

		$comments = [];
		$stmt = $this->prepare('SELECT pa.attname as column_name, pd.description as column_comment FROM pg_stat_all_tables psat, pg_description pd, pg_attribute pa WHERE psat.schemaname = current_schema() AND psat.relname = ? AND psat.relid = pd.objoid AND pd.objsubid <> 0 AND pd.objoid = pa.attrelid AND pd.objsubid = pa.attnum');
		$stmt->execute([$table_name]);
		foreach ($stmt as $comment) {
			$comments[$comment['column_name']] = $comment['column_comment'];
		}

		$pdo_param_list = $this->GetPdoParamList();

		$this->_columns[$table_name] = [];
		$stmt = $this->prepare('SELECT *  FROM information_schema.columns WHERE table_catalog = current_database() AND table_name = ? ORDER BY ordinal_position');
		$stmt->setFetchMode(\PDO::FETCH_ASSOC);
		$stmt->execute([$table_name]);
		foreach ($stmt as $columns) {
			$auto_increment = preg_match("/^nextval\('.+'::regclass\)$/", $columns['column_default']) !== 0;
			$this->_columns[$table_name][$columns['column_name']] = [
				'column_name'		=> $columns['column_name'],
				'type'				=> $columns['data_type'],
				'not_null'			=> filter_var($columns['is_nullable'], FILTER_VALIDATE_BOOLEAN),
				'default'			=> $columns['column_default'],
				'auto_increment'	=> $auto_increment,
				'primary_key'		=> $auto_increment ?: ($pkey_column_name === $columns['column_name']),
				'comment'			=> isset($comments[$columns['column_name']]) ? $comments[$columns['column_name']] : '',
				'raw_data'			=> $columns,
				'pdo_param'			=> $pdo_param_list[explode('(', $columns['data_type'])[0]],
			];
		}
	}