You are viewing a plain text version of this content. The canonical link for it is here.
Posted to issues@metamodel.apache.org by "RATISH BANSAL (Jira)" <ji...@apache.org> on 2019/12/15 10:32:00 UTC

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

    [ https://issues.apache.org/jira/browse/METAMODEL-1191?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=16996672#comment-16996672 ] 

RATISH BANSAL commented on METAMODEL-1191:
------------------------------------------

I think this issue is same as https://issues.apache.org/jira/browse/METAMODEL-156 , which was fixed in 5.2.1.
cc [~kaspersor]

> 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
(v8.3.4#803005)