| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
1 parent 4f6066c commit 1f3b59b
5 files changed
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -5,7 +5,7 @@ | |||
| 5 | 5 | ||
| 6 | 6 | <groupId>com.github.Tencent</groupId> | |
| 7 | 7 | <artifactId>APIJSON</artifactId> | |
| 8 | - <version>7.0.3</version> | ||
| 8 | + <version>7.0.5</version> | ||
| 9 | 9 | <packaging>jar</packaging> | |
| 10 | 10 | ||
| 11 | 11 | <name>APIJSONORM</name> | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -480,6 +480,31 @@ public JSONObject putsEmpty(String key, boolean isEmpty, boolean trim) { | |||
| 480 | 480 | public JSONObject putsLength(String key, String compare) { | |
| 481 | 481 | return puts(key+"{}", SQL.length(key) + compare); | |
| 482 | 482 | } | |
| 483 | + /** | ||
| 484 | + * @param key | ||
| 485 | + * @param compare <=, > ... | ||
| 486 | + * @param value 1, 5, 3.14, -99 ... | ||
| 487 | + * @return {@link #puts(String, Object)} | ||
| 488 | + */ | ||
| 489 | + public JSONObject putsLength(String key, String compare, Object value) { | ||
| 490 | + return puts(key+"["+(StringUtil.isEmpty(compare) || "=".equals(compare) ? "" : ("!=".equals(compare) ? "!" : compare)), value); | ||
| 491 | + } | ||
| 492 | + /** | ||
| 493 | + * @param key | ||
| 494 | + * @param compare <=0, >5 ... | ||
| 495 | + * @return {@link #puts(String, Object)} | ||
| 496 | + */ | ||
| 497 | + public JSONObject putsJSONLength(String key, String compare) { | ||
| 498 | + return puts(key+"{}", SQL.json_length(key) + compare); | ||
| 499 | + } | ||
| 500 | + /** | ||
| 501 | + * @param key | ||
| 502 | + * @param compare <=0, >5 ... | ||
| 503 | + * @return {@link #puts(String, Object)} | ||
| 504 | + */ | ||
| 505 | + public JSONObject putsJSONLength(String key, String compare, Object value) { | ||
| 506 | + return puts(key + "{" + (StringUtil.isEmpty(compare) || "=".equals(compare) ? "" : ("!=".equals(compare) ? "!" : compare)), value); | ||
| 507 | + } | ||
| 483 | 508 | ||
| 484 | 509 | /**设置搜索 | |
| 485 | 510 | * type = SEARCH_TYPE_CONTAIN_FULL | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -14,7 +14,7 @@ public class Log { | |||
| 14 | 14 | ||
| 15 | 15 | public static boolean DEBUG = true; | |
| 16 | 16 | ||
| 17 | - public static final String VERSION = "7.0.3"; | ||
| 17 | + public static final String VERSION = "7.0.5"; | ||
| 18 | 18 | public static final String KEY_SYSTEM_INFO_DIVIDER = "\n---|-----APIJSON SYSTEM INFO-----|---\n"; | |
| 19 | 19 | ||
| 20 | 20 | public static final String OS_NAME; | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -116,6 +116,13 @@ public static String lengthCompare(String s, String compare) { | |||
| 116 | 116 | public static String length(String s) { | |
| 117 | 117 | return "length(" + s + ")"; | |
| 118 | 118 | } | |
| 119 | + /** | ||
| 120 | + * @param s 因为POWER(x,y)等函数含有不只一个key,所以需要客户端添加进去,服务端检测到条件中有'('和')'时就不转换,直接当SQL语句查询 | ||
| 121 | + * @return "json_length(" + s + ")" | ||
| 122 | + */ | ||
| 123 | + public static String json_length(String s) { | ||
| 124 | + return "json_length(" + s + ")"; | ||
| 125 | + } | ||
| 119 | 126 | /** | |
| 120 | 127 | * @param s 因为POWER(x,y)等函数含有不只一个key,所以需要客户端添加进去,服务端检测到条件中有'('和')'时就不转换,直接当SQL语句查询 | |
| 121 | 128 | * @return "char_length(" + s + ")" | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -3585,7 +3585,9 @@ public String getCompareString(String key, String column, Object value, String t | |||
| 3585 | 3585 | if (value != null && JSON.isBooleanOrNumberOrString(value) == false && value instanceof Subquery == false) { | |
| 3586 | 3586 | throw new IllegalArgumentException(key + ":value 中 value 不合法!比较运算 [>, <, >=, <=] 只支持 [Boolean, Number, String] 内的类型 !"); | |
| 3587 | 3587 | } | |
| 3588 | - if (StringUtil.isName(column) == false) { | ||
| 3588 | + | ||
| 3589 | + String rc = column.endsWith("[") || column.endsWith("{") ? column.substring(0, column.length() - 1) : column; | ||
| 3590 | + if ( ! StringUtil.isName(rc)) { | ||
| 3589 | 3591 | throw new IllegalArgumentException(key + ":value 中 key 不合法!比较运算 [>, <, >=, <=] 不支持 [&, !, |] 中任何逻辑运算符 !"); | |
| 3590 | 3592 | } | |
| 3591 | 3593 | ||
@@ -3594,7 +3596,16 @@ public String getCompareString(String key, String column, Object value, String t | |||
| 3594 | 3596 | } | |
| 3595 | 3597 | ||
| 3596 | 3598 | public String getKey(String key) { | |
| 3597 | - if (isTest()) { | ||
| 3599 | + String lenFun = ""; | ||
| 3600 | + if (key.endsWith("[")) { | ||
| 3601 | + lenFun = isSQLServer() ? "datalength" : "length"; | ||
| 3602 | + key = key.substring(0, key.length() - 1); | ||
| 3603 | + } | ||
| 3604 | + else if (key.endsWith("{")) { | ||
| 3605 | + lenFun = "json_length"; | ||
| 3606 | + key = key.substring(0, key.length() - 1); | ||
| 3607 | + } | ||
| 3608 | + else if (isTest()) { | ||
| 3598 | 3609 | if (key.contains("'")) { // || key.contains("#") || key.contains("--")) { | |
| 3599 | 3610 | throw new IllegalArgumentException("参数 " + key + " 不合法!key 中不允许有单引号 ' !"); | |
| 3600 | 3611 | } | |
@@ -3606,13 +3617,18 @@ public String getKey(String key) { | |||
| 3606 | 3617 | if (expression == null) { | |
| 3607 | 3618 | expression = COLUMN_KEY_MAP == null ? null : COLUMN_KEY_MAP.get(key); | |
| 3608 | 3619 | } | |
| 3620 | + | ||
| 3621 | + String sqlKey; | ||
| 3609 | 3622 | if (expression == null) { | |
| 3610 | - return getSQLKey(key); | ||
| 3623 | + sqlKey = getSQLKey(key); | ||
| 3624 | + } | ||
| 3625 | + else { | ||
| 3626 | + // (name,tag) left(date,4) 等 | ||
| 3627 | + List<String> raw = getRaw(); | ||
| 3628 | + sqlKey = parseSQLExpression(KEY_KEY, expression, raw != null && raw.contains(KEY_KEY), false); | ||
| 3611 | 3629 | } | |
| 3612 | 3630 | ||
| 3613 | - // (name,tag) left(date,4) 等 | ||
| 3614 | - List<String> raw = getRaw(); | ||
| 3615 | - return parseSQLExpression(KEY_KEY, expression, raw != null && raw.contains(KEY_KEY), false); | ||
| 3631 | + return lenFun.isEmpty() ? sqlKey : lenFun + "(" + sqlKey + ")"; | ||
| 3616 | 3632 | } | |
| 3617 | 3633 | public String getSQLKey(String key) { | |
| 3618 | 3634 | String q = getQuote(); | |
@@ -6016,28 +6032,37 @@ else if (key.endsWith("-")) {//缩减,PUT查询时处理 | |||
| 6016 | 6032 | } | |
| 6017 | 6033 | } | |
| 6018 | 6034 | ||
| 6019 | - //TODO if (key.endsWith("-")) { // 表示 key 和 value 顺序反过来: value LIKE key | ||
| 6035 | + String len = ""; | ||
| 6036 | + if (key.endsWith("[") || key.endsWith("{")) { | ||
| 6037 | + len = key.substring(key.length() - 1); | ||
| 6038 | + key = key.substring(0, key.length() - 1); | ||
| 6039 | + } | ||
| 6040 | + | ||
| 6041 | + // TODO if (key.endsWith("-")) { // 表示 key 和 value 顺序反过来: value LIKE key ? | ||
| 6020 | 6042 | ||
| 6021 | - //不用Logic优化代码,否则 key 可能变为 key| 导致 key=value 变成 key|=value 而出错 | ||
| 6043 | + // 不用Logic优化代码,否则 key 可能变为 key| 导致 key=value 变成 key|=value 而出错 | ||
| 6022 | 6044 | String last = key.isEmpty() ? "" : key.substring(key.length() - 1); | |
| 6023 | 6045 | if ("&".equals(last) || "|".equals(last) || "!".equals(last)) { | |
| 6024 | 6046 | key = key.substring(0, key.length() - 1); | |
| 6025 | 6047 | } else { | |
| 6026 | 6048 | last = null;//避免key + StringUtil.getString(last)错误延长 | |
| 6027 | 6049 | } | |
| 6028 | 6050 | ||
| 6029 | - //"User:toUser":User转换"toUser":User, User为查询同名Table得到的JSONObject。交给客户端处理更好 | ||
| 6030 | - if (isTableKey) {//不允许在column key中使用Type:key形式 | ||
| 6031 | - key = Pair.parseEntry(key, true).getKey();//table以左边为准 | ||
| 6051 | + // "User:toUser":User转换"toUser":User, User为查询同名Table得到的JSONObject。交给客户端处理更好 | ||
| 6052 | + if (isTableKey) { // 不允许在column key中使用Type:key形式 | ||
| 6053 | + key = Pair.parseEntry(key, true).getKey(); // table以左边为准 | ||
| 6032 | 6054 | } else { | |
| 6033 | - key = Pair.parseEntry(key).getValue();//column以右边为准 | ||
| 6055 | + key = Pair.parseEntry(key).getValue();// column 以右边为准 | ||
| 6034 | 6056 | } | |
| 6035 | 6057 | ||
| 6036 | 6058 | if (verifyName && StringUtil.isName(key.startsWith("@") ? key.substring(1) : key) == false) { | |
| 6037 | 6059 | throw new IllegalArgumentException(method + "请求,字符 " + originKey + " 不合法!" | |
| 6038 | - + " key:value 中的key只能关键词 '@key' 或 'key[逻辑符][条件符]' 或 PUT请求下的 'key+' / 'key-' !"); | ||
| 6060 | + + " key:value 中的 key 只能关键词 '@key' 或 'key[长度符][逻辑符][条件符]' 或 PUT 请求下的 'key+' / 'key-' !" | ||
| 6061 | + + "长度符 只能为 [ - length 和 { - json_length,逻辑符 只能是 & - 与、| - 或、! - 非 !"); | ||
| 6039 | 6062 | } | |
| 6040 | 6063 | ||
| 6064 | + key += len; | ||
| 6065 | + | ||
| 6041 | 6066 | if (saveLogic && last != null) { | |
| 6042 | 6067 | key = key + last; | |
| 6043 | 6068 | } | |
| Back | FazBrowse Home | New Git URL |
0 commit comments