Skip to content

Commit 2b19a12

Browse files
committed
返回字段 @column 支持 (balance)*100 和 length(content)%2=0 这种 字段 或 SQL 函数 后拼接数字比较表达式
1 parent 71f9043 commit 2b19a12

1 file changed

Lines changed: 19 additions & 16 deletions

File tree

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

Lines changed: 19 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -957,11 +957,14 @@ public String getColumnString(boolean inSQLJoin) throws Exception {
957957

958958
method = expression.substring(0, start);
959959
boolean distinct = i <= 0 && method.startsWith(PREFFIX_DISTINCT);
960-
if (StringUtil.isName(distinct ? method.substring(PREFFIX_DISTINCT.length()) : method) == false) {
960+
String fun = distinct ? method.substring(PREFFIX_DISTINCT.length()) : method;
961+
962+
if (fun.isEmpty() == false && StringUtil.isName(fun) == false) {
961963
throw new IllegalArgumentException("字符 " + method + " 不合法!"
962964
+ "预编译模式下 @column:\"column0,column1:alias;function0(arg0,arg1,...);function1(...):alias...\""
963965
+ " 中SQL函数名 function 必须符合正则表达式 ^[0-9a-zA-Z_]+$ !");
964966
}
967+
965968
}
966969

967970
boolean isColumn = start < 0;
@@ -1043,23 +1046,23 @@ else if (StringUtil.isName(origin)) {
10431046
}
10441047
else {
10451048
String suffix = expression.substring(end + 1, expression.length()); //:contactCount
1046-
String alias = suffix.startsWith(":") ? suffix.substring(1) : null; //contactCount
1047-
1048-
if (StringUtil.isEmpty(alias, true)) {
1049-
if (suffix.isEmpty() == false) {
1050-
throw new IllegalArgumentException("GET请求: 预编译模式下 @column:value 中 value里面用 ; 分割的每一项"
1051-
+ " function(arg0,arg1,...):alias 中 alias 如果有就必须是1个单词!并且不要有多余的空格!");
1052-
}
1053-
}
1054-
else {
1055-
if (StringUtil.isEmpty(alias, true) == false && StringUtil.isName(alias) == false) {
1056-
throw new IllegalArgumentException("GET请求: 预编译模式下 @column:value 中 value里面用 ; 分割的每一项"
1057-
+ " function(arg0,arg1,...):alias 中 alias 必须是1个单词!并且不要有多余的空格!");
1058-
}
1049+
int index = suffix.lastIndexOf(":");
1050+
String alias = index < 0 ? "" : suffix.substring(index + 1); //contactCount
1051+
suffix = index < 0 ? suffix : suffix.substring(0, index);
1052+
1053+
if (alias.isEmpty() == false && StringUtil.isName(alias) == false) {
1054+
throw new IllegalArgumentException("字符串 " + alias + " 不合法!"
1055+
+ "预编译模式下 @column:value 中 value里面用 ; 分割的每一项"
1056+
+ " function(arg0,arg1,...):alias 中 alias 必须是1个单词!并且不要有多余的空格!");
1057+
}
1058+
1059+
if (suffix.isEmpty() == false && (((String) suffix).contains("--") || PATTERN_RANGE.matcher((String) suffix).matches() == false)) {
1060+
throw new UnsupportedOperationException("字符串 " + suffix + " 不合法!"
1061+
+ "预编译模式下 @column:\"column?value;function(arg0,arg1,...)?value...\""
1062+
+ " 中 ?value 必须符合正则表达式 " + PATTERN_RANGE + " 且不包含连续减号 -- !不允许多余的空格!");
10591063
}
10601064

1061-
1062-
String origin = method + "(" + StringUtil.getString(ckeys) + ")";
1065+
String origin = method + "(" + StringUtil.getString(ckeys) + ")" + suffix;
10631066
// if (isKeyPrefix()) {
10641067
// keys[i] = origin + " AS " + quote + (isMain() ? "" : tableAlias + ".") + (StringUtil.isEmpty(alias, true) ? method : alias) + quote;
10651068
// }

0 commit comments

Comments
 (0)