| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -1230,18 +1230,12 @@ public String getHavingString(boolean hasPrefix) throws Exception { | |||
| 1230 | 1230 | return (hasPrefix ? " HAVING " : "") + StringUtil.concat(havingString, joinHaving, AND); | |
| 1231 | 1231 | } | |
| 1232 | 1232 | ||
| 1233 | - protected String getHavingItem(String quote, String table, String alias, String key, String expression, boolean containRaw) { | ||
| 1233 | + protected String getHavingItem(String quote, String table, String alias, String key, String expression, boolean containRaw) throws Exception { | ||
| 1234 | 1234 | //fun(arg0,arg1,...) | |
| 1235 | 1235 | if (containRaw) { | |
| 1236 | - try { | ||
| 1237 | - String rawSQL = getRawSQL(KEY_HAVING, expression); | ||
| 1238 | - if (rawSQL != null) { | ||
| 1239 | - return rawSQL; | ||
| 1240 | - } | ||
| 1241 | - } catch (Exception e) { | ||
| 1242 | - Log.e(TAG, "newSQLConfig rawColumnSQL == null >> try { " | ||
| 1243 | - + " String rawSQL = ((AbstractSQLConfig) config).getRawSQL(KEY_COLUMN, fk); ... " | ||
| 1244 | - + "} catch (Exception e) = " + e.getMessage()); | ||
| 1236 | + String rawSQL = getRawSQL(KEY_HAVING, expression); | ||
| 1237 | + if (rawSQL != null) { | ||
| 1238 | + return rawSQL; | ||
| 1245 | 1239 | } | |
| 1246 | 1240 | } | |
| 1247 | 1241 | ||
@@ -1460,6 +1454,17 @@ public SQLConfig setRaw(List<String> raw) { | |||
| 1460 | 1454 | */ | |
| 1461 | 1455 | @Override | |
| 1462 | 1456 | public String getRawSQL(String key, Object value) throws Exception { | |
| 1457 | + return getRawSQL(key, value, false); | ||
| 1458 | + } | ||
| 1459 | + /**获取原始 SQL 片段 | ||
| 1460 | + * @param key | ||
| 1461 | + * @param value | ||
| 1462 | + * @param throwWhenMissing | ||
| 1463 | + * @return | ||
| 1464 | + * @throws Exception | ||
| 1465 | + */ | ||
| 1466 | + @Override | ||
| 1467 | + public String getRawSQL(String key, Object value, boolean throwWhenMissing) throws Exception { | ||
| 1463 | 1468 | if (value == null) { | |
| 1464 | 1469 | return null; | |
| 1465 | 1470 | } | |
@@ -1474,11 +1479,12 @@ public String getRawSQL(String key, Object value) throws Exception { | |||
| 1474 | 1479 | String rawSQL = containRaw ? RAW_MAP.get(value) : null; | |
| 1475 | 1480 | if (containRaw) { | |
| 1476 | 1481 | if (rawSQL == null) { | |
| 1477 | - throw new UnsupportedOperationException("@raw:value 的 value 中 " + key + " 不合法!" | ||
| 1478 | - + "对应的 " + key + ":value 中 value 值 " + value + " 未在后端 RAW_MAP 中配置 !"); | ||
| 1482 | + if (throwWhenMissing) { | ||
| 1483 | + throw new UnsupportedOperationException("@raw:value 的 value 中 " + key + " 不合法!" | ||
| 1484 | + + "对应的 " + key + ":value 中 value 值 " + value + " 未在后端 RAW_MAP 中配置 !"); | ||
| 1485 | + } | ||
| 1479 | 1486 | } | |
| 1480 | - | ||
| 1481 | - if (rawSQL.isEmpty()) { | ||
| 1487 | + else if (rawSQL.isEmpty()) { | ||
| 1482 | 1488 | return (String) value; | |
| 1483 | 1489 | } | |
| 1484 | 1490 | } | |
@@ -1824,14 +1830,14 @@ public String parseSQLExpression(String key, String expression, boolean containR | |||
| 1824 | 1830 | String s2 = expression.substring(keyIndex + 1); // OVER 后半部分 | |
| 1825 | 1831 | ||
| 1826 | 1832 | int index1 = s1.indexOf("("); // 函数 "(" 的起始位置 | |
| 1827 | - String fun = s1.substring(0, index1); // 函数名称 | ||
| 1828 | 1833 | int end = s2.lastIndexOf(")"); // 后半部分 “)” 的位置 | |
| 1829 | 1834 | ||
| 1830 | - if (index1 >= end) { | ||
| 1835 | + if (index1 >= end + s1.length()) { | ||
| 1831 | 1836 | throw new IllegalArgumentException("字符 " + expression + " 不合法!" | |
| 1832 | 1837 | + key + ":value 中 value 里的 SQL 函数必须为 function(arg0,arg1,...) 这种格式!"); | |
| 1833 | 1838 | } | |
| 1834 | 1839 | ||
| 1840 | + String fun = s1.substring(0, index1); // 函数名称 | ||
| 1835 | 1841 | if (fun.isEmpty() == false) { | |
| 1836 | 1842 | if (SQL_FUNCTION_MAP == null || SQL_FUNCTION_MAP.isEmpty()) { | |
| 1837 | 1843 | if (StringUtil.isName(fun) == false) { | |
@@ -1851,11 +1857,26 @@ else if (SQL_FUNCTION_MAP.containsKey(fun) == false) { | |||
| 1851 | 1857 | int index2 = s2.indexOf("("); // 后半部分 “(”的起始位置 | |
| 1852 | 1858 | String argString2 = s2.substring(index2 + 1, end); // 后半部分的参数 | |
| 1853 | 1859 | // 别名 | |
| 1854 | - String alias = allowAlias == false || s2.lastIndexOf(":") < s2.lastIndexOf(")") ? null : s2.substring(s2.lastIndexOf(":") + 1); | ||
| 1860 | + int aliasIndex = allowAlias == false ? -1 : s2.lastIndexOf(":"); | ||
| 1861 | + String alias = aliasIndex < 0 ? "" : s2.substring(aliasIndex + 1); | ||
| 1862 | + if (alias.isEmpty() == false && StringUtil.isName(alias) == false) { | ||
| 1863 | + throw new IllegalArgumentException("字符串 " + alias + " 不合法!预编译模式下 " | ||
| 1864 | + + key + ":value 中 value里面用 ; 分割的每一项" | ||
| 1865 | + + " function(arg0,arg1,...):alias 中 alias 必须是1个单词!并且不要有多余的空格!"); | ||
| 1866 | + } | ||
| 1867 | + | ||
| 1868 | + String suffix = s2.substring(end + 1, aliasIndex < 0 ? s2.length() : aliasIndex); | ||
| 1869 | + if (suffix.isEmpty() == false && (((String) suffix).contains("--") || ((String) suffix).contains("/*") | ||
| 1870 | + || PATTERN_RANGE.matcher((String) suffix).matches() == false)) { | ||
| 1871 | + throw new UnsupportedOperationException("字符串 " + suffix + " 不合法!预编译模式下 " + key | ||
| 1872 | + + ":\"column?value;function(arg0,arg1,...)?value...\"" | ||
| 1873 | + + " 中 ?value 必须符合正则表达式 " + PATTERN_RANGE + " 且不包含连续减号 -- 或注释符 /* !不允许多余的空格!"); | ||
| 1874 | + } | ||
| 1875 | + | ||
| 1855 | 1876 | // 获取后半部分的参数解析 (agr0 agr1 ...) | |
| 1856 | 1877 | String argsString2[] = parseArgsSplitWithComma(argString2, false, containRaw, allowAlias); | |
| 1857 | 1878 | expression = fun + "(" + StringUtil.getString(agrsString1) + (containOver ? ") OVER (" : ") AGAINST (") // 传参不传空格,拼接带空格 | |
| 1858 | - + StringUtil.getString(argsString2) + ")" + (StringUtil.isEmpty(alias, true) ? "" : " AS " + quote + alias + quote); } | ||
| 1879 | + + StringUtil.getString(argsString2) + ")" + suffix + (StringUtil.isEmpty(alias, true) ? "" : " AS " + quote + alias + quote); } | ||
| 1859 | 1880 | } | |
| 1860 | 1881 | ||
| 1861 | 1882 | return expression; | |
@@ -3016,8 +3037,6 @@ protected String getWhereItem(String key, Object value, RequestMethod method, bo | |||
| 3016 | 3037 | throw new IllegalArgumentException(TAG + ".getWhereItem: 字符 " + key + " 不合法!"); | |
| 3017 | 3038 | } | |
| 3018 | 3039 | ||
| 3019 | - // 原始 SQL 片段 | ||
| 3020 | - String rawSQL = getRawSQL(key, value); | ||
| 3021 | 3040 | ||
| 3022 | 3041 | int keyType; | |
| 3023 | 3042 | if (key.endsWith("$")) { | |
@@ -3054,6 +3073,9 @@ else if (key.endsWith("<")) { | |||
| 3054 | 3073 | } | |
| 3055 | 3074 | ||
| 3056 | 3075 | String column = getRealKey(method, key, false, true, verifyName); | |
| 3076 | + | ||
| 3077 | + // 原始 SQL 片段 | ||
| 3078 | + String rawSQL = getRawSQL(key, value, keyType != 4 || value instanceof String == false); | ||
| 3057 | 3079 | ||
| 3058 | 3080 | switch (keyType) { | |
| 3059 | 3081 | case 1: | |
@@ -4747,15 +4769,9 @@ else if (whereList.contains(key)) { | |||
| 4747 | 4769 | boolean containColumnRaw = rawList != null && rawList.contains(KEY_COLUMN); | |
| 4748 | 4770 | String rawColumnSQL = null; | |
| 4749 | 4771 | if (containColumnRaw) { | |
| 4750 | - try { | ||
| 4751 | - rawColumnSQL = config.getRawSQL(KEY_COLUMN, column); | ||
| 4752 | - if (rawColumnSQL != null) { | ||
| 4753 | - cs.add(rawColumnSQL); | ||
| 4754 | - } | ||
| 4755 | - } catch (Exception e) { | ||
| 4756 | - Log.e(TAG, "newSQLConfig config instanceof AbstractSQLConfig >> try { " | ||
| 4757 | - + " rawColumnSQL = ((AbstractSQLConfig) config).getRawSQL(KEY_COLUMN, column); " | ||
| 4758 | - + "} catch (Exception e) = " + e.getMessage()); | ||
| 4772 | + rawColumnSQL = config.getRawSQL(KEY_COLUMN, column); | ||
| 4773 | + if (rawColumnSQL != null) { | ||
| 4774 | + cs.add(rawColumnSQL); | ||
| 4759 | 4775 | } | |
| 4760 | 4776 | } | |
| 4761 | 4777 | ||
@@ -4766,16 +4782,10 @@ else if (whereList.contains(key)) { | |||
| 4766 | 4782 | String[] ks; | |
| 4767 | 4783 | for (String fk : fks) { | |
| 4768 | 4784 | if (containColumnRaw) { | |
| 4769 | - try { | ||
| 4770 | - String rawSQL = config.getRawSQL(KEY_COLUMN, fk); | ||
| 4771 | - if (rawSQL != null) { | ||
| 4772 | - cs.add(rawSQL); | ||
| 4773 | - continue; | ||
| 4774 | - } | ||
| 4775 | - } catch (Exception e) { | ||
| 4776 | - Log.e(TAG, "newSQLConfig rawColumnSQL == null >> try { " | ||
| 4777 | - + " String rawSQL = ((AbstractSQLConfig) config).getRawSQL(KEY_COLUMN, fk); ... " | ||
| 4778 | - + "} catch (Exception e) = " + e.getMessage()); | ||
| 4785 | + String rawSQL = config.getRawSQL(KEY_COLUMN, fk); | ||
| 4786 | + if (rawSQL != null) { | ||
| 4787 | + cs.add(rawSQL); | ||
| 4788 | + continue; | ||
| 4779 | 4789 | } | |
| 4780 | 4790 | } | |
| 4781 | 4791 | ||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -244,6 +244,7 @@ public interface SQLConfig { | |||
| 244 | 244 | String getWhereString(boolean hasPrefix) throws Exception; | |
| 245 | 245 | ||
| 246 | 246 | String getRawSQL(String key, Object value) throws Exception; | |
| 247 | + String getRawSQL(String key, Object value, boolean throwWhenMissing) throws Exception; | ||
| 247 | 248 | ||
| 248 | 249 | boolean isKeyPrefix(); | |
| 249 | 250 | ||
| Back | FazBrowse Home | New Git URL |
0 commit comments