Skip to content

Commit 12738bf

Browse files
committed
解决 JOIN ON 中用 @combine 等情况下预编译值与 SQL 中 ? 占位符顺序对不上导致的异常
1 parent 9776408 commit 12738bf

File tree

1 file changed

+15
-9
lines changed

1 file changed

+15
-9
lines changed

APIJSONORM/src/main/java/apijson/orm/AbstractSQLConfig.java

Lines changed: 15 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -2463,8 +2463,10 @@ protected String parseCombineExpression(RequestMethod method, String quote, Stri
24632463

24642464
int n = s.length();
24652465
if (n > 0) {
2466-
setPreparedValueList(new ArrayList<>());
2467-
2466+
if (isHaving == false) {
2467+
setPreparedValueList(new ArrayList<>()); // 必须反过来,否则 JOIN ON 内部 @combine 拼接后顺序错误
2468+
}
2469+
24682470
int maxDepth = getMaxCombineDepth();
24692471
int maxCombineCount = getMaxCombineCount();
24702472
int maxCombineKeyCount = getMaxCombineKeyCount();
@@ -2675,13 +2677,17 @@ else if (c == ')') {
26752677
if (StringUtil.isEmpty(result, true)) {
26762678
result = andCond;
26772679
}
2678-
else if (StringUtil.isNotEmpty(andCond, true)) { // andWhere 必须放后面,否则 prepared 值顺序错误
2679-
// result = "( " + result + " )" + AND + andCond;
2680-
result = andCond + AND + "( " + result + " )"; // 先暂存之前的 prepared 值,然后反向整合
2681-
if (n > 0) {
2682-
prepreadValues.addAll(getPreparedValueList());
2683-
setPreparedValueList(prepreadValues);
2684-
}
2680+
else if (StringUtil.isNotEmpty(andCond, true)) { // andCond 必须放后面,否则 prepared 值顺序错误
2681+
if (isHaving) { // HAVING 前 WHERE 已经有条件 ? 占位,不能反过来,想优化 AND 连接在最前,需要多遍历一次内部的 key,也可以 newSQLConfig 时存到 andList
2682+
result = "( " + result + " )" + AND + andCond;
2683+
}
2684+
else {
2685+
result = andCond + AND + "( " + result + " )"; // 先暂存之前的 prepared 值,然后反向整合
2686+
if (n > 0) {
2687+
prepreadValues.addAll(getPreparedValueList());
2688+
setPreparedValueList(prepreadValues);
2689+
}
2690+
}
26852691
}
26862692

26872693
return result;

0 commit comments

Comments
 (0)