You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@shardingsphere.apache.org by GitBox <gi...@apache.org> on 2020/10/29 04:54:39 UTC

[GitHub] [shardingsphere] strongduanmu commented on a change in pull request #7949: fix some sql parse exception and ddl, dcl route logic

strongduanmu commented on a change in pull request #7949:
URL: https://github.com/apache/shardingsphere/pull/7949#discussion_r513968592



##########
File path: shardingsphere-sql-parser/shardingsphere-sql-parser-engine/src/main/java/org/apache/shardingsphere/sql/parser/api/parser/SQLParserEngine.java
##########
@@ -64,7 +64,7 @@ public ParseTree parse(final String sql, final boolean useCache) {
     private ParseTree parse(final String sql) {
         ParseASTNode result = twoPhaseParse(sql);
         if (result.getRootNode() instanceof ErrorNode) {
-            throw new SQLParsingException(String.format("Unsupported SQL of `%s`", sql));
+            throw new SQLParsingException(String.format("Unsupported SQL of `%s`", sql).replaceAll("%", "%%"));

Review comment:
       > Why is `replaceAll("%", "%%")` needed?
   
   @tristaZero When user executes a SQL containing `%` and the SQL parsing is abnormal, for example: `SET PASSWORD FOR'bob'@'%.example.org' = PASSWORD('auth_string');`. Since the `%` symbol is a reserved character, an `UnknownFormatConversionException` will occur when the `String.format()` method is executed.
   
   In order to allow users to see the real prompt, such as: `Unsupported SQL of xxxStatement`, we need to escape the `%` symbol, that is, replace it with the `%%` symbol.
   
   




----------------------------------------------------------------
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.

For queries about this service, please contact Infrastructure at:
users@infra.apache.org