Retrieves field information about the given table

@param   string   $table     The name of the database table.
@param   boolean  $typeOnly  True to only return field types.
@return  array    An array of fields for the database table.
@since   2.2.15
6164
public function getTableColumns($table, $typeOnly = true)
	{
		$columns = 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 . ')');
		$fields = $this->loadObjectList();

		if ($typeOnly)
		{
			foreach ($fields as $field)
			{
				$columns[$field->NAME] = $field->TYPE;
			}
		}
		else
		{
			foreach ($fields as $field)
			{
				// Normalize output
				$columns[$field->NAME] = (object) array(
					'Field'   => $field->NAME,
					'Type'    => $field->TYPE,
					'Null'    => ($field->NOTNULL == '1' ? 'NO' : 'YES'),
					'Default' => $field->DFLT_VALUE,
					'Key'     => ($field->PK != '0' ? 'PRI' : '')
				);
			}
		}

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

		return $columns;
	}
730606
private function get_columns( $table ) {
		global $wpdb;

		$table_sql    = $this->esc_sql_ident( $table );
		$primary_keys = $text_columns = $all_columns = array();

		foreach ( $wpdb->get_results( "DESCRIBE $table_sql" ) as $col ) {
			if ( 'PRI' === $col->Key ) {
				$primary_keys[] = $col->Field;
			}

			if ( $this->is_text_col( $col->Type ) ) {
				$text_columns[] = $col->Field;
			}

			$all_columns[] = $col->Field;
		}

		return array( $primary_keys, $text_columns, $all_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;
    }
802333
function GetFieldInfo($table, $field)
    {
        $isUnique = false;
        $isPrimary = false;
        $isNullable = false;
        $defaultValue = null;
        $fullName = '';
        if (!$this->GetBasicFieldInfo($table, $field, $fullName, $defaultValue, $isPrimary, $isUnique, $isNullable))
        {
            return null;
        }
        $typeDef = TypeDef::ParseFullName($fullName);
        if (!$typeDef)
        {
            return null;
        }
        $keyName = $this->GetKeyName($table, $field);
        if (!$keyName)
        {
            return new FieldInfo($field, $typeDef, $defaultValue, $isNullable, null, null, null);
        }
        $keyInfo = new KeyInfo($keyName, $isPrimary, $isUnique);
        $constraintName = '';
        $refTable = '';
        $refField = '';
        if (!$this->GetForeignKey($table, $field, $constraintName, $refTable, $refField))
        {
            return new FieldInfo($field, $typeDef, $defaultValue, $isNullable, $keyInfo, null, null);
        }
        
        $onUpdate = null;
        $onDelete = null;
        $this->GetConstraintRules($constraintName, $onUpdate, $onDelete);
        $foreignKey = new ForeignKey($refTable, $refField);
        $constraint = new Constraint($constraintName, $onUpdate, $onDelete);
        return new FieldInfo($field, $typeDef, $defaultValue, $isNullable, $keyInfo, $foreignKey, $constraint);
    }
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];
    }
427366
public function describe($table = '')
    {
        $this->sql = $sql = "DESC $table;";
        $this->STH = $this->prepare($sql);
        $this->STH->execute();
        $colList = $this->STH->fetchAll();

        $field = [];
        $type = [];
        foreach ($colList as $key) {
            $field[] = $key['Field'];
            $type[] = $key['Type'];
        }

        return array_combine($field, $type);
    }
46295
public function field_data($table)
	{
		$sql = 'SELECT COLUMN_NAME, DATA_TYPE, CHARACTER_MAXIMUM_LENGTH, NUMERIC_PRECISION, COLUMN_DEFAULT
			FROM INFORMATION_SCHEMA.Columns
			WHERE UPPER(TABLE_NAME) = '.$this->escape(strtoupper($table));

		if (($query = $this->query($sql)) === FALSE)
		{
			return FALSE;
		}
		$query = $query->result_object();

		$retval = array();
		for ($i = 0, $c = count($query); $i < $c; $i++)
		{
			$retval[$i]			= new stdClass();
			$retval[$i]->name		= $query[$i]->COLUMN_NAME;
			$retval[$i]->type		= $query[$i]->DATA_TYPE;
			$retval[$i]->max_length		= ($query[$i]->CHARACTER_MAXIMUM_LENGTH > 0) ? $query[$i]->CHARACTER_MAXIMUM_LENGTH : $query[$i]->NUMERIC_PRECISION;
			$retval[$i]->default		= $query[$i]->COLUMN_DEFAULT;
		}

		return $retval;
	}
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 . ')';
    }
244884
public function getTableColumns(string $table): array
    {
        $schemaTable = self::SCHEMA_COLUMN;

        $where[] = "TABLE_NAME = '{$table}'";
        $where[] = "TABLE_SCHEMA = '{$this->db}'";
        $where   = !empty($where) ? ' WHERE ' . implode(' AND ', $where) : null;

        $querySql = "SELECT `COLUMN_NAME` as `name`,`DATA_TYPE` as `type`,`CHARACTER_MAXIMUM_LENGTH` as `length`,`COLUMN_DEFAULT` as `default` ,`COLUMN_KEY` as `key`,`IS_NULLABLE` as `nullable`,`COLUMN_TYPE` as `column_type`,`COLUMN_COMMENT` as `column_comment` FROM {$schemaTable} {$where}";
        $this->dbHandler->prepare($querySql);
        $this->dbHandler->execute([]);
        $columns = $this->dbHandler->fetch();

        return !empty($columns) ? $columns : [];
    }
976493
public function normalizeColumns($data, $typeOnly = true)
	{
		$results = [];

		// If we only want the type as the value add just that to the list
		if ($typeOnly)
		{
			foreach ($data as $field)
			{
				// @FIXME: should we try to normalize types too?
				$results[$field->name] = $field->type;
			}
		}
		// If we want the whole field data object add that to the list
		else
		{
			foreach ($data as $field)
			{
				$results[$field->name] =
				[
					'name'      => $field->name,
					'type'      => $field->type,
					'allownull' => $field->notnull ? false : true,
					'default'   => $field->dflt_value,
					'pk'        => $field->pk ? true : false
				];
			}
		}

		return $results;
	}
901087
public function getTableCols(string $table): array
    {
        $schema = $this->conn->getSchemaManager();
        $tableCols = $schema->listTableColumns($table);
        $cols = [];
        foreach ($tableCols as $col) {
            $cols[$col->getName()] = [
                'length' => $col->getLength(),
                'type' => $col->getType(),
                'unsigned' => $col->getUnsigned(),
            ];
        }

        return $cols;
    }
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();
    }
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 ];
    }
1319575
protected function _getUpdateFieldsForTable($table, $useSkipSaveFields = true)
    {
        $coreTable = $this->getCoreTableName();

        $skipMultilingual = false;
        $skipCoreFields = false;

        if ($table != $coreTable) {
            $skipCoreFields = true;
        }
        if ($this->_blEmployMultilanguage) {
            if ($table != getLangTableName($coreTable, $this->getLanguage())) {
                $skipMultilingual = true;
            }
        }

        $sql = '';
        $sep = false;
        foreach (array_keys($this->_aFieldNames) as $key) {
            $keyLowercase = strtolower($key);
            if ($keyLowercase != 'oxid') {
                if ($this->_blEmployMultilanguage) {
                    if ($skipMultilingual && $this->isMultilingualField($key)) {
                        continue;
                    }
                    if ($skipCoreFields && !$this->isMultilingualField($key)) {
                        continue;
                    }
                } else {
                    // need to explicitly check field language
                    $fieldLang = $this->_getFieldLang($key);
                    if ($fieldLang) {
                        if ($table != getLangTableName($coreTable, $fieldLang)) {
                            continue;
                        }
                    } elseif ($skipCoreFields) {
                        continue;
                    }
                }
            }

            if (!$this->checkFieldCanBeUpdated($key)) {
                continue;
            }

            $longName = $this->_getFieldLongName($key);
            $field = $this->$longName;

            if (!$useSkipSaveFields || ($useSkipSaveFields && !in_array($keyLowercase, $this->_aSkipSaveFields))) {
                $key = $this->getUpdateSqlFieldName($key);
                $sql .= (($sep) ? ',' : '') . $key . " = " . $this->_getUpdateFieldValue($key, $field);
                $sep = true;
            }
        }

        return $sql;
    }
384743
public function getColumns($table): ?array
	{
		return $this->driverQuery($this->getSql()->columnList($this->prefixTable($table)), FALSE);
	}
645317
public function getTableSchema($table)
    {
        $backup = [];
        //get the schema
        $schema = $this->getColumns($table);
        if (count($schema)) {
            //lets rebuild this schema
            $query = $this->getCreateQuery()->setName($table);

            foreach ($schema as $field) {
                //first try to parse what we can from each field
                $fieldTypeArray = explode(' ', $field['Type']);
                $typeArray = explode('(', $fieldTypeArray[0]);
                
                $type = $typeArray[0];
                
                $length = null;
                if (isset($typeArray[1])) {
                    $length = str_replace(')', '', $typeArray[1]);
                }
                
                $attribute = isset($fieldTypeArray[1]) ? $fieldTypeArray[1] : null;
                
                $null = strtolower($field['Null']) == 'no' ? false : true;
                
                $increment = strtolower($field['Extra']) == 'auto_increment' ? true : false;
                
                //lets now add a field to our schema class
                $query->addField($field['Field'], [
                    'type'              => $type,
                    'length'            => $length,
                    'attribute'         => $attribute,
                    'null'              => $null,
                    'default'           => $field['Default'],
                    'auto_increment'    => $increment
                ]);
                
                //set keys where found
                switch ($field['Key']) {
                    case 'PRI':
                        $query->addPrimaryKey($field['Field']);
                        break;
                    case 'UNI':
                        $query->addUniqueKey($field['Field'], [$field['Field']]);
                        break;
                    case 'MUL':
                        $query->addKey($field['Field'], [$field['Field']]);
                        break;
                }
            }
            
            //store the query but dont run it
            $backup[] = $query;
        }
        
        //get the rows
        $rows = $this->query($this->getSelectQuery()->from($table)->getQuery());
        
        if (count($rows)) {
            //lets build an insert query
            $query = $this->getInsertQuery($table);

            foreach ($rows as $index => $row) {
                foreach ($row as $key => $value) {
                    $query->set($key, $value, $index);
                }
            }
            
            //store the query but dont run it
            $backup[] = $query->getQuery(true);
        }
        
        return implode("\n\n", $backup);
    }
258041
public function getTableColumns($table, $typeOnly=true)
	{
		$columns = $this->query($this->syntax->getColumnsQuery($table), 'rows');

		return $this->syntax->normalizeColumns($columns, $typeOnly);
	}