From 4fc3fbc4a0f38618a50940497c2bc760ca7b9f0c Mon Sep 17 00:00:00 2001 From: zhongxuchen Date: Thu, 4 Jul 2024 09:51:47 +0800 Subject: [PATCH 1/7] =?UTF-8?q?=E6=9B=B4=E6=96=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../dialect/utils/DefaultDialectUtils.java | 46 ++++++++++++++++--- .../config/SqlConfigParseUtilsTest.java | 2 +- 2 files changed, 40 insertions(+), 8 deletions(-) diff --git a/trunk/sqltoy-orm-core/src/main/java/org/sagacity/sqltoy/dialect/utils/DefaultDialectUtils.java b/trunk/sqltoy-orm-core/src/main/java/org/sagacity/sqltoy/dialect/utils/DefaultDialectUtils.java index 5bf6174f7..43c0fad7b 100644 --- a/trunk/sqltoy-orm-core/src/main/java/org/sagacity/sqltoy/dialect/utils/DefaultDialectUtils.java +++ b/trunk/sqltoy-orm-core/src/main/java/org/sagacity/sqltoy/dialect/utils/DefaultDialectUtils.java @@ -34,6 +34,7 @@ import org.sagacity.sqltoy.callback.ReflectPropsHandler; import org.sagacity.sqltoy.callback.UpdateRowHandler; import org.sagacity.sqltoy.config.SqlConfigParseUtils; +import org.sagacity.sqltoy.config.model.DataVersionConfig; import org.sagacity.sqltoy.config.model.EntityMeta; import org.sagacity.sqltoy.config.model.FieldMeta; import org.sagacity.sqltoy.config.model.OperateType; @@ -52,6 +53,7 @@ import org.sagacity.sqltoy.utils.BeanUtil; import org.sagacity.sqltoy.utils.DataSourceUtils; import org.sagacity.sqltoy.utils.DataSourceUtils.DBType; +import org.sagacity.sqltoy.utils.DateUtil; import org.sagacity.sqltoy.utils.ReservedWordsUtil; import org.sagacity.sqltoy.utils.ResultUtils; import org.sagacity.sqltoy.utils.SqlUtil; @@ -414,6 +416,8 @@ public void execute(Object rowData, PreparedStatement pst, ResultSet rs) throws int rowCnt = finalRs.getMetaData().getColumnCount(); int index = 0; List result = new ArrayList(); + DataVersionConfig dataVersion = entityMeta.getDataVersion(); + final String dataVersionField = (dataVersion == null) ? null : dataVersion.getField(); while (finalRs.next()) { if (index > 0) { throw new DataAccessException("updateSaveFetch操作只能针对单条记录进行操作,请检查uniqueProps参数设置!"); @@ -421,16 +425,44 @@ public void execute(Object rowData, PreparedStatement pst, ResultSet rs) throws // 存在修改记录 if (hasUpdateRow) { SqlExecuteStat.debug("执行updateRow", "记录存在调用updateRowHandler.updateRow!"); + // 存在数据版本:1、校验当前的版本是否为null(目前跳过);2、对比传递过来的版本值跟数据库中的值是否一致;3、修改数据库中数据版本+1 + if (dataVersion != null) { + Object version = BeanUtil.getProperty(entity, dataVersionField); + String nowVersion = finalRs.getString(entityMeta.getColumnName(dataVersionField)); + if (version != null && !version.toString().equals(nowVersion)) { + throw new IllegalArgumentException("表:" + entityMeta.getTableName() + + " 存在版本@DataVersion配置,在updateSaveFetch做更新时,属性:" + dataVersionField + + " 值不等于当前数据库中的值:" + version + "<>" + nowVersion + ",说明数据已经被修改过!"); + } + // 以日期开头 + if (dataVersion.isStartDate()) { + String nowDate = DateUtil.formatDate(DateUtil.getNowTime(), + DateUtil.FORMAT.DATE_8CHAR); + if (nowVersion.startsWith(nowDate)) { + nowVersion = nowDate + (Integer.parseInt(nowVersion.substring(8)) + 1); + } else { + nowVersion = nowDate + 1; + } + } else { + nowVersion = "" + (Integer.parseInt(nowVersion) + 1); + } + // 修改数据版本 + resultUpdate(conn, finalRs, entityMeta.getFieldMeta(dataVersionField), nowVersion, + dbType, false); + } // 执行update反调,实现锁定行记录值的修改 updateRowHandler.updateRow(finalRs, index); updateRowHandler.updateRow(finalRs, index, (fieldName, fieldValue) -> { - Optional.ofNullable(entityMeta.getFieldMeta(fieldName)).ifPresent(fieldMeta -> { - try { - resultUpdate(conn, finalRs, fieldMeta, fieldValue, dbType, false); - } catch (Exception e) { - throw new RuntimeException(e); - } - }); + // 排除dataVersionField字段避免被重复处理 + if (dataVersionField == null || !fieldName.equals(dataVersionField)) { + Optional.ofNullable(entityMeta.getFieldMeta(fieldName)).ifPresent(fieldMeta -> { + try { + resultUpdate(conn, finalRs, fieldMeta, fieldValue, dbType, false); + } catch (Exception e) { + throw new RuntimeException(e); + } + }); + } }); // 考虑公共字段修改 if (unifyFieldsHandler != null && unifyFieldsHandler.updateUnifyFields() != null) { diff --git a/trunk/sqltoy-orm-core/src/test/java/org/sagacity/sqltoy/config/SqlConfigParseUtilsTest.java b/trunk/sqltoy-orm-core/src/test/java/org/sagacity/sqltoy/config/SqlConfigParseUtilsTest.java index c824bf12b..2a6293f20 100644 --- a/trunk/sqltoy-orm-core/src/test/java/org/sagacity/sqltoy/config/SqlConfigParseUtilsTest.java +++ b/trunk/sqltoy-orm-core/src/test/java/org/sagacity/sqltoy/config/SqlConfigParseUtilsTest.java @@ -394,7 +394,7 @@ public void testOverSizeIn6() throws Exception { @Test public void testLike() throws Exception { - String sql = "select * from table t where t.name ilike N:name and t.desc like :desc"; + String sql = "select * from table t where t.name ilike :name and t.desc like :desc"; SqlToyResult result = SqlConfigParseUtils.processSql(sql, new String[] { "name", "desc" }, new Object[] { "张三", "验证" }); From aaecbaef2f03eb3fc976d78d03771d8bb9aade49 Mon Sep 17 00:00:00 2001 From: zhongxuchen Date: Thu, 11 Jul 2024 21:31:12 +0800 Subject: [PATCH 2/7] =?UTF-8?q?=E6=9B=B4=E6=96=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../org/sagacity/sqltoy/SqlExecuteStat.java | 5 +++++ .../sqltoy/dialect/utils/DialectExtUtils.java | 5 +++-- .../sqltoy/plugins/function/impl/Concat.java | 7 +++---- .../sqltoy/plugins/function/impl/ConcatWs.java | 17 ++++++++++------- .../sqltoy/plugins/function/impl/ToDate.java | 2 +- .../sqltoy/plugins/function/impl/ToNumber.java | 2 +- .../java/org/sagacity/sqltoy/utils/SqlUtil.java | 10 ++++++++-- .../sqltoy/config/SqlConfigParseUtilsTest.java | 2 +- 8 files changed, 32 insertions(+), 18 deletions(-) diff --git a/trunk/sqltoy-orm-core/src/main/java/org/sagacity/sqltoy/SqlExecuteStat.java b/trunk/sqltoy-orm-core/src/main/java/org/sagacity/sqltoy/SqlExecuteStat.java index 04e65f3ae..54ba5c787 100644 --- a/trunk/sqltoy-orm-core/src/main/java/org/sagacity/sqltoy/SqlExecuteStat.java +++ b/trunk/sqltoy-orm-core/src/main/java/org/sagacity/sqltoy/SqlExecuteStat.java @@ -2,6 +2,7 @@ import static java.lang.System.out; +import java.lang.reflect.Proxy; import java.util.List; import java.util.regex.Matcher; import java.util.regex.Pattern; @@ -327,6 +328,10 @@ public static String getFirstTrace() { // 避免异常发生 if (i + 1 < length) { traceElement = stackTraceElements[i + 1]; + //判断是否代理类,是代理类继续向上推一层 + if ((i + 2) < length && Proxy.isProxyClass(traceElement.getClass())) { + traceElement = stackTraceElements[i + 2]; + } className = traceElement.getClassName(); method = traceElement.getMethodName(); lineNumber = traceElement.getLineNumber(); diff --git a/trunk/sqltoy-orm-core/src/main/java/org/sagacity/sqltoy/dialect/utils/DialectExtUtils.java b/trunk/sqltoy-orm-core/src/main/java/org/sagacity/sqltoy/dialect/utils/DialectExtUtils.java index 76f5a310e..ac99c273c 100644 --- a/trunk/sqltoy-orm-core/src/main/java/org/sagacity/sqltoy/dialect/utils/DialectExtUtils.java +++ b/trunk/sqltoy-orm-core/src/main/java/org/sagacity/sqltoy/dialect/utils/DialectExtUtils.java @@ -463,7 +463,7 @@ public static String mergeIgnore(IUnifyFieldsHandler unifyFieldsHandler, Integer } /** - * @TODO 针对postgresql\kingbase\guassdb等数据库 + * @TODO 针对postgresql\kingbase\guassdb\mogdb等数据库 * @param unifyFieldsHandler * @param dbType * @param entityMeta @@ -487,7 +487,8 @@ public static String insertIgnore(IUnifyFieldsHandler unifyFieldsHandler, Intege StringBuilder values = new StringBuilder(columnSize * 2 - 1); if (dbType == DBType.GAUSSDB) { sql.append("insert ignore into "); - } else { + } // mogdb支持insert into do nothing + else { sql.append("insert into "); } sql.append(entityMeta.getSchemaTable(tableName, dbType)); diff --git a/trunk/sqltoy-orm-core/src/main/java/org/sagacity/sqltoy/plugins/function/impl/Concat.java b/trunk/sqltoy-orm-core/src/main/java/org/sagacity/sqltoy/plugins/function/impl/Concat.java index efd883808..8e92fee93 100644 --- a/trunk/sqltoy-orm-core/src/main/java/org/sagacity/sqltoy/plugins/function/impl/Concat.java +++ b/trunk/sqltoy-orm-core/src/main/java/org/sagacity/sqltoy/plugins/function/impl/Concat.java @@ -24,7 +24,7 @@ public class Concat extends IFunction { */ @Override public String dialects() { - return "oracle"; + return super.ALL; } /* @@ -46,9 +46,8 @@ public Pattern regex() { @Override public String wrap(int dialect, String functionName, boolean hasArgs, String... args) { // 只针对oracle数据库,其他数据库原样返回 - if (dialect == DBType.ORACLE || dialect == DBType.OCEANBASE || dialect == DBType.DM - || dialect == DBType.ORACLE11) { - // 超过2个参数 + if (dialect == DBType.ORACLE || dialect == DBType.ORACLE11) { + // 超过2个参数(oracle 支持2个参数) if (args != null && args.length > 2) { StringBuilder result = new StringBuilder(); for (int i = 0; i < args.length; i++) { diff --git a/trunk/sqltoy-orm-core/src/main/java/org/sagacity/sqltoy/plugins/function/impl/ConcatWs.java b/trunk/sqltoy-orm-core/src/main/java/org/sagacity/sqltoy/plugins/function/impl/ConcatWs.java index 36c6e419f..9270b7eb3 100644 --- a/trunk/sqltoy-orm-core/src/main/java/org/sagacity/sqltoy/plugins/function/impl/ConcatWs.java +++ b/trunk/sqltoy-orm-core/src/main/java/org/sagacity/sqltoy/plugins/function/impl/ConcatWs.java @@ -24,7 +24,7 @@ public class ConcatWs extends IFunction { */ @Override public String dialects() { - return "oracle"; + return super.ALL; } /* @@ -45,12 +45,8 @@ public Pattern regex() { */ @Override public String wrap(int dialect, String functionName, boolean hasArgs, String... args) { - if (args.length < 2) { - return super.IGNORE; - } - // 只针对oracle数据库,其他数据库原样返回 - if (dialect == DBType.ORACLE || dialect == DBType.OCEANBASE || dialect == DBType.DM - || dialect == DBType.ORACLE11) { + // oracle 不支持concat_ws + if (dialect == DBType.ORACLE || dialect == DBType.ORACLE11) { StringBuilder result = new StringBuilder(); String split = args[0].replace("\\'", "''"); for (int i = 1; i < args.length; i++) { @@ -60,6 +56,13 @@ public String wrap(int dialect, String functionName, boolean hasArgs, String... result.append(args[i].replace("\\'", "''")); } return result.toString(); + } else if (dialect == DBType.DM) { + String splitStr = args[0].trim(); + // dm concat_ws不支持双引号包装分割符号 + if (splitStr.startsWith("\"") && splitStr.endsWith("\"")) { + args[0] = "'" + splitStr.substring(1, splitStr.length() - 1) + "'"; + return wrapArgs("concat_ws", args); + } } return super.IGNORE; } diff --git a/trunk/sqltoy-orm-core/src/main/java/org/sagacity/sqltoy/plugins/function/impl/ToDate.java b/trunk/sqltoy-orm-core/src/main/java/org/sagacity/sqltoy/plugins/function/impl/ToDate.java index 70c96a1ac..e83f6ddb8 100644 --- a/trunk/sqltoy-orm-core/src/main/java/org/sagacity/sqltoy/plugins/function/impl/ToDate.java +++ b/trunk/sqltoy-orm-core/src/main/java/org/sagacity/sqltoy/plugins/function/impl/ToDate.java @@ -19,7 +19,7 @@ public class ToDate extends IFunction { @Override public String dialects() { - return "oracle,dm,mysql,sqlserver,h2"; + return ALL; } /* diff --git a/trunk/sqltoy-orm-core/src/main/java/org/sagacity/sqltoy/plugins/function/impl/ToNumber.java b/trunk/sqltoy-orm-core/src/main/java/org/sagacity/sqltoy/plugins/function/impl/ToNumber.java index db5093ff4..1fa5d89cd 100644 --- a/trunk/sqltoy-orm-core/src/main/java/org/sagacity/sqltoy/plugins/function/impl/ToNumber.java +++ b/trunk/sqltoy-orm-core/src/main/java/org/sagacity/sqltoy/plugins/function/impl/ToNumber.java @@ -28,7 +28,7 @@ public Pattern regex() { @Override public String dialects() { - return "db2,oracle,dm"; + return ALL; } /* diff --git a/trunk/sqltoy-orm-core/src/main/java/org/sagacity/sqltoy/utils/SqlUtil.java b/trunk/sqltoy-orm-core/src/main/java/org/sagacity/sqltoy/utils/SqlUtil.java index e17eb58cb..ce8eff1ab 100644 --- a/trunk/sqltoy-orm-core/src/main/java/org/sagacity/sqltoy/utils/SqlUtil.java +++ b/trunk/sqltoy-orm-core/src/main/java/org/sagacity/sqltoy/utils/SqlUtil.java @@ -749,7 +749,10 @@ public static String clearMark(String sql) { int markIndex = sql.indexOf("", markIndex); - if (endMarkIndex == -1 || endMarkIndex == sql.length() - 3) { + // update 2024-7-8 兼容sql中存在收尾的情况 + if (endMarkIndex == -1) { + break; + } else if (endMarkIndex == sql.length() - 3) { sql = sql.substring(0, markIndex); break; } else { @@ -761,7 +764,10 @@ public static String clearMark(String sql) { markIndex = StringUtil.matchIndex(sql, maskPattern); while (markIndex != -1) { endMarkIndex = sql.indexOf("*/", markIndex); - if (endMarkIndex == -1 || endMarkIndex == sql.length() - 2) { + // update 2024-7-8 兼容sql中存在/* 但没有*/收尾的情况 + if (endMarkIndex == -1) { + break; + } else if (endMarkIndex == sql.length() - 2) { sql = sql.substring(0, markIndex); break; } else { diff --git a/trunk/sqltoy-orm-core/src/test/java/org/sagacity/sqltoy/config/SqlConfigParseUtilsTest.java b/trunk/sqltoy-orm-core/src/test/java/org/sagacity/sqltoy/config/SqlConfigParseUtilsTest.java index 5f2b25257..ef1719e03 100644 --- a/trunk/sqltoy-orm-core/src/test/java/org/sagacity/sqltoy/config/SqlConfigParseUtilsTest.java +++ b/trunk/sqltoy-orm-core/src/test/java/org/sagacity/sqltoy/config/SqlConfigParseUtilsTest.java @@ -394,7 +394,7 @@ public void testOverSizeIn6() throws Exception { @Test public void testLike() throws Exception { - String sql = "select * from table t where t.name ilike :name and t.desc like :desc"; + String sql = "select * from table t where t.name ilike N:name and t.desc like :desc"; SqlToyResult result = SqlConfigParseUtils.processSql(sql, new String[] { "name", "desc" }, new Object[] { "张三", "验证" }); From 29105187999f6a4b0bff13ef11143749e76e5823 Mon Sep 17 00:00:00 2001 From: zhongxuchen Date: Thu, 11 Jul 2024 22:45:49 +0800 Subject: [PATCH 3/7] =?UTF-8?q?=E6=9B=B4=E6=96=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../plugins/function/FunctionUtils.java | 6 +++- .../sqltoy/plugins/function/impl/Concat.java | 19 ++++++------ .../plugins/function/impl/ConcatWs.java | 3 ++ .../plugins/function/impl/DateFormat.java | 3 ++ .../sqltoy/plugins/function/impl/Decode.java | 3 ++ .../sqltoy/plugins/function/impl/Instr.java | 3 ++ .../sqltoy/plugins/function/impl/Length.java | 3 ++ .../sqltoy/plugins/function/impl/Nvl.java | 5 ++- .../sqltoy/plugins/function/impl/SubStr.java | 5 ++- .../sqltoy/plugins/function/impl/ToChar.java | 2 +- .../sqltoy/plugins/function/impl/ToDate.java | 31 +++++++++---------- .../sqltoy/plugins/function/impl/Trim.java | 3 ++ 12 files changed, 57 insertions(+), 29 deletions(-) diff --git a/trunk/sqltoy-orm-core/src/main/java/org/sagacity/sqltoy/plugins/function/FunctionUtils.java b/trunk/sqltoy-orm-core/src/main/java/org/sagacity/sqltoy/plugins/function/FunctionUtils.java index d77257973..0fc4accd3 100644 --- a/trunk/sqltoy-orm-core/src/main/java/org/sagacity/sqltoy/plugins/function/FunctionUtils.java +++ b/trunk/sqltoy-orm-core/src/main/java/org/sagacity/sqltoy/plugins/function/FunctionUtils.java @@ -117,7 +117,11 @@ private static String replaceFunction(String sqlContent, int dbType, IFunction f if (StringUtil.matches(functionParams, function.regex())) { functionParams = replaceFunction(functionParams, dbType, function); } - args = StringUtil.splitExcludeSymMark(functionParams, ",", SqlToyConstants.filters); + if (functionParams.trim().equals("")) { + args = null; + } else { + args = StringUtil.splitExcludeSymMark(functionParams, ",", SqlToyConstants.filters); + } } else { args = null; endMarkIndex = matcher.end() - 1; diff --git a/trunk/sqltoy-orm-core/src/main/java/org/sagacity/sqltoy/plugins/function/impl/Concat.java b/trunk/sqltoy-orm-core/src/main/java/org/sagacity/sqltoy/plugins/function/impl/Concat.java index 8e92fee93..4832874a5 100644 --- a/trunk/sqltoy-orm-core/src/main/java/org/sagacity/sqltoy/plugins/function/impl/Concat.java +++ b/trunk/sqltoy-orm-core/src/main/java/org/sagacity/sqltoy/plugins/function/impl/Concat.java @@ -45,19 +45,20 @@ public Pattern regex() { */ @Override public String wrap(int dialect, String functionName, boolean hasArgs, String... args) { + if (args == null || args.length < 3) { + return super.IGNORE; + } // 只针对oracle数据库,其他数据库原样返回 if (dialect == DBType.ORACLE || dialect == DBType.ORACLE11) { - // 超过2个参数(oracle 支持2个参数) - if (args != null && args.length > 2) { - StringBuilder result = new StringBuilder(); - for (int i = 0; i < args.length; i++) { - if (i > 0) { - result.append("||"); - } - result.append(args[i].replace("\\'", "''")); + // 超过2个参数(oracle 支持2个参数 + StringBuilder result = new StringBuilder(); + for (int i = 0; i < args.length; i++) { + if (i > 0) { + result.append("||"); } - return result.toString(); + result.append(args[i].replace("\\'", "''")); } + return result.toString(); } return super.IGNORE; } diff --git a/trunk/sqltoy-orm-core/src/main/java/org/sagacity/sqltoy/plugins/function/impl/ConcatWs.java b/trunk/sqltoy-orm-core/src/main/java/org/sagacity/sqltoy/plugins/function/impl/ConcatWs.java index 9270b7eb3..3acf191a7 100644 --- a/trunk/sqltoy-orm-core/src/main/java/org/sagacity/sqltoy/plugins/function/impl/ConcatWs.java +++ b/trunk/sqltoy-orm-core/src/main/java/org/sagacity/sqltoy/plugins/function/impl/ConcatWs.java @@ -45,6 +45,9 @@ public Pattern regex() { */ @Override public String wrap(int dialect, String functionName, boolean hasArgs, String... args) { + if (args == null || args.length < 2) { + return super.IGNORE; + } // oracle 不支持concat_ws if (dialect == DBType.ORACLE || dialect == DBType.ORACLE11) { StringBuilder result = new StringBuilder(); diff --git a/trunk/sqltoy-orm-core/src/main/java/org/sagacity/sqltoy/plugins/function/impl/DateFormat.java b/trunk/sqltoy-orm-core/src/main/java/org/sagacity/sqltoy/plugins/function/impl/DateFormat.java index 0be792a58..a0a45df83 100644 --- a/trunk/sqltoy-orm-core/src/main/java/org/sagacity/sqltoy/plugins/function/impl/DateFormat.java +++ b/trunk/sqltoy-orm-core/src/main/java/org/sagacity/sqltoy/plugins/function/impl/DateFormat.java @@ -46,6 +46,9 @@ public Pattern regex() { */ @Override public String wrap(int dialect, String functionName, boolean hasArgs, String... args) { + if (args == null || args.length < 2) { + return super.IGNORE; + } String format; switch (dialect) { case DBType.POSTGRESQL: diff --git a/trunk/sqltoy-orm-core/src/main/java/org/sagacity/sqltoy/plugins/function/impl/Decode.java b/trunk/sqltoy-orm-core/src/main/java/org/sagacity/sqltoy/plugins/function/impl/Decode.java index c9ad1f66e..b8aa87ab8 100644 --- a/trunk/sqltoy-orm-core/src/main/java/org/sagacity/sqltoy/plugins/function/impl/Decode.java +++ b/trunk/sqltoy-orm-core/src/main/java/org/sagacity/sqltoy/plugins/function/impl/Decode.java @@ -39,6 +39,9 @@ public String dialects() { */ @Override public String wrap(int dialect, String functionName, boolean hasArgs, String... args) { + if (args == null || args.length < 2) { + return super.IGNORE; + } /* * if (dialect == DBType.MYSQL || dialect == DBType.MYSQL8) { return * wrapArgs("ELT", args); } else diff --git a/trunk/sqltoy-orm-core/src/main/java/org/sagacity/sqltoy/plugins/function/impl/Instr.java b/trunk/sqltoy-orm-core/src/main/java/org/sagacity/sqltoy/plugins/function/impl/Instr.java index 6812846a3..ce2f0f3c7 100644 --- a/trunk/sqltoy-orm-core/src/main/java/org/sagacity/sqltoy/plugins/function/impl/Instr.java +++ b/trunk/sqltoy-orm-core/src/main/java/org/sagacity/sqltoy/plugins/function/impl/Instr.java @@ -45,6 +45,9 @@ public Pattern regex() { */ @Override public String wrap(int dialect, String functionName, boolean hasArgs, String... args) { + if (args == null || args.length == 0) { + return super.IGNORE; + } String[] realArgs; String funLow = functionName.toLowerCase(); if ("position".equals(funLow)) { diff --git a/trunk/sqltoy-orm-core/src/main/java/org/sagacity/sqltoy/plugins/function/impl/Length.java b/trunk/sqltoy-orm-core/src/main/java/org/sagacity/sqltoy/plugins/function/impl/Length.java index 1db365d87..0d6705f63 100644 --- a/trunk/sqltoy-orm-core/src/main/java/org/sagacity/sqltoy/plugins/function/impl/Length.java +++ b/trunk/sqltoy-orm-core/src/main/java/org/sagacity/sqltoy/plugins/function/impl/Length.java @@ -45,6 +45,9 @@ public Pattern regex() { */ @Override public String wrap(int dialect, String functionName, boolean hasArgs, String... args) { + if (args == null || args.length == 0) { + return super.IGNORE; + } String funLow = functionName.toLowerCase(); if (dialect == DBType.SQLSERVER) { if ("datalength".equals(funLow)) { diff --git a/trunk/sqltoy-orm-core/src/main/java/org/sagacity/sqltoy/plugins/function/impl/Nvl.java b/trunk/sqltoy-orm-core/src/main/java/org/sagacity/sqltoy/plugins/function/impl/Nvl.java index e1239cb1e..99fbc23a7 100644 --- a/trunk/sqltoy-orm-core/src/main/java/org/sagacity/sqltoy/plugins/function/impl/Nvl.java +++ b/trunk/sqltoy-orm-core/src/main/java/org/sagacity/sqltoy/plugins/function/impl/Nvl.java @@ -47,6 +47,9 @@ public Pattern regex() { */ @Override public String wrap(int dialect, String functionName, boolean hasArgs, String... args) { + if (args == null || args.length == 0) { + return super.IGNORE; + } String funLow = functionName.toLowerCase(); if (dialect == DBType.SQLSERVER) { return wrapArgs("isnull", args); @@ -56,7 +59,7 @@ public String wrap(int dialect, String functionName, boolean hasArgs, String... return wrapArgs("coalesce", args); } if (dialect == DBType.MYSQL || dialect == DBType.TIDB || dialect == DBType.MYSQL57) { - if (args.length == 1) { + if (args != null && args.length == 1) { return wrapArgs("isnull", args); } return wrapArgs("ifnull", args); diff --git a/trunk/sqltoy-orm-core/src/main/java/org/sagacity/sqltoy/plugins/function/impl/SubStr.java b/trunk/sqltoy-orm-core/src/main/java/org/sagacity/sqltoy/plugins/function/impl/SubStr.java index 0373571ee..bbe791424 100644 --- a/trunk/sqltoy-orm-core/src/main/java/org/sagacity/sqltoy/plugins/function/impl/SubStr.java +++ b/trunk/sqltoy-orm-core/src/main/java/org/sagacity/sqltoy/plugins/function/impl/SubStr.java @@ -38,9 +38,12 @@ public Pattern regex() { */ @Override public String wrap(int dialect, String functionName, boolean hasArgs, String... args) { + if (args == null || args.length == 0) { + return super.IGNORE; + } if (dialect == DBType.POSTGRESQL || dialect == DBType.POSTGRESQL15 || dialect == DBType.GAUSSDB || dialect == DBType.MOGDB || dialect == DBType.SQLSERVER || dialect == DBType.H2) { - if (dialect == DBType.SQLSERVER && args != null && args.length == 2) { + if (dialect == DBType.SQLSERVER && args.length == 2) { return "substring(" + args[0] + "," + args[1] + ",len(" + args[0] + "))"; } return wrapArgs("substring", args); diff --git a/trunk/sqltoy-orm-core/src/main/java/org/sagacity/sqltoy/plugins/function/impl/ToChar.java b/trunk/sqltoy-orm-core/src/main/java/org/sagacity/sqltoy/plugins/function/impl/ToChar.java index 536a3731f..c90299c3e 100644 --- a/trunk/sqltoy-orm-core/src/main/java/org/sagacity/sqltoy/plugins/function/impl/ToChar.java +++ b/trunk/sqltoy-orm-core/src/main/java/org/sagacity/sqltoy/plugins/function/impl/ToChar.java @@ -29,7 +29,7 @@ public String dialects() { */ @Override public String wrap(int dialect, String functionName, boolean hasArgs, String... args) { - if (args.length == 1) { + if (args == null || args.length < 2) { return super.IGNORE; } String format; diff --git a/trunk/sqltoy-orm-core/src/main/java/org/sagacity/sqltoy/plugins/function/impl/ToDate.java b/trunk/sqltoy-orm-core/src/main/java/org/sagacity/sqltoy/plugins/function/impl/ToDate.java index e83f6ddb8..b60b0f2a2 100644 --- a/trunk/sqltoy-orm-core/src/main/java/org/sagacity/sqltoy/plugins/function/impl/ToDate.java +++ b/trunk/sqltoy-orm-core/src/main/java/org/sagacity/sqltoy/plugins/function/impl/ToDate.java @@ -39,8 +39,11 @@ public Pattern regex() { */ @Override public String wrap(int dialect, String functionName, boolean hasArgs, String... args) { + if (args == null || args.length == 0) { + return super.IGNORE; + } if (dialect == DBType.SQLSERVER) { - if (args != null && args.length == 1) { + if (args.length == 1) { if (args[0].length() > 12) { return "convert(datetime," + args[0] + ")"; } @@ -48,26 +51,22 @@ public String wrap(int dialect, String functionName, boolean hasArgs, String... } } if (dialect == DBType.ORACLE || dialect == DBType.ORACLE11) { - if (args != null) { - if (args.length > 1) { - return wrapArgs("to_date", args); + if (args.length > 1) { + return wrapArgs("to_date", args); + } else { + if (args[0].length() > 12) { + return "to_date(" + args[0] + ",'yyyy-MM-dd HH:mm:ss')"; } else { - if (args[0].length() > 12) { - return "to_date(" + args[0] + ",'yyyy-MM-dd HH:mm:ss')"; - } else { - return "to_date(" + args[0] + ",'yyyy-MM-dd')"; - } + return "to_date(" + args[0] + ",'yyyy-MM-dd')"; } } } if (dialect == DBType.H2) { - if (args != null) { - if (args != null && args.length == 1) { - if (args[0].length() > 12) { - return "formatdatetime(" + args[0] + ",'yyyy-MM-dd HH:mm:ss')"; - } else { - return "formatdatetime(" + args[0] + ",'yyyy-MM-dd')"; - } + if (args.length == 1) { + if (args[0].length() > 12) { + return "formatdatetime(" + args[0] + ",'yyyy-MM-dd HH:mm:ss')"; + } else { + return "formatdatetime(" + args[0] + ",'yyyy-MM-dd')"; } } } diff --git a/trunk/sqltoy-orm-core/src/main/java/org/sagacity/sqltoy/plugins/function/impl/Trim.java b/trunk/sqltoy-orm-core/src/main/java/org/sagacity/sqltoy/plugins/function/impl/Trim.java index 815e55245..abe427848 100644 --- a/trunk/sqltoy-orm-core/src/main/java/org/sagacity/sqltoy/plugins/function/impl/Trim.java +++ b/trunk/sqltoy-orm-core/src/main/java/org/sagacity/sqltoy/plugins/function/impl/Trim.java @@ -45,6 +45,9 @@ public Pattern regex() { */ @Override public String wrap(int dialect, String functionName, boolean hasArgs, String... args) { + if (args == null || args.length == 0) { + return super.IGNORE; + } if (dialect == DBType.SQLSERVER) { return "rtrim(ltrim(" + args[0] + "))"; } From 9cf1da01ed9bb784c4e4e206d4a73ef96d450149 Mon Sep 17 00:00:00 2001 From: zhongxuchen Date: Fri, 12 Jul 2024 12:55:55 +0800 Subject: [PATCH 4/7] =?UTF-8?q?=E6=9B=B4=E6=96=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- trunk/sqltoy-orm-core/pom.xml | 2 +- .../org/sagacity/sqltoy/plugins/function/FunctionUtils.java | 2 +- .../java/org/sagacity/sqltoy/plugins/function/impl/Nvl.java | 2 +- trunk/sqltoy-orm-solon-plugin/pom.xml | 6 +++--- trunk/sqltoy-orm-spring-starter/pom.xml | 2 +- trunk/sqltoy-orm-spring/pom.xml | 4 ++-- 6 files changed, 9 insertions(+), 9 deletions(-) diff --git a/trunk/sqltoy-orm-core/pom.xml b/trunk/sqltoy-orm-core/pom.xml index feb327933..2b43e57ac 100644 --- a/trunk/sqltoy-orm-core/pom.xml +++ b/trunk/sqltoy-orm-core/pom.xml @@ -3,7 +3,7 @@ xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> 4.0.0 com.sagframe - 5.6.11.RC4 + 5.6.11.RC8 sagacity-sqltoy sqltoy core code sagacity-sqltoy diff --git a/trunk/sqltoy-orm-core/src/main/java/org/sagacity/sqltoy/plugins/function/FunctionUtils.java b/trunk/sqltoy-orm-core/src/main/java/org/sagacity/sqltoy/plugins/function/FunctionUtils.java index 0fc4accd3..2411ee58f 100644 --- a/trunk/sqltoy-orm-core/src/main/java/org/sagacity/sqltoy/plugins/function/FunctionUtils.java +++ b/trunk/sqltoy-orm-core/src/main/java/org/sagacity/sqltoy/plugins/function/FunctionUtils.java @@ -117,7 +117,7 @@ private static String replaceFunction(String sqlContent, int dbType, IFunction f if (StringUtil.matches(functionParams, function.regex())) { functionParams = replaceFunction(functionParams, dbType, function); } - if (functionParams.trim().equals("")) { + if (functionParams == null || functionParams.trim().equals("")) { args = null; } else { args = StringUtil.splitExcludeSymMark(functionParams, ",", SqlToyConstants.filters); diff --git a/trunk/sqltoy-orm-core/src/main/java/org/sagacity/sqltoy/plugins/function/impl/Nvl.java b/trunk/sqltoy-orm-core/src/main/java/org/sagacity/sqltoy/plugins/function/impl/Nvl.java index 99fbc23a7..37309fe9a 100644 --- a/trunk/sqltoy-orm-core/src/main/java/org/sagacity/sqltoy/plugins/function/impl/Nvl.java +++ b/trunk/sqltoy-orm-core/src/main/java/org/sagacity/sqltoy/plugins/function/impl/Nvl.java @@ -59,7 +59,7 @@ public String wrap(int dialect, String functionName, boolean hasArgs, String... return wrapArgs("coalesce", args); } if (dialect == DBType.MYSQL || dialect == DBType.TIDB || dialect == DBType.MYSQL57) { - if (args != null && args.length == 1) { + if (args.length == 1) { return wrapArgs("isnull", args); } return wrapArgs("ifnull", args); diff --git a/trunk/sqltoy-orm-solon-plugin/pom.xml b/trunk/sqltoy-orm-solon-plugin/pom.xml index 5e8191830..ac51f7d57 100644 --- a/trunk/sqltoy-orm-solon-plugin/pom.xml +++ b/trunk/sqltoy-orm-solon-plugin/pom.xml @@ -5,7 +5,7 @@ 4.0.0 com.sagframe - 5.6.11.RC4 + 5.6.11.RC8 sagacity-sqltoy-solon-plugin sagacity-sqltoy-solon-plugin @@ -16,8 +16,8 @@ UTF-8 - 2.8.4 - 1.6.4 + 2.8.5 + 1.6.5 3.12.14 2.0.13 3.1.8 diff --git a/trunk/sqltoy-orm-spring-starter/pom.xml b/trunk/sqltoy-orm-spring-starter/pom.xml index 27e5abec9..3124ce161 100644 --- a/trunk/sqltoy-orm-spring-starter/pom.xml +++ b/trunk/sqltoy-orm-spring-starter/pom.xml @@ -4,7 +4,7 @@ xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd"> 4.0.0 com.sagframe - 5.6.11.RC4 + 5.6.11.RC8 sagacity-sqltoy-spring-starter sagacity-sqltoy-spring-starter sqltoy springboot starter diff --git a/trunk/sqltoy-orm-spring/pom.xml b/trunk/sqltoy-orm-spring/pom.xml index c97ed1f19..ffaf02c79 100644 --- a/trunk/sqltoy-orm-spring/pom.xml +++ b/trunk/sqltoy-orm-spring/pom.xml @@ -3,14 +3,14 @@ xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> 4.0.0 com.sagframe - 5.6.11.RC4 + 5.6.11.RC8 sagacity-sqltoy-spring sagacity-sqltoy-spring sagacity-sqltoy-spring https://github.com/sagframe/sagacity-sqltoy UTF-8 - 6.1.10 + 6.1.11 3.2.7 3.2.7 4.2.7 From 656ab22249558873277fc4ed4baaa133d05ef94b Mon Sep 17 00:00:00 2001 From: zhongxuchen Date: Fri, 12 Jul 2024 17:12:06 +0800 Subject: [PATCH 5/7] Update README.md --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index 47cc8881d..249267b65 100644 --- a/README.md +++ b/README.md @@ -46,7 +46,7 @@ https://github.com/sagframe/sqltoy-online-doc/blob/master/docs/sqltoy/search.md # 码云地址: https://gitee.com/sagacity/sagacity-sqltoy # 最新版本 -* 5.6.10 LTS (jdk17+/springboot3.x)/5.6.10.jre8 (兼容5.2.x/5.3.x版本) 发版日期: 2024-5-27 +* 5.6.11 LTS (jdk17+/springboot3.x)/5.6.11.jre8 (兼容5.2.x/5.3.x版本) 发版日期: 2024-7-12 ```xml com.sagframe From 0378be4cfbf164f2bc3d72f4b3a94979b2147e03 Mon Sep 17 00:00:00 2001 From: zhongxuchen Date: Fri, 12 Jul 2024 17:12:26 +0800 Subject: [PATCH 6/7] Update README.md --- README.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index 249267b65..b32f41886 100644 --- a/README.md +++ b/README.md @@ -52,8 +52,8 @@ https://github.com/sagframe/sqltoy-online-doc/blob/master/docs/sqltoy/search.md com.sagframe sagacity-sqltoy-spring-starter - - 5.6.10 + + 5.6.11 ``` * 5.2.105 LTS (jdk1.8+) 发版日期: 2024-6-6 From 4fdcbbb0029a016529cf24cbcbaea0fe67cdfd9b Mon Sep 17 00:00:00 2001 From: zhongxuchen Date: Fri, 12 Jul 2024 17:16:12 +0800 Subject: [PATCH 7/7] =?UTF-8?q?=E6=9B=B4=E6=96=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- trunk/sqltoy-orm-core/pom.xml | 2 +- trunk/sqltoy-orm-solon-plugin/pom.xml | 2 +- trunk/sqltoy-orm-spring-starter/pom.xml | 2 +- trunk/sqltoy-orm-spring/pom.xml | 2 +- 4 files changed, 4 insertions(+), 4 deletions(-) diff --git a/trunk/sqltoy-orm-core/pom.xml b/trunk/sqltoy-orm-core/pom.xml index 2b43e57ac..01ac141c4 100644 --- a/trunk/sqltoy-orm-core/pom.xml +++ b/trunk/sqltoy-orm-core/pom.xml @@ -3,7 +3,7 @@ xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> 4.0.0 com.sagframe - 5.6.11.RC8 + 5.6.11 sagacity-sqltoy sqltoy core code sagacity-sqltoy diff --git a/trunk/sqltoy-orm-solon-plugin/pom.xml b/trunk/sqltoy-orm-solon-plugin/pom.xml index ac51f7d57..fad5d0879 100644 --- a/trunk/sqltoy-orm-solon-plugin/pom.xml +++ b/trunk/sqltoy-orm-solon-plugin/pom.xml @@ -5,7 +5,7 @@ 4.0.0 com.sagframe - 5.6.11.RC8 + 5.6.11 sagacity-sqltoy-solon-plugin sagacity-sqltoy-solon-plugin diff --git a/trunk/sqltoy-orm-spring-starter/pom.xml b/trunk/sqltoy-orm-spring-starter/pom.xml index 3124ce161..e50ce13ba 100644 --- a/trunk/sqltoy-orm-spring-starter/pom.xml +++ b/trunk/sqltoy-orm-spring-starter/pom.xml @@ -4,7 +4,7 @@ xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd"> 4.0.0 com.sagframe - 5.6.11.RC8 + 5.6.11 sagacity-sqltoy-spring-starter sagacity-sqltoy-spring-starter sqltoy springboot starter diff --git a/trunk/sqltoy-orm-spring/pom.xml b/trunk/sqltoy-orm-spring/pom.xml index ffaf02c79..b4b4b9f64 100644 --- a/trunk/sqltoy-orm-spring/pom.xml +++ b/trunk/sqltoy-orm-spring/pom.xml @@ -3,7 +3,7 @@ xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> 4.0.0 com.sagframe - 5.6.11.RC8 + 5.6.11 sagacity-sqltoy-spring sagacity-sqltoy-spring sagacity-sqltoy-spring