mirror of
https://gitee.com/chinabugotech/hutool.git
synced 2025-04-19 03:01:48 +08:00
fix sql formater bug
This commit is contained in:
parent
eae7edc1ae
commit
2f4544bc23
@ -3,7 +3,7 @@
|
||||
|
||||
-------------------------------------------------------------------------------------------------------------
|
||||
|
||||
# 5.7.3 (2021-06-24)
|
||||
# 5.7.3 (2021-06-25)
|
||||
|
||||
### 🐣新特性
|
||||
* 【core 】 增加Convert.toSet方法(issue#I3XFG2@Gitee)
|
||||
@ -16,6 +16,7 @@
|
||||
* 【core 】 修复FormatCache中循环引用异常(pr#1673@Github)
|
||||
* 【core 】 修复IdcardUtil.getIdcardInfo.getProvinceCode获取为汉字的问题(issue#I3XP4Q@Gitee)
|
||||
* 【core 】 修复CollUtil.subtract使用非标准Set等空指针问题(issue#I3XN1Z@Gitee)
|
||||
* 【core 】 修复SqlFormatter部分SQL空指针问题(issue#I3XS44@Gitee)
|
||||
|
||||
-------------------------------------------------------------------------------------------------------------
|
||||
|
||||
|
@ -1,6 +1,11 @@
|
||||
package cn.hutool.db.sql;
|
||||
|
||||
import java.util.*;
|
||||
import cn.hutool.core.util.StrUtil;
|
||||
|
||||
import java.util.HashSet;
|
||||
import java.util.LinkedList;
|
||||
import java.util.Set;
|
||||
import java.util.StringTokenizer;
|
||||
|
||||
/**
|
||||
* SQL格式化器 from Hibernate
|
||||
@ -303,6 +308,9 @@ public class SqlFormatter {
|
||||
}
|
||||
|
||||
private static boolean isFunctionName(String tok) {
|
||||
if(StrUtil.isEmpty(tok)){
|
||||
return true;
|
||||
}
|
||||
char begin = tok.charAt(0);
|
||||
boolean isIdentifier = (Character.isJavaIdentifierStart(begin)) || ('"' == begin);
|
||||
return (isIdentifier) && (!LOGICAL.contains(tok)) && (!END_CLAUSES.contains(tok)) && (!QUANTIFIERS.contains(tok)) && (!DML.contains(tok)) && (!MISC.contains(tok));
|
||||
|
14
hutool-db/src/test/java/cn/hutool/db/sql/SqlFormatterTest.java
Executable file
14
hutool-db/src/test/java/cn/hutool/db/sql/SqlFormatterTest.java
Executable file
@ -0,0 +1,14 @@
|
||||
package cn.hutool.db.sql;
|
||||
|
||||
import org.junit.Test;
|
||||
|
||||
public class SqlFormatterTest {
|
||||
|
||||
@Test
|
||||
public void formatTest(){
|
||||
// issue#I3XS44@Gitee
|
||||
// 测试是否空指针错误
|
||||
String sql = "(select 1 from dual) union all (select 1 from dual)";
|
||||
SqlFormatter.format(sql);
|
||||
}
|
||||
}
|
Loading…
x
Reference in New Issue
Block a user