Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

DatabaseMetaData#getColumns returns wrong label #837

Closed
onacit opened this issue Feb 4, 2023 · 5 comments
Closed

DatabaseMetaData#getColumns returns wrong label #837

onacit opened this issue Feb 4, 2023 · 5 comments
Labels
bug Something isn't working released Issue has been released

Comments

@onacit
Copy link

onacit commented Feb 4, 2023

Describe the bug

DatabaseMetaData#getColumns't result contains SCOPE_CATLOG, not SCOPE_CATALOG.

https://docs.oracle.com/en/java/javase/17/docs/api//java.sql/java/sql/DatabaseMetaData.html#getColumns(java.lang.String,java.lang.String,java.lang.String,java.lang.String)

To Reproduce

        try (var connection = DriverManager.getConnection("jdbc:sqlite::memory:")) {
            final var meta = connection.getMetaData();
            log.debug("driverName: {}", meta.getDriverName());
            log.debug("driverVersion: {}", meta.getDriverVersion());
            log.debug("driverMajorVersion: {}", meta.getDriverMajorVersion());
            log.debug("driverMinorVersion: {}", meta.getDriverMinorVersion());
            log.debug("databaseProductName: {}", meta.getDatabaseProductName());
            log.debug("databaseProductVersion: {}", meta.getDatabaseProductVersion());
            log.debug("databaseMajorVersion: {}", meta.getDatabaseMajorVersion());
            log.debug("databaseMinorVersion: {}", meta.getDatabaseMinorVersion());
            try (ResultSet results = meta.getColumns("", "", "%", "%")) {
                final var labels = new HashSet<>();
                final var rsmd = results.getMetaData();
                for (int i = 1; i <= rsmd.getColumnCount(); i++) {
                    labels.add(rsmd.getColumnLabel(i));
                }
                labels.forEach(l -> {
                    log.debug("label: {}", l);
                });
            }
        }

Expected behavior
The SCOPE_CATLOG should be SCOPE_CATALOG.

Logs

1063 [main] DEBUG com.github.jinahya.database.metadata.bind.MemorySqliteTest - driverName: SQLite JDBC
1065 [main] DEBUG com.github.jinahya.database.metadata.bind.MemorySqliteTest - driverVersion: 3.40.1.0
1065 [main] DEBUG com.github.jinahya.database.metadata.bind.MemorySqliteTest - driverMajorVersion: 3
1065 [main] DEBUG com.github.jinahya.database.metadata.bind.MemorySqliteTest - driverMinorVersion: 40
1065 [main] DEBUG com.github.jinahya.database.metadata.bind.MemorySqliteTest - databaseProductName: SQLite
1065 [main] DEBUG com.github.jinahya.database.metadata.bind.MemorySqliteTest - databaseProductVersion: 3.40.1
1065 [main] DEBUG com.github.jinahya.database.metadata.bind.MemorySqliteTest - databaseMajorVersion: 3
1065 [main] DEBUG com.github.jinahya.database.metadata.bind.MemorySqliteTest - databaseMinorVersion: 40
1073 [main] DEBUG com.github.jinahya.database.metadata.bind.MemorySqliteTest - label: SCOPE_TABLE
1073 [main] DEBUG com.github.jinahya.database.metadata.bind.MemorySqliteTest - label: TABLE_CAT
1073 [main] DEBUG com.github.jinahya.database.metadata.bind.MemorySqliteTest - label: BUFFER_LENGTH
1073 [main] DEBUG com.github.jinahya.database.metadata.bind.MemorySqliteTest - label: IS_NULLABLE
1073 [main] DEBUG com.github.jinahya.database.metadata.bind.MemorySqliteTest - label: TABLE_NAME
1073 [main] DEBUG com.github.jinahya.database.metadata.bind.MemorySqliteTest - label: COLUMN_DEF
1073 [main] DEBUG com.github.jinahya.database.metadata.bind.MemorySqliteTest - label: TABLE_SCHEM
1073 [main] DEBUG com.github.jinahya.database.metadata.bind.MemorySqliteTest - label: COLUMN_NAME
1073 [main] DEBUG com.github.jinahya.database.metadata.bind.MemorySqliteTest - label: SCOPE_CATLOG <<<<<<<<<<<<<<<
1073 [main] DEBUG com.github.jinahya.database.metadata.bind.MemorySqliteTest - label: NULLABLE
1073 [main] DEBUG com.github.jinahya.database.metadata.bind.MemorySqliteTest - label: REMARKS
1073 [main] DEBUG com.github.jinahya.database.metadata.bind.MemorySqliteTest - label: DECIMAL_DIGITS
1073 [main] DEBUG com.github.jinahya.database.metadata.bind.MemorySqliteTest - label: NUM_PREC_RADIX
1073 [main] DEBUG com.github.jinahya.database.metadata.bind.MemorySqliteTest - label: SQL_DATETIME_SUB
1073 [main] DEBUG com.github.jinahya.database.metadata.bind.MemorySqliteTest - label: IS_GENERATEDCOLUMN
1073 [main] DEBUG com.github.jinahya.database.metadata.bind.MemorySqliteTest - label: IS_AUTOINCREMENT
1073 [main] DEBUG com.github.jinahya.database.metadata.bind.MemorySqliteTest - label: SQL_DATA_TYPE
1073 [main] DEBUG com.github.jinahya.database.metadata.bind.MemorySqliteTest - label: CHAR_OCTET_LENGTH
1073 [main] DEBUG com.github.jinahya.database.metadata.bind.MemorySqliteTest - label: ORDINAL_POSITION
1073 [main] DEBUG com.github.jinahya.database.metadata.bind.MemorySqliteTest - label: SCOPE_SCHEMA
1073 [main] DEBUG com.github.jinahya.database.metadata.bind.MemorySqliteTest - label: SOURCE_DATA_TYPE
1073 [main] DEBUG com.github.jinahya.database.metadata.bind.MemorySqliteTest - label: DATA_TYPE
1073 [main] DEBUG com.github.jinahya.database.metadata.bind.MemorySqliteTest - label: TYPE_NAME
1073 [main] DEBUG com.github.jinahya.database.metadata.bind.MemorySqliteTest - label: COLUMN_SIZE

Environment (please complete the following information):

Running `/Users/onacit/gitcl/github.com/jinahya/database-metadata-bind/mvnw`...
Apache Maven 3.8.7 (b89d5959fcde851dcb1c8946a785a163f14e1e29)
Maven home: /Users/onacit/.m2/wrapper/dists/apache-maven-3.8.7-bin/1ktonn2lleg549uah6ngl1r74r/apache-maven-3.8.7
Java version: 17.0.6, vendor: Eclipse Adoptium, runtime: /Library/Java/JavaVirtualMachines/temurin-17.jdk/Contents/Home
Default locale: en_KR, platform encoding: UTF-8
OS name: "mac os x", version: "13.1", arch: "aarch64", family: "mac"

Additional context
Thank you. I love you.

@onacit onacit added the triage label Feb 4, 2023
@onacit
Copy link
Author

onacit commented Feb 4, 2023

Even if the SCOPE_CATLOG is a SQLite-related custom/valid column, the driver should add a, (even null-valued), column named SCOPE_CATALOG, IMHO.
Thanks.

@onacit onacit changed the title DatabaseMetaData#getColumns returns wrong label name DatabaseMetaData#getColumns returns wrong label Feb 4, 2023
@gotson
Copy link
Collaborator

gotson commented Feb 6, 2023

I found this in the code:

// should be SCOPE_CATALOG, but misspelt in the standard
assertThat(rsmeta.getColumnName(19)).isEqualTo("SCOPE_CATLOG");

@gotson
Copy link
Collaborator

gotson commented Feb 6, 2023

Seems like pgjdbc had the same issue, so the spec must have been misspelt at some point: /~https://github.com/pgjdbc/pgjdbc/pull/1323/files

I found this H2 commit with some explanations too:

For compatibility with the specification, this column is now also named SCOPE_CATLOG in H2. A new column named SCOPE_CATALOG is appended as column 24. Please note that MySQL only supports SCOPE_CATALOG, while other databases only support SCOPE_CATLOG.

@gotson
Copy link
Collaborator

gotson commented Feb 6, 2023

Also found this on MySQL, and the last comment:

What I heard back from the JDBC expert group is it's a bug in the specification itself. Drivers should return SCOPE_CATALOG, not SCOPE_CATLOG (and most seem to).

@gotson gotson closed this as completed in 4429515 Feb 6, 2023
@gotson gotson added bug Something isn't working and removed triage labels Feb 6, 2023
@github-actions
Copy link
Contributor

🎉 This issue has been resolved in 3.41.0.0 (Release Notes)

@github-actions github-actions bot added the released Issue has been released label Feb 23, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working released Issue has been released
Projects
None yet
Development

No branches or pull requests

2 participants