You are viewing a plain text version of this content. The canonical link for it is here.
Posted to issues@metamodel.apache.org by "Hao Ling (JIRA)" <ji...@apache.org> on 2018/09/06 01:46:00 UTC

[jira] [Updated] (METAMODEL-1191) JdbcDataContext get wrong schema name on MySQL

     [ https://issues.apache.org/jira/browse/METAMODEL-1191?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel ]

Hao Ling updated METAMODEL-1191:
--------------------------------
    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:

 
{code:java}
for (int i = 0; i < schemaNames.size() && !found; i++) {
    String schemaName = schemaNames.get(i);
    if (lastToken.indexOf(schemaName) != -1) {
        result = schemaName;
        found = true;
    }
}
{code}
 

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.

 
{code:java}
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;
    }
}
{code}
 

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:
{code:java}
if (lastToken.startWith(schemaName)) 
{code}
 

 

 

 

 

  was:
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:

 
{code:java}
for (int i = 0; i < schemaNames.size() && !found; i++) {
    String schemaName = schemaNames.get(i);
    if (lastToken.indexOf(schemaName) != -1) {
        result = schemaName;
        found = true;
    }
}
{code}
 

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.

 
{code:java}
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;
    }
}
{code}
 

Consider the schema name may exists in the right part of ? character, so we think it's better to use startWith() instead of indexOf(). Like this:
{code:java}
if (lastToken.startWith(schemaName)) 
{code}
 

 

 

 

 


> JdbcDataContext get wrong schema name on MySQL
> ----------------------------------------------
>
>                 Key: METAMODEL-1191
>                 URL: https://issues.apache.org/jira/browse/METAMODEL-1191
>             Project: Apache MetaModel
>          Issue Type: Bug
>    Affects Versions: 5.0.0
>         Environment: MySQL 8.0
>            Reporter: Hao Ling
>            Priority: Major
>              Labels: jdbc
>
> 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:
>  
> {code:java}
> for (int i = 0; i < schemaNames.size() && !found; i++) {
>     String schemaName = schemaNames.get(i);
>     if (lastToken.indexOf(schemaName) != -1) {
>         result = schemaName;
>         found = true;
>     }
> }
> {code}
>  
> 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.
>  
> {code:java}
> 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;
>     }
> }
> {code}
>  
> 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:
> {code:java}
> if (lastToken.startWith(schemaName)) 
> {code}
>  
>  
>  
>  
>  



--
This message was sent by Atlassian JIRA
(v7.6.3#76005)