fix format bug

This commit is contained in:
Looly
2023-08-04 15:38:42 +08:00
parent 9a82679dd9
commit 790161264b
3 changed files with 28 additions and 1 deletions

View File

@@ -615,6 +615,15 @@ public class SqlBuilder implements Builder<String> {
return this.paramValues.toArray(new Object[0]);
}
/**
* 格式化SQL语句
* @return SqlBuilder
*/
public SqlBuilder format() {
this.sql.replace(0, this.sql.length(), SqlFormatter.format(this.sql.toString()));
return this;
}
/**
* 构建默认打印SQL日志
*

View File

@@ -122,6 +122,12 @@ public class SqlFormatter {
t = this.tokens.nextToken();
this.token += t;
} while (!"\"".equals(t));
} else if ("`".equals(this.token)) {
String t;
do {
t = this.tokens.nextToken();
this.token += t;
} while (!"`".equals(t));
}
if ((this.afterByOrSetOrFromOrSelect) && (",".equals(this.token))) {
@@ -320,7 +326,7 @@ public class SqlFormatter {
}
private static boolean isFunctionName(final String tok) {
if(StrUtil.isEmpty(tok)){
if (StrUtil.isEmpty(tok)) {
return true;
}
final char begin = tok.charAt(0);