Skip to content

Commit 79cd739

Browse files
committed
Server:子查询range的all和any全改为大写的ALL和ANY;解决=,IN等只能是1个字段的子查询嵌套JOIN会因为超过一个字段报错
1 parent ddb5da8 commit 79cd739

File tree

3 files changed

+45
-8
lines changed

3 files changed

+45
-8
lines changed

APIJSON-Java-Server/APIJSONORM/src/main/java/zuo/biao/apijson/StringUtil.java

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -837,6 +837,29 @@ public static String toLowerCase(String s, boolean trim) {
837837
return s.toLowerCase();
838838
}
839839

840+
public static String concat(String left, String right) {
841+
return concat(left, right, null);
842+
}
843+
public static String concat(String left, String right, String split) {
844+
return concat(left, right, split, true);
845+
}
846+
public static String concat(String left, String right, boolean trim) {
847+
return concat(left, right, null, trim);
848+
}
849+
public static String concat(String left, String right, String split, boolean trim) {
850+
if (isEmpty(left, trim)) {
851+
return right;
852+
}
853+
if (isEmpty(right, trim)) {
854+
return left;
855+
}
856+
857+
if (split == null) {
858+
split = ",";
859+
}
860+
return left + split + right;
861+
}
862+
840863
//校正(自动补全等)字符串>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
841864

842865
}

APIJSON-Java-Server/APIJSONORM/src/main/java/zuo/biao/apijson/server/AbstractObjectParser.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -334,8 +334,8 @@ public boolean onParse(@NotNull String key, @NotNull Object value) throws Except
334334

335335
JSONObject subquery = (JSONObject) value;
336336
String range = subquery.getString("range");
337-
if (range != null && "any".equals(range) == false && "all".equals(range) == false) {
338-
throw new IllegalArgumentException("子查询 " + path + "/" + key + ":{ range:value } 中 value 只能为 [any, all] 中的一个!");
337+
if (range != null && "ANY".equals(range) == false && "ALL".equals(range) == false) {
338+
throw new IllegalArgumentException("子查询 " + path + "/" + key + ":{ range:value } 中 value 只能为 [ANY, ALL] 中的一个!");
339339
}
340340

341341

APIJSON-Java-Server/APIJSONORM/src/main/java/zuo/biao/apijson/server/AbstractSQLConfig.java

Lines changed: 20 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -476,6 +476,10 @@ public AbstractSQLConfig setColumn(List<String> column) {
476476
}
477477
@JSONField(serialize = false)
478478
public String getColumnString() throws Exception {
479+
return getColumnString(false);
480+
}
481+
@JSONField(serialize = false)
482+
public String getColumnString(boolean inSQLJoin) throws Exception {
479483
switch (getMethod()) {
480484
case HEAD:
481485
case HEADS: //StringUtil.isEmpty(column, true) || column.contains(",") 时SQL.count(column)会return "*"
@@ -506,17 +510,23 @@ public String getColumnString() throws Exception {
506510
boolean isQuery = RequestMethod.isQueryMethod(method);
507511
String joinColumn = "";
508512
if (isQuery && joinList != null) {
509-
SQLConfig c;
513+
SQLConfig cfg;
514+
String c;
510515
boolean first = true;
511516
for (Join j : joinList) {
512517
if (j.isAppJoin()) {
513518
continue;
514519
}
515520

516-
c = j.getJoinConfig();
517-
c.setAlias(c.getTable());
518-
joinColumn += (first ? "" : ", ") + ((AbstractSQLConfig) c).getColumnString();
521+
cfg = j.getJoinConfig();
522+
cfg.setAlias(cfg.getTable());
523+
524+
c = ((AbstractSQLConfig) cfg).getColumnString(true);
525+
if (StringUtil.isEmpty(c, true) == false) {
526+
joinColumn += (first ? "" : ", ") + c;
527+
}
519528

529+
inSQLJoin = true;
520530
first = false;
521531
}
522532
}
@@ -527,7 +537,11 @@ public String getColumnString() throws Exception {
527537

528538
String[] keys = column == null ? null : column.toArray(new String[]{}); //StringUtil.split(c, ";");
529539
if (keys == null || keys.length <= 0) {
530-
return isKeyPrefix() == false ? "*" : (tableAlias + ".*" + (StringUtil.isEmpty(joinColumn, true) ? "" : ", " + joinColumn));
540+
541+
boolean noColumn = column != null && inSQLJoin;
542+
String mc = isKeyPrefix() == false ? (noColumn ? "" : "*") : (noColumn ? "" : tableAlias + ".*");
543+
544+
return StringUtil.concat(mc, joinColumn, ", ", true);
531545
}
532546

533547

@@ -2114,7 +2128,7 @@ else if (whereList != null && whereList.contains(key)) {
21142128
}
21152129

21162130
config.setFrom(from);
2117-
config.setColumn(cs);
2131+
config.setColumn(column == null ? null : cs); //解决总是 config.column != null,总是不能得到 *
21182132
config.setWhere(tableWhere);
21192133

21202134
config.setId(id);

0 commit comments

Comments
 (0)