Get column used as primary key.
@param string $tableName
@return string|string[]|null
763468
public function getTablePk($tableName) {
        $details = $this->getTableColumns($tableName);
        $pk = [];
        foreach ($details as $column) {
            if ($column['Key'] == 'PRI') {
                $pk[] =  $column['Field'];
            }
        }
        if (1 == count($pk)){
            return $pk[0];
        } elseif (count($pk)) {
            return $pk;
        }
        return null;
    }
843596
public function getIndices($tableName)
    {
        $result = [];

        if ($this->tableExists($tableName)) {
            $result = \OxidEsales\Eshop\Core\DatabaseProvider::getDb(\OxidEsales\Eshop\Core\DatabaseProvider::FETCH_MODE_ASSOC)->getAll("SHOW INDEX FROM $tableName");
        }

        return $result;
    }
467804
public static function tableForeignKeys($tableName)
    {
        $result = ['inner' => [], 'outer' => []];
        foreach (Yii::$app->db->schema->tableSchemas as $table) {
            $foreignKeys = static::findConstraints($table);
            /** @var TableSchema $table */
            if ($table->name == $tableName) {
                $result['inner'] = $foreignKeys;
                continue;
            }
            foreach ($foreignKeys as $foreignKey) {
                if ($foreignKey['ftable'] == $tableName) {
                    $result['outer'][] = $foreignKey;
                }
            }
        }
        return $result;
    }
691873
public function getColumns($tableName)
    {
        if (!isset($this->cache[$tableName])) {
            $columns = $this->entityManager->getConnection()->getSchemaManager()->listTableColumns($tableName);
            if ('leads' === $tableName) {
                if (!$this->extendedFieldAliases) {
                    // Hacked this query into here to avoid a recursive dependency in 2.15.0
                    $fq = $this->entityManager->getConnection()->createQueryBuilder();
                    $fq->select('f.alias')
                        ->from(MAUTIC_TABLE_PREFIX.'lead_fields', 'f')
                        ->where(
                            $fq->expr()->orX(
                                $fq->expr()->eq('f.object', $fq->expr()->literal('extendedField')),
                                $fq->expr()->eq('f.object', $fq->expr()->literal('extendedFieldSecure'))
                            )
                        );
                    foreach ($fq->execute()->fetchAll() as $result) {
                        $this->extendedFieldAliases[$result['alias']] = 'extendedField - This is never used as an actual column object';
                    }
                }
                if ($this->extendedFieldAliases) {
                    $columns = array_merge($columns, $this->extendedFieldAliases);
                }
            }
            $this->cache[$tableName] = $columns ?: [];
        }

        return $this->cache[$tableName];
    }
1279499
public function getForeignKeys($tableName)
    {
        $sql = sprintf("SELECT
                cols.TABLE_NAME,
                cols.COLUMN_NAME,
                cRefs.CONSTRAINT_NAME,
                refs.REFERENCED_TABLE_NAME,
                refs.REFERENCED_COLUMN_NAME,
                cRefs.UPDATE_RULE,
                cRefs.DELETE_RULE
            FROM INFORMATION_SCHEMA.COLUMNS AS cols
            LEFT JOIN INFORMATION_SCHEMA.KEY_COLUMN_USAGE AS refs
                ON refs.TABLE_SCHEMA=cols.TABLE_SCHEMA
                AND refs.REFERENCED_TABLE_SCHEMA=cols.TABLE_SCHEMA
                AND refs.TABLE_NAME=cols.TABLE_NAME
                AND refs.COLUMN_NAME=cols.COLUMN_NAME
            LEFT JOIN INFORMATION_SCHEMA.TABLE_CONSTRAINTS AS cons
                ON cons.TABLE_SCHEMA=cols.TABLE_SCHEMA
                AND cons.TABLE_NAME=cols.TABLE_NAME
                AND cons.CONSTRAINT_NAME=refs.CONSTRAINT_NAME
            LEFT JOIN INFORMATION_SCHEMA.REFERENTIAL_CONSTRAINTS AS cRefs
                ON cRefs.CONSTRAINT_SCHEMA=cols.TABLE_SCHEMA
                AND cRefs.CONSTRAINT_NAME=refs.CONSTRAINT_NAME
            WHERE
                cols.TABLE_NAME = %s
                AND cols.TABLE_SCHEMA = DATABASE()
                AND refs.REFERENCED_TABLE_NAME IS NOT NULL
                AND cons.CONSTRAINT_TYPE = 'FOREIGN KEY'
            ;", $this->quote($tableName));
        $stm = $this->pdo->query($sql);
        $rows = $stm->fetchAll();
        if (empty($rows)) {
            return null;
        }

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

        return $result;
    }
191045
public function getPrimaryKey($tableName)
    {
        $parts = $this->getSchemaName($tableName);
        $rows = $this->fetchAll(sprintf(
            "SELECT
                    tc.constraint_name,
                    kcu.column_name
                FROM information_schema.table_constraints AS tc
                JOIN information_schema.key_column_usage AS kcu
                    ON tc.constraint_name = kcu.constraint_name
                WHERE constraint_type = 'PRIMARY KEY'
                    AND tc.table_schema = %s
                    AND tc.table_name = %s
                ORDER BY kcu.position_in_unique_constraint",
            $this->getConnection()->quote($parts['schema']),
            $this->getConnection()->quote($parts['table'])
        ));

        $primaryKey = [
            'columns' => [],
        ];
        foreach ($rows as $row) {
            $primaryKey['constraint'] = $row['constraint_name'];
            $primaryKey['columns'][] = $row['column_name'];
        }

        return $primaryKey;
    }
30242
public function getTableKeys($tableName) {
		
		$keys = array();
		
		$fields = $this->describeTable($tableName);
		
		foreach ($fields as $field) {
			if ('PRI' == $field->Key) {
				$keys[] = $field->Field;
			}
		}
		
		return $keys;
		
	}
480365
public function cuGetColNamesFromTable($tableName)
    {

        $sql        = 'DESCRIBE ' . $tableName;
        $result     = $this->query($sql);
        $field_name = [];
        $data_array = [];
        while ($data = $result->fetch_assoc()) {
            $data_array[] = $data;
        }

        foreach ($data_array as $val) {
            $field_name[] = $val['Field'];
        }

        return $field_name;
    }
246547
private function retrieveColumnsCachedMetadata($tableName)
    {
        $key = $this->cachePrefix . '.' . $tableName . '.meta';

        /* @noinspection PhpUnhandledExceptionInspection */
        return Cache::remember($key, function () use ($tableName) {
            return $this->retrieveColumnsMetadata($tableName);
        });
    }
1144360
public function getForeignKeysReferencingTable($tableName)
    {
        $matches = [];
        foreach ($this->foreignKeys as $fk) {
            if ($fk->getForeignTableName() === $tableName) {
                $matches[] = $fk;
            }
        }

        return $matches;
    }
1130681
public function getColumn($columnName)
    {
        return isset($this->_columns[$columnName]) ? $this->_columns[$columnName] : null;
    }
807990
public function primaryKey ($tableName)
		{
			if (! isset($this->primaryKeys[$tableName])) {
				$sql = "SELECT *
					    FROM INFORMATION_SCHEMA.TABLE_CONSTRAINTS tc
					        JOIN INFORMATION_SCHEMA.CONSTRAINT_COLUMN_USAGE ccu ON tc.CONSTRAINT_NAME = ccu.Constraint_name
					    WHERE tc.CONSTRAINT_TYPE = 'Primary Key'
					        AND tc.TABLE_NAME = " . $this->quote($tableName);

				$keyResult                      = $this->query($sql);
				$key                            = $keyResult->fetchRow();
				$this->primaryKeys[$tableName]  = $key['COLUMN_NAME'];
			}

			return $this->primaryKeys[$tableName];
		}
639987
public function getTableFields($tableName = '')
    {
        if ('' == $tableName) {
            $tableName = isset($this->options['table']) ? $this->options['table'] : $this->getTable();
        }

        return $this->connection->getTableFields($tableName);
    }
104910
protected function getIndexes($tableName)
    {
        $parts = $this->getSchemaName($tableName);

        $indexes = [];
        $sql = sprintf(
            "SELECT
                i.relname AS index_name,
                a.attname AS column_name
            FROM
                pg_class t,
                pg_class i,
                pg_index ix,
                pg_attribute a,
                pg_namespace nsp
            WHERE
                t.oid = ix.indrelid
                AND i.oid = ix.indexrelid
                AND a.attrelid = t.oid
                AND a.attnum = ANY(ix.indkey)
                AND t.relnamespace = nsp.oid
                AND nsp.nspname = %s
                AND t.relkind = 'r'
                AND t.relname = %s
            ORDER BY
                t.relname,
                i.relname",
            $this->getConnection()->quote($parts['schema']),
            $this->getConnection()->quote($parts['table'])
        );
        $rows = $this->fetchAll($sql);
        foreach ($rows as $row) {
            if (!isset($indexes[$row['index_name']])) {
                $indexes[$row['index_name']] = ['columns' => []];
            }
            $indexes[$row['index_name']]['columns'][] = $row['column_name'];
        }

        return $indexes;
    }
456859
public function getIndexByName($indexName, $tableName)
    {
        $indices = $this->getIndices($tableName);

        $result = null;

        foreach ($indices as $index) {
            if ($indexName === $index['Column_name']) {
                $result = $index;
            }
        }

        return $result;
    }
733364
public function getPrimaryKeyColumns()
    {
        $primaryKey = $this->getPrimaryKey();

        if ($primaryKey === null) {
            throw new DBALException('Table ' . $this->getName() . ' has no primary key.');
        }

        return $primaryKey->getColumns();
    }
303713
public function get($tableName)
    {
        $capsules = $this->all();

        foreach ($capsules as $capsule) {
            if ($capsule->tableName == $tableName) {
                return $capsule;
            }
        }

        return null;
    }