|
|
@@ -766,12 +766,12 @@ public class PrintServiceImpl implements PrintService {
|
|
|
// by 的结果列数一般很小,所以可以在外面使用 count(1) ,一般不会超出 1000 行
|
|
|
String lowerSql = sql.toLowerCase();
|
|
|
if (!lowerSql.matches("[\\s\\S]+?group[\\s]+?by[\\s]+?[^)]+?")) {
|
|
|
- String regex = "[\\s\\S]+?from";
|
|
|
+ String regex = "([\\s\\S]+?from)[\\s]+?[^,]+?";
|
|
|
Pattern pattern = Pattern.compile(regex);
|
|
|
Matcher matcher = pattern.matcher(lowerSql);
|
|
|
if (matcher.find()) {
|
|
|
- int start = matcher.start();
|
|
|
- int end = matcher.end();
|
|
|
+ int start = matcher.start(1);
|
|
|
+ int end = matcher.end(1);
|
|
|
sql = sql.substring(0, start) + "select count(1) from" + sql.substring(end);
|
|
|
} else {
|
|
|
throw new IllegalStateException("sql 解析错误:未发现第一个 from");
|