Ensure scoped table retrieval for MySQL/MariaDB connections#1901
Merged
Conversation
Updated table retrieval logic to use `connection.catalog` when no specific catalog is provided. Added tests to verify tables are limited to the active database in MySQL, MariaDB, and MSSQL scenarios. Fixed connection URL constants in test files.
Jolanrensen
reviewed
Jun 16, 2026
| // tables from all MySQL/MariaDB databases when no specific catalog is given. | ||
| val effectiveCatalog = try { | ||
| connection.catalog.takeUnless { it.isNullOrBlank() } | ||
| } catch (_: Exception) { null } |
Collaborator
There was a problem hiding this comment.
if you're not interested in the exception, maybe you could try runCatching { ... }.getOrNull(). Just an alternative way to write it, but both are valid of course :)
Collaborator
Author
There was a problem hiding this comment.
Agree, it could be better for reading or handling
AndreiKingsley
approved these changes
Jun 17, 2026
…handling in JDBC table retrieval logic
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Closes #1746
Fix #1746: readAllSqlTables leaks tables from other databases on MySQL/MariaDB
1. Problem
readAllSqlTablesandDataFrameSchema.readAllSqlTablescalled without an explicitcatalogueincorrectly return tables from all accessible databases when connected to MySQL or MariaDB.
Root cause: both functions passed
nulldirectly toDatabaseMetaData.getTables(null, ...).On MySQL/MariaDB,
nullmeans all catalogs, so a connection scoped tojdbc:mysql://host/mydbwould enumerate tables from every database visible to that user.Subsequent
SELECT * FROM table_from_another_dbthen fails with "table doesn't exist"because the query runs in the wrong database context.
This is a MySQL/MariaDB-specific behavior: PostgreSQL and SQLite connections are inherently
single-database, so
getTables(null, ...)there already returns only the current DB.2. Solution
When
catalogueis not provided by the caller, fall back toconnection.catalog(standard JDBC API — returns the database name from the JDBC URL).
The same pattern is already used in
DbType.getTableColumnsMetadata.If the URL has no database (
jdbc:mysql://hostwithout/dbname),connection.catalogreturns
null/"", which falls through tonull— preserving the existing"all catalogs" behavior for that case.
Fixed in two places:
readJdbc.kt—DataFrame.readAllSqlTables(connection, ...)readDataFrameSchema.kt—DataFrameSchema.readAllSqlTables(connection, ...)(same bug, hardcodednull)3. Situation by Database
getTables(null,...)returns all databases;connection.catalog= DB from URLgetTablesalready scoped to current DBconnection.catalogreturnsnullconnection.catalogreturnsnullfor default in-memory catalogTests added (all
@Ignore, require local server) in:local/mysqlTest.ktlocal/mariadbTest.ktlocal/mssqlTest.ktEach test creates a second database with a unique table, connects to DB1 by URL,
calls
readAllSqlTableswithoutcatalogue, and asserts the second DB's table is absent.