|
|
@@ -358,6 +358,8 @@ public class PrintServiceImpl implements PrintService {
|
|
|
queryString = queryString.replace("$P!{WHERE_CONDITION}", "where rownum = 0");
|
|
|
}
|
|
|
queryString = replaceOtherParameters(queryString, otherParameters);
|
|
|
+ // 因为获取列名只需要在编译模版时执行一次,所以这里获取数据速度虽然较慢,但是可以接受,
|
|
|
+ // 不必像获取行数 #getCount 一样,对返回的结果做限制,反而增加了出错的可能性
|
|
|
List<String> columnNames = getColumnNames(connection, queryString);
|
|
|
if (CollectionUtils.isEmpty(columnNames)) {
|
|
|
throw new SQLException("未查询到任何列:" + queryString);
|
|
|
@@ -758,13 +760,13 @@ public class PrintServiceImpl implements PrintService {
|
|
|
try {
|
|
|
// 如果直接在 sql 外用 count(1) 统计数目,当关联表多时,可能会出现错误
|
|
|
// ORA-01792: 表或视图中的最大列数为 1000
|
|
|
- // 报错主要发生在 select * 的情况下,但是不能这样判断,因为可能存在
|
|
|
+ // 报错主要发生在类似 select * 的情况下,但是不能直接这样判断,因为可能存在
|
|
|
// 1. select tt.*, pi_id from purchase t left join
|
|
|
- // 2. union 这样的情况,很难区分
|
|
|
- // 因此 1. 对于普通 sql ,将 select 后的字段改为 count(1)
|
|
|
+ // 2. union
|
|
|
+ // 这样的情况,很难区分,因此
|
|
|
+ // 1. 对于普通 sql ,将 select 后的字段改为 count(1)
|
|
|
// 2. 而最外层含有 group by 的 sql ,直接改为 count(1) 可能得到不止一行,结果也并非实际行数。再加上
|
|
|
- // group
|
|
|
- // by 的结果列数一般很小,所以可以在外面使用 count(1) ,一般不会超出 1000 行
|
|
|
+ // group by 的结果列数一般很小,所以可以在外面使用 count(1) ,一般不会超出 1000 行
|
|
|
// 3. union 外层使用 count(1)
|
|
|
String lowerSql = sql.toLowerCase();
|
|
|
if (!lowerSql.matches("[\\s\\S]+?group[\\s]+?by[\\s]+?[^)]+?")
|