Skip to content

Commit

Permalink
bugfix: fix sql exception with postgresql in module console (#4661)
Browse files Browse the repository at this point in the history
  • Loading branch information
YSF-A committed Jun 6, 2022
1 parent 8ac7503 commit 29d83e8
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 2 deletions.
4 changes: 3 additions & 1 deletion changes/en-us/develop.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ Add changes here for all PR submitted to the develop branch.


### bugfix:

- [[#4661](https://github.com/seata/seata/pull/4661)] Fix sql exception with PostgreSQL in module console

### optimize:
- [[#4650](https://github.com/seata/seata/pull/4650)] fix some security vulnerabilities
Expand All @@ -18,5 +18,7 @@ Thanks to these contributors for their code commits. Please report an unintended

<!-- Please make sure your Github ID is in the list below -->
- [slievrly](https://github.com/slievrly)
- [YSF-A](https://github.com/YSF-A)


Also, we receive many valuable issues, questions and advices from our community. Thanks for you all.
2 changes: 2 additions & 0 deletions changes/zh-cn/develop.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
### feature:

### bugfix:
- [[#4661](https://github.com/seata/seata/pull/4661)] 修复控制台中使用PostgreSQL出现的SQL异常

### optimize:
- [[#4650](https://github.com/seata/seata/pull/4650)] 修复安全漏洞
Expand All @@ -16,5 +17,6 @@

<!-- 请确保您的 GitHub ID 在以下列表中 -->
- [slievrly](https://github.com/slievrly)
- [YSF-A](https://github.com/YSF-A)

同时,我们收到了社区反馈的很多有价值的issue和建议,非常感谢大家。
7 changes: 6 additions & 1 deletion common/src/main/java/io/seata/common/util/PageUtil.java
Original file line number Diff line number Diff line change
Expand Up @@ -128,10 +128,15 @@ public static String countSql(String sourceSql, String dbType) {
switch (dbType) {
case "mysql":
case "h2":
case "postgresql":
case "oceanbase":
case "oracle":
return sourceSql.replaceAll("(?i)(?<=select)(.*)(?=from)", " count(1) ");
case "postgresql":
int lastIndexOfOrderBy = sourceSql.toLowerCase().lastIndexOf("order by");
if (lastIndexOfOrderBy != -1) {
return sourceSql.substring(0, lastIndexOfOrderBy).replaceAll("(?i)(?<=select)(.*)(?=from)", " count(1) ");
}
return sourceSql.replaceAll("(?i)(?<=select)(.*)(?=from)", " count(1) ");
default:
throw new NotSupportYetException("PageUtil not support this dbType:" + dbType);
}
Expand Down

0 comments on commit 29d83e8

Please sign in to comment.