fix(hzya-nifi):修复 SQL Server 分页查询语法问题
- 优化 SQL Server 数据库的分页查询语句生成逻辑 - 修复 where 条件语句在 SQL 语句中的正确位置 - 添加 insertWhereClause 方法来处理 where 条件的插入 - 更新单元测试以验证新的分页查询语句生成逻辑
This commit is contained in:
parent
2015d502c1
commit
a07f92afa0
|
@ -2,8 +2,8 @@
|
|||
{
|
||||
"operation": "shift",
|
||||
"spec": {
|
||||
"pk_corp": "voucher.pk_corp",
|
||||
"pk_glorgbook": "voucher.pk_glorgbook",
|
||||
"corp_code": "voucher.pk_corp",
|
||||
"pk_glorgbook": "voucher.accbookCode",
|
||||
"pk_prepared": "voucher.pk_prepared",
|
||||
"vouchertype_shortname": "voucher.pk_vouchertype",
|
||||
"prepareddate": "voucher.prepareddate",
|
||||
|
|
|
@ -128,13 +128,19 @@ public class DevGeneratePaginatedSqlProcessor extends AbstractProcessor {
|
|||
} else if ("microsoft sql server".equals(dbType)) {
|
||||
StringBuffer montageSql = new StringBuffer();
|
||||
montageSql.append("WITH SortedData AS (");
|
||||
montageSql.append(baseSql);
|
||||
|
||||
if (!"".equals(whereClause)) {
|
||||
if (baseSql.toUpperCase().contains("WHERE")) {
|
||||
//替换为and
|
||||
whereClause = whereClause.replace("WHERE", "AND");
|
||||
}
|
||||
montageSql.append(whereClause);
|
||||
// if (baseSql.toUpperCase().contains("WHERE")) {
|
||||
// //替换为and
|
||||
// whereClause = whereClause.replace("WHERE", "AND");
|
||||
// }
|
||||
//where条件不能直接加载原始sql语句后面,否则order by xx asc where xxx,导致语法问题,而是要加载表名后面
|
||||
// montageSql.append(whereClause);
|
||||
whereClause = whereClause.replace("WHERE", "");
|
||||
// whereClause = whereClause.replace("AND", "");
|
||||
montageSql.append(insertWhereClause(baseSql, whereClause));
|
||||
} else {
|
||||
montageSql.append(baseSql);
|
||||
}
|
||||
if (baseSql.toUpperCase().contains("ORDER BY")) {
|
||||
//确保排序生效
|
||||
|
@ -191,7 +197,7 @@ public class DevGeneratePaginatedSqlProcessor extends AbstractProcessor {
|
|||
} else if ("microsoft sql server".equals(dbType)) {
|
||||
|
||||
whereClause = whereClause.replace("WHERE", "");
|
||||
whereClause = whereClause.replace("AND", "");
|
||||
// whereClause = whereClause.replace("AND", "");
|
||||
|
||||
StringBuffer splicingSql = new StringBuffer();
|
||||
splicingSql.append(baseSql);
|
||||
|
|
|
@ -0,0 +1,38 @@
|
|||
package com.hzya.frame;
|
||||
|
||||
import org.junit.Test;
|
||||
|
||||
import static org.junit.Assert.*;
|
||||
|
||||
/**
|
||||
* @Author:liuyang
|
||||
* @Package:com.hzya.frame
|
||||
* @Project:nifi-hzyadev-bundle
|
||||
* @name:DevGeneratePaginatedSqlProcessorTest
|
||||
* @Date:2025/7/30 18:22
|
||||
* @Filename:DevGeneratePaginatedSqlProcessorTest
|
||||
*/
|
||||
public class DevGeneratePaginatedSqlProcessorTest {
|
||||
|
||||
|
||||
@Test
|
||||
public void test01() throws Exception{
|
||||
String aaa = "\n" +
|
||||
"\tSELECT\n" +
|
||||
"\t\tpk_bdinfo AS pk_accassitem,\n" +
|
||||
"\t\tbdcode AS code,\n" +
|
||||
"\t\tbdname AS name,\n" +
|
||||
"\t\tpk_defdef AS pkDefdef,\n" +
|
||||
"\t\ttablename AS tablename,\n" +
|
||||
"\t\ttablepkname AS tablepkname,\n" +
|
||||
"\t\tdr AS dr,\n" +
|
||||
"\t\tts AS ts \n" +
|
||||
"\tFROM\n" +
|
||||
"\t\tbd_bdinfo \n" +
|
||||
"\tORDER BY\n" +
|
||||
"\t\tpk_bdinfo,\n" +
|
||||
"\tts ASC";
|
||||
String bbb = "1=1 and 2=2";
|
||||
System.out.println(DevGeneratePaginatedSqlProcessor.insertWhereClause(aaa, bbb));
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue