cweijan / vscode-database-client

Database Client For Visual Studio Code
https://database-client.com
MIT License
2.5k stars 288 forks source link

SQL parameters and variables #1248

Open shwivel opened 3 months ago

shwivel commented 3 months ago

I don't know if this is a bug or a feature request. I am trying to use parameters for purposes of substitution variables. In the changelog for this extension there is the following mentioned:

6.9.2 2023-12-14 Supports completion of parameters and variables.

However, the most common characters for denoting such are & and : yet neither work (the user does not get prompted to supply some value for the parameter). In other software, such as dbeaver, there is an area within the settings menu where one can set the character, where depicted below for example:

image

I am looking for a similar place in Settings where I can set the character to be used for parameters. Or, if parameters are already supported, what character does this extension expect? (supposedly parameters are supported, but there is no mention of how to use them, and the usual characters used to denote parameters don't work)

cweijan commented 3 months ago

You can configure the variable indicator via "database-client.variableIndicator".

image

shwivel commented 3 months ago

Thanks. So I set the character to an ampersand which is what I expect. However, it seems to behave weirdly relative to other software. It seems that if you have the same named variable, in one place as a quoted string and in another as a number, that it will only substitute wherever the same as the first occurrence.

For example, in an Oracle database if I run:

select    to_date('01-JUL-'||(&fiscal_year -1))   as aaa,
          &fiscal_year                            as bbb,
          '&fiscal_year'                          as ccc
from      dual;

I would expect output like this, which I do, in PL/SQL Developer:

image

However, using this extension in VS code, column ccc has no substitution:

image

Ideally the substitution would occur wherever the same named variable exists in the query, regardless of whether it is quoted. It should replace. Is there a way to make this expected behavior (common to all other software afaik) occur with this extension?