mirror of
https://gitee.com/chinabugotech/hutool.git
synced 2025-07-21 15:09:48 +08:00
fix code
This commit is contained in:
@@ -426,11 +426,11 @@ public class Condition implements Cloneable, Serializable {
|
||||
// pr#2046@Github
|
||||
valuesForIn = (Collection<?>) value;
|
||||
} else if (value instanceof CharSequence) {
|
||||
valuesForIn = StrUtil.split((CharSequence) value, ',');
|
||||
valuesForIn = SplitUtil.split((CharSequence) value, StrUtil.COMMA);
|
||||
} else {
|
||||
valuesForIn = Arrays.asList(Convert.convert(Object[].class, value));
|
||||
}
|
||||
conditionStrBuilder.append(StrUtil.repeatAndJoin("?", valuesForIn.size(), ","));
|
||||
conditionStrBuilder.append(StrUtil.repeatAndJoin("?", valuesForIn.size(), StrUtil.COMMA));
|
||||
if (null != paramValues) {
|
||||
paramValues.addAll(valuesForIn);
|
||||
}
|
||||
@@ -490,13 +490,13 @@ public class Condition implements Cloneable, Serializable {
|
||||
}
|
||||
}
|
||||
|
||||
final List<String> strs = StrUtil.split(valueStr, CharUtil.SPACE, 2);
|
||||
final List<String> strs = SplitUtil.split(valueStr, StrUtil.SPACE, 2, true, false);
|
||||
if (strs.size() < 2) {
|
||||
return;
|
||||
}
|
||||
|
||||
// 处理常用符号和IN
|
||||
final String firstPart = strs.get(0).trim().toUpperCase();
|
||||
final String firstPart = strs.get(0).toUpperCase();
|
||||
if (OPERATORS.contains(firstPart)) {
|
||||
this.operator = firstPart;
|
||||
// 比较符号后跟大部分为数字,此处做转换(IN不做转换)
|
||||
@@ -514,7 +514,8 @@ public class Condition implements Cloneable, Serializable {
|
||||
|
||||
// 处理BETWEEN x AND y
|
||||
if (OPERATOR_BETWEEN.equals(firstPart)) {
|
||||
final List<String> betweenValueStrs = SplitUtil.splitTrimIgnoreCase(strs.get(1), LogicalOperator.AND.toString(), 2, true);
|
||||
final List<String> betweenValueStrs = SplitUtil.split(strs.get(1), LogicalOperator.AND.toString(),
|
||||
2, true, true, true);
|
||||
if (betweenValueStrs.size() < 2) {
|
||||
// 必须满足a AND b格式,不满足被当作普通值
|
||||
return;
|
||||
@@ -532,11 +533,10 @@ public class Condition implements Cloneable, Serializable {
|
||||
* @param value 值
|
||||
* @return 去掉引号后的值
|
||||
*/
|
||||
private static String unwrapQuote(String value) {
|
||||
private static String unwrapQuote(final String value) {
|
||||
if (null == value) {
|
||||
return null;
|
||||
}
|
||||
value = value.trim();
|
||||
|
||||
int from = 0;
|
||||
int to = value.length();
|
||||
@@ -562,8 +562,7 @@ public class Condition implements Cloneable, Serializable {
|
||||
* @param value 被转换的字符串值
|
||||
* @return 转换后的值
|
||||
*/
|
||||
private static Object tryToNumber(String value) {
|
||||
value = StrUtil.trim(value);
|
||||
private static Object tryToNumber(final String value) {
|
||||
if (false == NumberUtil.isNumber(value)) {
|
||||
return value;
|
||||
}
|
||||
|
@@ -2,8 +2,8 @@ package cn.hutool.db.sql;
|
||||
|
||||
import cn.hutool.core.collection.CollUtil;
|
||||
import cn.hutool.core.text.StrUtil;
|
||||
import cn.hutool.core.text.split.SplitUtil;
|
||||
import cn.hutool.core.util.ArrayUtil;
|
||||
import cn.hutool.core.util.CharUtil;
|
||||
import cn.hutool.db.Entity;
|
||||
|
||||
import java.io.Serializable;
|
||||
@@ -115,7 +115,11 @@ public class QuoteWrapper implements Serializable {
|
||||
|
||||
//对于Oracle这类数据库,表名中包含用户名需要单独拆分包装
|
||||
if (field.contains(StrUtil.DOT)) {
|
||||
final Collection<String> target = CollUtil.edit(StrUtil.split(field, CharUtil.DOT, 2), t -> StrUtil.format("{}{}{}", preWrapQuote, t, sufWrapQuote));
|
||||
final Collection<String> target = CollUtil.edit(
|
||||
// 用户名和表名不能包含空格
|
||||
SplitUtil.split(field, StrUtil.DOT, 2, true, false),
|
||||
// 用户名和表名都加引号
|
||||
t -> StrUtil.format("{}{}{}", preWrapQuote, t, sufWrapQuote));
|
||||
return CollUtil.join(target, StrUtil.DOT);
|
||||
}
|
||||
|
||||
|
@@ -2,6 +2,7 @@ package cn.hutool.db.meta;
|
||||
|
||||
import cn.hutool.core.collection.SetUtil;
|
||||
import cn.hutool.core.text.StrUtil;
|
||||
import cn.hutool.core.text.split.SplitUtil;
|
||||
import cn.hutool.db.ds.DSFactory;
|
||||
import org.junit.Assert;
|
||||
import org.junit.Test;
|
||||
@@ -33,7 +34,7 @@ public class MetaUtilTest {
|
||||
@Test
|
||||
public void getColumnNamesTest() {
|
||||
final String[] names = MetaUtil.getColumnNames(ds, "user");
|
||||
Assert.assertArrayEquals(StrUtil.splitToArray("id,name,age,birthday,gender", ','), names);
|
||||
Assert.assertArrayEquals(SplitUtil.splitToArray("id,name,age,birthday,gender", StrUtil.COMMA), names);
|
||||
}
|
||||
|
||||
@Test
|
||||
|
Reference in New Issue
Block a user