zgq7 opened a new issue #14224:
URL: https://github.com/apache/shardingsphere/issues/14224


   my project dependency version:
   - springboot 2.1.7
   - shardingsphere-jdbc-core-spring-boot-starter 5.0.0
   - mybatis-plus 3.2.0
   -  mysql 5.1.27
   - mysql-connector 8.0.17
   
   ***
   i customed xml sql like :
   ```xml
       <select id="getTableNames" resultType="java.lang.String">
           SHOW TABLES LIKE #{likeStr}
       </select>
   ```
   it‘s worked like : 
   ```sql
   SHOW TABLES LIKE 't_order_%' ;
   ```
   when i haven't add sharding-jdbc in my project it worked normally。
   
   but it occured error when I use it after i add sharding-jdbc in my project :
   
   ```text
   Caused by: 
org.apache.shardingsphere.sql.parser.exception.SQLParsingException: You have an 
error in your SQL syntax
        at 
org.apache.shardingsphere.sql.parser.core.database.parser.SQLParserExecutor.twoPhaseParse(SQLParserExecutor.java:68)
        at 
org.apache.shardingsphere.sql.parser.core.database.parser.SQLParserExecutor.parse(SQLParserExecutor.java:49)
        at 
org.apache.shardingsphere.sql.parser.api.SQLParserEngine.parse(SQLParserEngine.java:51)
        at 
org.apache.shardingsphere.infra.parser.sql.SQLStatementParserExecutor.parse(SQLStatementParserExecutor.java:47)
        at 
org.apache.shardingsphere.infra.parser.cache.SQLStatementCacheLoader.load(SQLStatementCacheLoader.java:40)
        at 
org.apache.shardingsphere.infra.parser.cache.SQLStatementCacheLoader.load(SQLStatementCacheLoader.java:29)
        at 
com.google.common.cache.LocalCache$LoadingValueReference.loadFuture(LocalCache.java:3529)
        at 
com.google.common.cache.LocalCache$Segment.loadSync(LocalCache.java:2278)
        at 
com.google.common.cache.LocalCache$Segment.lockedGetOrLoad(LocalCache.java:2155)
        at com.google.common.cache.LocalCache$Segment.get(LocalCache.java:2045)
        ... 89 more
   ```
   
   you can reproduce this case like this :
   ```java
       @Test
       public void build() {
           SQLParserExecutor sqlParserExecutor = new SQLParserExecutor("MySQL", 
false);
           try {
               sqlParserExecutor.parse("show tables like ? ");
               log.info("sharding jdbc sql 编译成功");
           } catch (Exception e) {
               log.error("sharding jdbc sql 编译报错:", e);
           }
       }
   ```
   it will occured a error 
   
   ```text
   16:05:17.004 [main] ERROR - sharding jdbc sql 编译报错:
   org.apache.shardingsphere.sql.parser.exception.SQLParsingException: You have 
an error in your SQL syntax
        at 
org.apache.shardingsphere.sql.parser.core.database.parser.SQLParserExecutor.twoPhaseParse(SQLParserExecutor.java:68)
        at 
org.apache.shardingsphere.sql.parser.core.database.parser.SQLParserExecutor.parse(SQLParserExecutor.java:49)
   ```
   
   how to avoid this :
   ```java
       @Test
       public void build() {
           SQLParserExecutor sqlParserExecutor = new SQLParserExecutor("MySQL", 
false);
           try {
               sqlParserExecutor.parse("show tables like 'table_name' ");
               log.info("sharding jdbc sql 编译成功");
           } catch (Exception e) {
               log.error("sharding jdbc sql 编译报错:", e);
           }
       }
   ```
   
   so my mybatis xml code changed like this 👍 
    ```xml
       <select id="getTableNames" resultType="java.lang.String">
           SHOW TABLES LIKE ${likeStr}
       </select>
   ```
   so that the prama value will be like "'t_xxx'" 。
   
   ***
   my expected 
   
   - [ ] :when sharding-jdbc parse the sql which is 'show tables' can use # 
rather than $ in mybatis xml 。
   
   thanks !  :bug::bug::bug::bug::bug::bug:
   
   @terrymanu 
   
   
   
   
   
   


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]


Reply via email to