@@ -83,7 +83,7 @@ public abstract class AbstractSQLConfig implements SQLConfig {
8383 // * 和 / 不能同时出现,防止 /* */ 段注释! # 和 -- 不能出现,防止行注释! ; 不能出现,防止隔断SQL语句!空格不能出现,防止 CRUD,DROP,SHOW TABLES等语句!
8484 private static final Pattern PATTERN_RANGE ;
8585 private static final Pattern PATTERN_FUNCTION ;
86- private static final Pattern PATTERN_STRING ;
86+ private static final Pattern PATTERN_STRING ;
8787
8888 /**
8989 * 表名映射,隐藏真实表名,对安全要求很高的表可以这么做
@@ -1490,9 +1490,8 @@ public String getColumnString(boolean inSQLJoin) throws Exception {
14901490 return "(" + s + ")" ;
14911491 case GET :
14921492 case GETS :
1493- boolean isQuery = RequestMethod .isQueryMethod (method ); //TODO 这个有啥用?上面应是 getMethod 的值 GET 和 GETS 了。
14941493 String joinColumn = "" ;
1495- if (isQuery && joinList != null ) {
1494+ if (joinList != null ) {
14961495 SQLConfig ecfg ;
14971496 SQLConfig cfg ;
14981497 String c ;
@@ -1501,23 +1500,31 @@ public String getColumnString(boolean inSQLJoin) throws Exception {
15011500 if (j .isAppJoin ()) {
15021501 continue ;
15031502 }
1504-
1505- ecfg = j .getOuterConfig ();
1506- if (ecfg != null && ecfg .getColumn () != null ) { //优先级更高
1507- cfg = ecfg ;
1508- }
1509- else {
1510- cfg = j .getJoinConfig ();
1511- }
1512-
1513- if (StringUtil .isEmpty (cfg .getAlias (), true )) {
1514- cfg .setAlias (cfg .getTable ());
1515- }
1516-
1517- c = ((AbstractSQLConfig ) cfg ).getColumnString (true );
1518- if (StringUtil .isEmpty (c , true ) == false ) {
1519- joinColumn += (first ? "" : ", " ) + c ;
1503+
1504+ if (j .isLeftOrRightJoin ()) {
1505+ // 改为 SELECT ViceTable.* 解决 SELECT sum(ViceTable.id) LEFT/RIGHT JOIN (SELECT sum(id) FROM ViceTable...) AS ViceTable
1506+ // 不仅导致 SQL 函数重复计算,还有时导致 SQL 报错或对应字段未返回
1507+ String quote = getQuote ();
1508+ joinColumn += (first ? "" : ", " ) + quote + (StringUtil .isEmpty (j .getAlias (), true ) ? j .getTable () : j .getAlias ()) + quote + ".*" ;
15201509 first = false ;
1510+ } else {
1511+ ecfg = j .getOuterConfig ();
1512+ if (ecfg != null && ecfg .getColumn () != null ) { //优先级更高
1513+ cfg = ecfg ;
1514+ }
1515+ else {
1516+ cfg = j .getJoinConfig ();
1517+ }
1518+
1519+ if (StringUtil .isEmpty (cfg .getAlias (), true )) {
1520+ cfg .setAlias (cfg .getTable ());
1521+ }
1522+
1523+ c = ((AbstractSQLConfig ) cfg ).getColumnString (true );
1524+ if (StringUtil .isEmpty (c , true ) == false ) {
1525+ joinColumn += (first ? "" : ", " ) + c ;
1526+ first = false ;
1527+ }
15211528 }
15221529
15231530 inSQLJoin = true ;
0 commit comments