override fun existingPrimaryKeys()

in exposed-jdbc/src/main/kotlin/org/jetbrains/exposed/v1/jdbc/statements/jdbc/JdbcDatabaseMetadataImpl.kt [325:342]


    override fun existingPrimaryKeys(vararg tables: Table): Map<Table, PrimaryKeyMetadata?> {
        val isSqlite = currentDialect is SQLiteDialect
        return tables.associateWith { table ->
            val (catalog, tableSchema) = tableCatalogAndSchema(table)
            metadata.getPrimaryKeys(catalog, tableSchema, table.nameInDatabaseCaseUnquoted()).let { rs ->
                val columnNames = mutableListOf<String>()
                var pkName = ""
                while (rs.next()) {
                    rs.getString("PK_NAME")?.let { pkName = it }
                    columnNames += rs.getString("COLUMN_NAME")
                }
                rs.close()
                // SQLite is the only supported database that does not assign a name to an unnamed primary key constraint.
                // So it is possible for the result set to have rows with primary key columns etc., but empty PK_NAME field
                if (pkName.isEmpty() && (!isSqlite || columnNames.isEmpty())) null else PrimaryKeyMetadata(pkName, columnNames)
            }
        }
    }