Skip to content
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,8 @@

import java.sql.SQLException;
import java.sql.SQLSyntaxErrorException;
import java.util.regex.Matcher;
import java.util.regex.Pattern;

public class DefaultRouteStrategy extends AbstractRouteStrategy {

Expand All @@ -41,6 +43,18 @@ protected RouteResultset routeNormalSqlWithAST(SchemaConfig schema,
}

private SQLStatement parserSQL(String originSql, ServerConnection c) throws SQLSyntaxErrorException {

// 提取 SELECT 和 FROM 之间的字段部分(忽略大小写)
Pattern pattern = Pattern.compile("(?i)SELECT\\s+(.*?)\\s+FROM", Pattern.DOTALL);
Matcher matcher = pattern.matcher(originSql);
if (matcher.find()) {
String selectList = matcher.group(1);
// 仅检查字段列表中的逗号
if (Pattern.compile("[,\\uFF0C]").matcher(selectList).find()) {
throw new SQLSyntaxErrorException("invalid chinese symbol ,");
}
}

SQLStatementParser parser = new MySqlStatementParser(originSql);
try {
return parser.parseStatement(true);
Expand Down
Loading