diff --git a/src/main/java/io/mycat/server/ServerConnection.java b/src/main/java/io/mycat/server/ServerConnection.java index 4c3b39b8adc61304267db672032172a835d4cdfd..99c17fd132f75d201e513bc817e473441ba51e10 100644 --- a/src/main/java/io/mycat/server/ServerConnection.java +++ b/src/main/java/io/mycat/server/ServerConnection.java @@ -327,6 +327,13 @@ public class ServerConnection extends FrontendConnection { return ServerParse.SELECT == type || ServerParse.INSERT == type || ServerParse.UPDATE == type || ServerParse.DELETE == type || ServerParse.DDL == type; } + /** + * 判断sql是否为CRUD操作,mycat会将一部分SET操作转换为UPDATE操作(io.mycat.server.handler.SetHandler)如:set session sql_mode='HIGH_NOT_PRECEDENCE',从而导致解析错误,所以UPDATE特殊判断 + */ + private boolean isCRUDSql(int type, String sql) { + return ServerParse.SELECT == type || ServerParse.INSERT == type || ServerParse.UPDATE == ServerParse.parse(sql) || ServerParse.DELETE == type; + } + public RouteResultset routeSQL(String sql, int type) { // 检查当前使用的DB @@ -375,7 +382,7 @@ public class ServerConnection extends FrontendConnection { // 路由计算 RouteResultset rrs = null; try { - boolean sqlPass = !sql.contains("information_schema") && (type == ServerParse.DELETE || type == ServerParse.INSERT || type == ServerParse.UPDATE || type == ServerParse.SELECT); + boolean sqlPass = !sql.contains("information_schema") && isCRUDSql(type, sql); //zrx 如果是增删查改 if (sqlPass) { // zrx 路由之前修改sql