From 1e09143a006e03f31587314a9b6688ca315ef799 Mon Sep 17 00:00:00 2001 From: "Yuan.Wang" Date: Fri, 22 Dec 2023 11:18:41 +0800 Subject: [PATCH] =?UTF-8?q?REPORT-111169=20=E6=95=B0=E6=8D=AE=E9=9B=86?= =?UTF-8?q?=E5=90=AB=E6=9C=89=E6=B3=A8=E9=87=8A=E7=9A=84=E5=8F=82=E6=95=B0?= =?UTF-8?q?=EF=BC=8C=E4=BD=86=E5=8F=82=E6=95=B0=E4=BE=9D=E7=84=B6=E7=94=9F?= =?UTF-8?q?=E6=95=88?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../tabledatapane/DBTableDataPane.java | 14 +++++-- .../tabledatapane/DBTableDataPaneTest.java | 41 +++++++++++++++++++ 2 files changed, 51 insertions(+), 4 deletions(-) create mode 100644 designer-base/src/test/java/com/fr/design/data/tabledata/tabledatapane/DBTableDataPaneTest.java diff --git a/designer-base/src/main/java/com/fr/design/data/tabledata/tabledatapane/DBTableDataPane.java b/designer-base/src/main/java/com/fr/design/data/tabledata/tabledatapane/DBTableDataPane.java index ed2417449c..4a0d1f665e 100644 --- a/designer-base/src/main/java/com/fr/design/data/tabledata/tabledatapane/DBTableDataPane.java +++ b/designer-base/src/main/java/com/fr/design/data/tabledata/tabledatapane/DBTableDataPane.java @@ -61,6 +61,7 @@ import com.fr.stable.ArrayUtils; import com.fr.stable.ParameterProvider; import com.fr.stable.StringUtils; import com.fr.workspace.WorkContext; +import org.jetbrains.annotations.NotNull; import javax.swing.BorderFactory; import javax.swing.Box; @@ -416,10 +417,7 @@ public class DBTableDataPane extends AbstractTableDataPane implemen } private void checkParameter() { - String[] paramTexts = new String[2]; - paramTexts[0] = SqlUtils.clearSqlComments(this.sqlTextPane.getText()); - paramTexts[1] = SqlUtils.clearSqlComments(this.pageQuery); - Parameter[] parameters = ParameterHelper.analyze4Parameters(paramTexts, false); + Parameter[] parameters = getParameters(); if (parameters.length < 1 && this.editorPane.update().size() < 1) { return; @@ -443,6 +441,14 @@ public class DBTableDataPane extends AbstractTableDataPane implemen refreshParameters(); } + @NotNull + private Parameter[] getParameters() { + String[] paramTexts = new String[2]; + paramTexts[0] = SqlUtils.clearSqlComments(this.sqlTextPane.getText()); + paramTexts[1] = SqlUtils.clearSqlComments(this.pageQuery); + return ParameterHelper.analyze4Parameters(paramTexts, false); + } + @Override public void populateBean(DBTableData dbTableData) { this.dbTableData = dbTableData; diff --git a/designer-base/src/test/java/com/fr/design/data/tabledata/tabledatapane/DBTableDataPaneTest.java b/designer-base/src/test/java/com/fr/design/data/tabledata/tabledatapane/DBTableDataPaneTest.java new file mode 100644 index 0000000000..e549f13461 --- /dev/null +++ b/designer-base/src/test/java/com/fr/design/data/tabledata/tabledatapane/DBTableDataPaneTest.java @@ -0,0 +1,41 @@ +package com.fr.design.data.tabledata.tabledatapane; + +import com.fr.base.Parameter; +import com.fr.design.data.datapane.sqlpane.SQLEditPane; +import com.fr.invoke.Reflect; +import junit.framework.TestCase; +import org.junit.Assert; + +/** + * @author Yuan.Wang + * @since 11.0 + * Created on 2023/12/22 + */ +public class DBTableDataPaneTest extends TestCase { + + public void testGetParameters() { + DBTableDataPane pane = new DBTableDataPane(); + SQLEditPane editPane = new SQLEditPane(); + String sql = "select distinct 类别ID from S产品\n" + + "where 1=1\n" + + "order by 类别ID\n" + + "--${ if(len(comboBox0) = 0,\"\",\"AND 类别00ID = '\" + comboBox0 + \"'\")}"; + + String sql1 = "select distinct 类别ID from S产品\n" + + "where 1=1\n" + + "order by 类别ID\n" + + "${ if(len(comboBox0) = 0,\"\",\"AND 类别00ID = '\" + comboBox0 + \"'\")}"; + editPane.setText(sql); + Reflect.on(pane).set("sqlTextPane", editPane); + Reflect.on(pane).set("pageQuery", sql); + + Parameter[] parameters = Reflect.on(pane).call("getParameters").get(); + + Assert.assertEquals(0, parameters.length); + editPane.setText(sql1); + + parameters = Reflect.on(pane).call("getParameters").get(); + Assert.assertEquals(1, parameters.length); + Assert.assertEquals(parameters[0].getName(), "comboBox0"); + } +} \ No newline at end of file