Skip to content

Commit 9d4bd7b

Browse files
committed
解决 Windows mysql-5.6.26-winx64 等低于 5.7 的 MySQL 可能 id{}: [0] 生成 id IN(0) 触发 MySQL bug 导致忽略 IN 条件
1 parent 5d23942 commit 9d4bd7b

File tree

1 file changed

+20
-1
lines changed

1 file changed

+20
-1
lines changed

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

Lines changed: 20 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,7 @@
5656
import apijson.StringUtil;
5757
import apijson.orm.AbstractSQLConfig.IdCallback;
5858
import apijson.orm.exception.ConflictException;
59+
import apijson.orm.exception.NotExistException;
5960
import apijson.orm.exception.NotLoggedInException;
6061
import apijson.orm.model.Access;
6162
import apijson.orm.model.Column;
@@ -610,7 +611,25 @@ private static void verifyId(@NotNull String method, @NotNull String name, @NotN
610611
//new ArrayList<Long>(idIn) 不能检查类型,Java泛型擦除问题,居然能把 ["a"] 赋值进去还不报错
611612
for (int i = 0; i < idIn.size(); i++) {
612613
Object o = idIn.get(i);
613-
if (o != null && o instanceof Number == false && o instanceof String == false) {
614+
if (o == null) {
615+
throw new IllegalArgumentException(method + "请求," + name + "/" + key
616+
+ " 里面的 " + idInKey + ":[] 中所有项都不能为 [ null, <= 0 的数字, 空字符串 \"\" ] 中任何一个 !");
617+
}
618+
if (o instanceof Number) {
619+
//解决 Windows mysql-5.6.26-winx64 等低于 5.7 的 MySQL 可能 id{}: [0] 生成 id IN(0) 触发 MySQL bug 导致忽略 IN 条件
620+
//例如 UPDATE `apijson`.`TestRecord` SET `testAccountId` = -1 WHERE ( (`id` IN (0)) AND (`userId`= 82001) )
621+
if (((Number) o).longValue() <= 0) {
622+
throw new IllegalArgumentException(method + "请求," + name + "/" + key
623+
+ " 里面的 " + idInKey + ":[] 中所有项都不能为 [ null, <= 0 的数字, 空字符串 \"\" ] 中任何一个 !");
624+
}
625+
}
626+
else if (o instanceof String) {
627+
if (StringUtil.isEmpty(o, true)) {
628+
throw new IllegalArgumentException(method + "请求," + name + "/" + key
629+
+ " 里面的 " + idInKey + ":[] 中所有项都不能为 [ null, <= 0 的数字, 空字符串 \"\" ] 中任何一个 !");
630+
}
631+
}
632+
else {
614633
throw new IllegalArgumentException(method + "请求," + name + "/" + key
615634
+ " 里面的 " + idInKey + ":[] 中所有项的类型都只能是 Long 或 String !");
616635
}

0 commit comments

Comments
 (0)