Bug #116113 DatabaseMetaData#getTables doesn't work properly for delimited identifiers
Submitted: 15 Sep 17:45 Modified: 16 Sep 9:20
Reporter: Ashhar Hasan Email Updates:
Status: Verified Impact on me:
None 
Category:Connector / J Severity:S3 (Non-critical)
Version:9.0 OS:Any
Assigned to: CPU Architecture:Any

[15 Sep 17:45] Ashhar Hasan
Description:
DatabaseMetaData#getTables doesn't work if the tableNamePattern is a value like "`back``quoted`" and a table exists on the server with that name.

I've attached a java class to reproduce this issue. Trying with or without the `pedantic` connection property leads to same result.

How to repeat:
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;
import java.util.Properties;

class Scratch
{
    public static void main(String[] args)
    {
        Properties properties = new Properties();
        properties.put("user", "test");
        properties.put("password", "test");
        properties.put("pedantic", "true");
        try (Connection connection = DriverManager.getConnection("jdbc:mysql://localhost:33018/tpch", properties)) {
            try (Statement stmt = connection.createStatement()) {
                stmt.execute("CREATE TABLE IF NOT EXISTS ```back````quoted``` (```back````quoted``` bigint)");
            }
            try (ResultSet rs = connection.getMetaData().getTables(
                    "tpch",
                    null,
                    "`back``quoted`",
                    null)) {
                while (rs.next()) {
                    System.out.println("table");
                    System.out.println(rs.getString("TABLE_NAME"));
                }
            }
            try (ResultSet rs = connection.getMetaData().getColumns(
                    "tpch",
                    null,
                    "`back``quoted`",
                    null)) {
                while (rs.next()) {
                    System.out.println("column");
                    System.out.println(rs.getString("COLUMN_NAME"));
                }
            }
        }
        catch (SQLException e) {
            throw new RuntimeException(e);
        }
    }
}
[16 Sep 9:20] MySQL Verification Team
Hello Ashhar Hasan,

Thank you for the report and feedback.

regards,
Umesh
[19 Sep 16:34] Axyoan Marcelo
Posted by developer:
 
Hello Ashhar,

The tableNamePattern argument you are passing to getTables should be ```back````quoted```. The server treats `tableName`, the same as tablename, so we need a way to make them equivalent, meaning that Connector/J has to first unquote the tableName. There actually exists bug here, it lies in getColumns, as it is not unquoting the tableNamePattern given.
Thank you for your report.