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