Repository: dbeaver/dbeaver
Issue: Get prompted every time a variable is referenced in a SQL script

### Description

I upgraded DBeaver Community Edition to version 22.3.3.202301211053 a few days ago. After this upgrade the behavior of the variables in DBeaver has changed., I use @set statements to setup values for the variable and was able to use them throughout my SQL scripts. The same scripts now kept prompting for the value of the variables. Looks like it does not use the values that I set in the script. Even after I entered the value in the "Bind parameters" dialog, it popped up each time the variable is used.

I have been searching to see if there is setting that I can control but to no avail... thinking of downgrading to 22.3.2,

Thanks

### DBeaver Version

Community Edition 22.3.3

### Operating System

Windows

### Database and driver

Snowflake

### Steps to reproduce

@set v_WorkFlow = Clone_Operations_Schema
@echo ${v_WorkFlow}, ${V_WORKFLOW}
select '${v_WorkFlow}';


### Additional context

_No response_

Changed files:
plugins/org.jkiss.dbeaver.model/src/org/jkiss/dbeaver/model/sql/SQLQueryParameter.java
test/org.jkiss.dbeaver.test.platform/src/org/jkiss/dbeaver/model/sql/parser/SQLScriptParserGenericsTest.java
plugins/org.jkiss.dbeaver.model.sql/src/org/jkiss/dbeaver/model/sql/parser/SQLScriptParser.java

diff --git a/plugins/org.jkiss.dbeaver.model.sql/src/org/jkiss/dbeaver/model/sql/parser/SQLScriptParser.java b/plugins/org.jkiss.dbeaver.model.sql/src/org/jkiss/dbeaver/model/sql/parser/SQLScriptParser.java
index 1dc5f278e1..b712d7f7cb 100644
--- a/plugins/org.jkiss.dbeaver.model.sql/src/org/jkiss/dbeaver/model/sql/parser/SQLScriptParser.java
+++ b/plugins/org.jkiss.dbeaver.model.sql/src/org/jkiss/dbeaver/model/sql/parser/SQLScriptParser.java
@@ -781,7 +781,13 @@ public class SQLScriptParser {
                         }
 
                         if (param == null) {
-                            param = new SQLQueryParameter(syntaxManager, orderPos, matcher.group(0), start, matcher.end() - matcher.start());
+                            param = new SQLQueryParameter(
+                                syntaxManager,
+                                orderPos,
+                                matcher.group(SQLQueryParameter.VARIABLE_NAME_GROUP_NAME).toUpperCase(Locale.ENGLISH),
+                                start,
+                                matcher.end() - matcher.start()
+                            );
                             if (parameters == null) {
                                 parameters = new ArrayList<>();
                             }
diff --git a/plugins/org.jkiss.dbeaver.model/src/org/jkiss/dbeaver/model/sql/SQLQueryParameter.java b/plugins/org.jkiss.dbeaver.model/src/org/jkiss/dbeaver/model/sql/SQLQueryParameter.java
index 5b12c7678b..dcab25dea1 100644
--- a/plugins/org.jkiss.dbeaver.model/src/org/jkiss/dbeaver/model/sql/SQLQueryParameter.java
+++ b/plugins/org.jkiss.dbeaver.model/src/org/jkiss/dbeaver/model/sql/SQLQueryParameter.java
@@ -25,9 +25,10 @@ import java.util.regex.Pattern;
  */
 public class SQLQueryParameter {
 
+    public static final String VARIABLE_NAME_GROUP_NAME = "pn";
 
-    private static final Pattern VARIABLE_PATTERN_SIMPLE = Pattern.compile("\\\\$\\\\{[a-z0-9_]+\\\\}", Pattern.CASE_INSENSITIVE);
-    private static final Pattern VARIABLE_PATTERN_FULL = Pattern.compile("\\\\$P?!?\\\\{[a-z0-9_]+\\\\}", Pattern.CASE_INSENSITIVE);
+    private static final Pattern VARIABLE_PATTERN_SIMPLE = Pattern.compile("\\\\$\\\\{(?<pn>[a-z0-9_]+)\\\\}", Pattern.CASE_INSENSITIVE);
+    private static final Pattern VARIABLE_PATTERN_FULL = Pattern.compile("\\\\$P?!?\\\\{(?<pn>[a-z0-9_]+)\\\\}", Pattern.CASE_INSENSITIVE);
 
 
     private final SQLSyntaxManager syntaxManager;
diff --git a/test/org.jkiss.dbeaver.test.platform/src/org/jkiss/dbeaver/model/sql/parser/SQLScriptParserGenericsTest.java b/test/org.jkiss.dbeaver.test.platform/src/org/jkiss/dbeaver/model/sql/parser/SQLScriptParserGenericsTest.java
index 7008710ba3..202f194b73 100644
--- a/test/org.jkiss.dbeaver.test.platform/src/org/jkiss/dbeaver/model/sql/parser/SQLScriptParserGenericsTest.java
+++ b/test/org.jkiss.dbeaver.test.platform/src/org/jkiss/dbeaver/model/sql/parser/SQLScriptParserGenericsTest.java
@@ -176,7 +176,7 @@ public class SQLScriptParserGenericsTest {
         }
         Assert.assertEquals(List.of("1", "SYs_B_1", "MyVar8", "ABC", "#d2"), actualParamNames);
     }
-    
+
     @Test
     public void parseVariables() throws DBException {
         List<String> inputParamNames = List.of("aBc", "PrE#%&@T", "a@c=");
@@ -191,6 +191,36 @@ public class SQLScriptParserGenericsTest {
         }
         Assert.assertEquals(List.of("ABC", "PRE#%&@T", "A@C="), actualParamNames);
     }
+
+    @Test
+    public void parseVariablesInStrings() throws DBException {
+        List<String> inputParamNames = List.of("aBc", "PrET", "ac");
+        StringJoiner joiner = new StringJoiner(", ", "select ", " from dual");
+        inputParamNames.stream().forEach(p -> joiner.add("'${" + p + "}'"));
+        String query = joiner.toString();
+        SQLParserContext context = createParserContext(setDialect("snowflake"), query);
+        List<SQLQueryParameter> params = SQLScriptParser.parseParametersAndVariables(context, 0, query.length());
+        List<String> actualParamNames = new ArrayList<String>();
+        for (SQLQueryParameter sqlQueryParameter : params) {
+            actualParamNames.add(sqlQueryParameter.getName());
+        }
+        Assert.assertEquals(List.of("ABC", "PRET", "AC"), actualParamNames);
+    }
+
+    @Test
+    public void parseVariablesInComment() throws DBException {
+        List<String> inputParamNames = List.of("aBc", "PrET", "ac");
+        StringJoiner joiner = new StringJoiner(", ", "-- ", " ");
+        inputParamNames.stream().forEach(p -> joiner.add("${" + p + "}"));
+        String query = joiner.toString();
+        SQLParserContext context = createParserContext(setDialect("snowflake"), query);
+        List<SQLQueryParameter> params = SQLScriptParser.parseParametersAndVariables(context, 0, query.length());
+        List<String> actualParamNames = new ArrayList<String>();
+        for (SQLQueryParameter sqlQueryParameter : params) {
+            actualParamNames.add(sqlQueryParameter.getName());
+        }
+        Assert.assertEquals(List.of("ABC", "PRET", "AC"), actualParamNames);
+    }
     
     @Test
     public void parseParameterFromSetCommand() throws DBException {