database-rider / database-rider

Database testing made easy!

Home Page:https://database-rider.github.io/database-rider

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

[MySQL] Schema resolver always returns null

coiouhkc opened this issue · comments

See

For MySQL apparently the schema name resides in column TABLE_CAT.

To test on your local MySQL with multi-schema layout, please use following code:

try (Connection connection = dataSource.getConnection()) {
            System.out.println("Catalogs:");
            ResultSet rsCatalogs = connection.getMetaData().getCatalogs();
            int rsCatalogsColumnCount = rsCatalogs.getMetaData().getColumnCount();
            while (rsCatalogs.next()) {
                for (int i = 1; i <= rsCatalogsColumnCount; i++) {
                    System.out.print(rsCatalogs.getString(i) + "\t");
                }
                System.out.println();
            }

            System.out.println("-------");

            System.out.println("Schemas:");
            ResultSet rsSchemas = connection.getMetaData().getSchemas();
            int rsSchemasColumnCount = rsCatalogs.getMetaData().getColumnCount();
            while (rsSchemas.next()) {
                for (int i = 1; i <= rsSchemasColumnCount; i++) {
                    System.out.print(rsSchemas.getString(i) + "\t");
                }
                System.out.println();
            }
        } catch (SQLException e) {
            throw new RuntimeException(e);
        }

Suggested fix: make TableNameResolver aware of the db-type, quickfix could be to return [<catalog>.][<schema>.]<tablename> if either <catalog> or <schema> are null.

@rmpestano - do you want me to submit the quickfix as PR?

Hey @coiouhkc, that would be awesome, I think we can go for your first suggestion. Thank you!

This fix is available in v1.35.0. thank you @coiouhkc!