get name of the sequence that a serial or bigserial column uses
@param Connection $connection
@param string $tableName

@return string
430824
protected function getSequenceName(Connection $connection, $tableName)
    {
        $PkColumns = $connection->query("SELECT a.attname, format_type(a.atttypid, a.atttypmod) AS data_type
            FROM   pg_index i
            JOIN   pg_attribute a ON a.attrelid = i.indrelid
                                 AND a.attnum = ANY(i.indkey)
            WHERE  i.indrelid = :table_name::regclass
            AND    i.indisprimary;", [':table_name' => $tableName])->fetchAll(\PDO::FETCH_ASSOC);
        $PkColumnsCount = count($PkColumns);
        if ($PkColumnsCount != 1) {
            return null;
        }

        return $connection->query('select pg_get_serial_sequence(:table_name, :column_name)', [':table_name' => $tableName, ':column_name' => $PkColumns[0]['attname']])->fetchScalar();
    }
1289905
private function getTableNameByClassName($tableName): string
    {
        // 不是实体类名
        if (strpos($tableName, '\\') === false) {
            return $tableName;
        }

        $entities = EntityCollector::getCollector();
        if (!isset($entities[$tableName]['table']['name'])) {
            throw new DbException('Class is not an entity，className=' . $tableName);
        }
        // 选择数据库
        $this->selectInstance($entities[$tableName]['instance']);

        return $entities[$tableName]['table']['name'];
    }
1127845
public function getTable($tableName)
    {
        if (is_array($tableName)) {
            list($tableName, $entitySuffix) = $tableName;
        } else {
            $entitySuffix = null;
        }

        if ($entitySuffix !== null) {
            $tableName .= '_' . $entitySuffix;
        }

        if (!isset($this->_tables[$tableName])) {
            $this->_tables[$tableName] = $this->_resources->getTableName(
                $tableName,
                ResourceConnection::DEFAULT_CONNECTION
            );
        }

        return $this->_tables[$tableName];
    }
842623
public function getLastInsertID($table)
	{
		$this->ensureTable($table);
		if($table->sequenceName!==null)
			return $this->_connection->getLastInsertID($table->sequenceName);
		else
			return null;
	}
148029
public function nextSequenceId($sequenceName)
    {
        $this->_connect();
        $sql = 'SELECT NEXTVAL FOR '.$this->quoteIdentifier($sequenceName, true).' AS VAL FROM SYSIBM.SYSDUMMY1';
        $value = $this->fetchOne($sql);
        return (string) $value;
    }
215722
public function getSequenceName($table, $column)
    {
        if (($table === 'ezcontentobject_attribute') && ($column === 'id')) {
            return "{$table}.{$column}";
        }

        if (($table === 'ezcontentclass') && ($column === 'id')) {
            return "{$table}.{$column}";
        }

        if (($table === 'ezcontentclass_attribute') && ($column === 'id')) {
            return "{$table}.{$column}";
        }

        return null;
    }
81574
private function readSeeded(Connection $connection): array
    {
        $builder = $connection->createQueryBuilder();
        $seeded  = [];

        if ($connection->getSchemaManager()->tablesExist([$this->getSeedsTable()]) === true) {
            $seeds = $builder
                ->select(static::SEEDS_COLUMN_ID, static::SEEDS_COLUMN_CLASS)
                ->from($this->getSeedsTable())
                ->orderBy(static::SEEDS_COLUMN_ID)
                ->execute()
                ->fetchAll();
            foreach ($seeds as $seed) {
                $index          = $seed[static::SEEDS_COLUMN_ID];
                $class          = $seed[static::SEEDS_COLUMN_CLASS];
                $seeded[$index] = $class;
            }
        }

        return $seeded;
    }
1347061
public function getFieldsType($tableName = '', $field = null)
    {
        if ('' == $tableName) {
            $tableName = isset($this->options['table']) ? $this->options['table'] : $this->getTable();
        }

        return $this->connection->getFieldsType($tableName, $field);
    }
697203
public static function tablesExist(Connection $connection, $tables)
    {
        $result = false;
        if (!empty($tables)) {
            try {
                $connection->connect();
                $result = $connection->getSchemaManager()->tablesExist($tables);
            } catch (\PDOException $e) {
            } catch (DBALException $e) {
            }
        }

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

        return $this->connection->getTableFields($tableName);
    }
533701
function getSequence( $table ) {

        if ( isset( $this->sequences[ $table ] ) ) {

            return $this->sequences[ $table ];

        }

        $primary = $this->getPrimary( $table );

        if ( is_array( $primary ) ) return null;

        $table = $this->rewriteTable( $table );

        return $table . '_' . $primary . '_seq';

    }
108364
public function getTableSchemaId(string $tableName): string
    {
        $sql = sprintf('SHOW FULL COLUMNS FROM %s;', $this->quoter->quoteName($tableName));
        $rows = $this->db->query($sql)->fetchAll(PDO::FETCH_ASSOC);

        return sha1(json_encode($rows));
    }
828950
public function getColumns($table, $connection = null)
    {
        $this->updateConnection($connection)->setUpDoctrineSchema();

        $schema  = $this->getSchemaBuilder();
        $columns = $schema->getColumnListing($table);

        $columnData = [];

        foreach ($columns as $name) {

            $column = $schema->getConnection()->getDoctrineColumn($table, $name);

            $columnData[] = [
                'name'     => $column->getName(),
                'type'     => $column->getType()->getName(),
                'length'   => $column->getLength(),
                'values'   => false,
                'unsigned' => $column->getUnsigned(),
                'nullable' => ! $column->getNotnull(),
            ];
        }

        return $columnData;
    }
576037
private function getDatabasePlatform(Connection $connection)
    {
        try {
            return $connection->getDatabasePlatform();
        } catch (DriverException $driverException) {
            throw new DBALException(
                'An exception occured while establishing a connection to figure out your platform version.' . PHP_EOL .
                "You can circumvent this by setting a 'server_version' configuration value" . PHP_EOL . PHP_EOL .
                'For further information have a look at:' . PHP_EOL .
                'https://github.com/doctrine/DoctrineBundle/issues/673',
                0,
                $driverException
            );
        }
    }
288862
protected function getTableIndexes($tableName = null, $connectionName = null)
    {
        $tableName = $this->validateTableName($tableName);

        return $this->getSchema($connectionName)->listTableIndexes($tableName);
    }
649429
protected static function checkTableName($tableName, $con=NULL)
    {
        $connection = self::checkConnection($con);

        $query = $connection->query("SELECT 1 FROM {$tableName} LIMIT 1");
        if($query !== false)
        {
            return $tableName;
        }
        throw new TableDoesNotExistException();
    }
1212305
protected function &retrieveColumnsMetadata($tableName)
    {
        /* @noinspection PhpUnhandledExceptionInspection */
        $result = $this->connection->query('SHOW COLUMNS FROM ' . $tableName);
        $result = $result->fetchAll();

        $fields       = [];
        $fieldTypes   = [];
        $fieldLengths = [];

        $cnt = count($result);
        for ($i = 0; $i < $cnt; $i++) {
            $fName                = &$result[$i]['Field'];
            $fType                = &$result[$i]['Type'];
            $fields[]             = &$fName;
            $fieldTypes[$fName]   = explode('(', $fType)[0];
            $fieldLengths[$fName] = $this->extractFieldTypeLength($fType);
        }

        $returnArray = [ // compact() ???
            'fields'       => &$fields,
            'fieldTypes'   => &$fieldTypes,
            'fieldLengths' => &$fieldLengths,
        ];

        return $returnArray;
    }