Details
-
Bug
-
Status: Open
-
Major
-
Resolution: Unresolved
-
5.0.0
-
None
-
MySQL 8.0
Description
A MySQL database has multiple schemas: "dc", "rdc", "rdc_test" ...
The jdbc connection url is jdbc:mysql://192.168.1.199:3306/rdc_test?useUnicode=true...
When use JdbcDataContext.getDefaultSchemaName() to obtain the default schema,
we expected this function to return "rdc_test",which is the part of connection url, but it returns "dc".
After debug, we found the issue is caused by following code:
JdbcDataContext.java Line 672:
for (int i = 0; i < schemaNames.size() && !found; i++) { String schemaName = schemaNames.get(i); if (lastToken.indexOf(schemaName) != -1) { result = schemaName; found = true; } }
Here the lastToken is "rdc_test?useUnicode=....." which is extracted from url, it's correct. When use indexOf() to match schemaNames array, the first schema "dc" is matched and returned.
The most simplest solution I think is to get the longest schema which is a part of lastToken. Below is the fixed code. We tested it and works fine.
for (int i = 0; i < schemaNames.size(); i++) { String schemaName = schemaNames.get(i); if (lastToken.indexOf(schemaName) != -1) { if (result == null) { result = schemaName; } else { result = schemaName.length() > result.length() ? schemaName : result; } found = true; } }
Consider the same string with schema name may also appears in the right part of '?' character, is it better to use startWith() instead of indexOf()? Like this:
if (lastToken.startWith(schemaName))
Attachments
Issue Links
- links to