microsoft / vscode-cpptools

Official repository for the Microsoft C/C++ extension for VS Code.
Other
5.53k stars 1.56k forks source link

Support Dynamic SQL syntax #3688

Open yedane opened 5 years ago

yedane commented 5 years ago

Type: LanguageService

Describe the bug

We have to use dynamic SQL statements, and in the synthax we have to put a ":" before a variable, but it seems that break the IntelliSense. Please have a look on the documentation below: Oracle dynamic statements

Actually when we want to drive into dba_test_with_proc_and_without_colon function it show us the header instead of the function declaration. But when we drive into dba_test_with_proc_and_without_colon it shows us the declaration.

To Reproduce

  1. Go to the main file
  2. Go to Declaration (F12) on the dba_test_with_proc_and_colon, it drives to the header declaration
  3. Go to Declaration (F12) on the dba_test_without_proc, it drives to the function declaration
  4. Go to Declaration (F12) on the dba_test_with_proc_and_without_colon, it drives to the function declaration

Expected behavior

when we go to Declaration (F12) on the dba_test_with_proc_and_colon, it must drive to the function declaration instead of the header

Code source

main.c

#include "hello.h"

int main()
{
  int vl_err = 0;
  short vl_num = 0;

  vl_err = dba_test_with_proc_and_colon(vl_num);
  vl_err = dba_test_without_proc(vl_num);
  vl_err = dba_test_with_proc_and_without_colon(vl_num);
  return 0;
}

hello.h

int dba_test_with_proc_and_without_colon(short va_num);
int dba_test_with_proc_and_colon(short va_num);
int dba_test_without_proc(short va_num);

hello.c

int dba_test_without_proc(short va_num)
{
  int vl_ret_cod = 0;

  if (va_num > 1)
    vl_ret_cod = 1;
  return vl_ret_cod;
}

int dba_test_with_proc_and_without_colon(short va_num)
{
  int vl_ret_cod = 0;

  EXEC SQL BEGIN DECLARE SECTION;
  char vl_string[2048] = {0};
  EXEC SQL END DECLARE SECTION;
  strcpy(vl_string, "select * from tab");
  EXEC SQL PREPARE select from vl_string;
  return vl_ret_cod;
}

int dba_test_with_proc_and_colon(short va_num)
{
  int vl_ret_cod = 0;

  EXEC SQL BEGIN DECLARE SECTION;
  char vl_string[2048] = {0};
  EXEC SQL END DECLARE SECTION;

  strcpy(vl_string, "select * from tab");
  EXEC SQL PREPARE select from :vl_string;
  return vl_ret_cod;
}

In the zip, you can find the source with we repro the issue Intellisense.zip

Colengms commented 5 years ago

Hi @yedane,

I don't think I have enough information to repro your issue.

The 'main.c' and 'Header file' you provided appear to be the same file. Did you intend to send another file? Perhaps one which declared the macros you are using?

Consider creating a repo with a self-contained example of the issue, which we could pull to investigate.

Thanks,

yedane commented 5 years ago

Hello @Colengms,

My bad, I edited my post

Colengms commented 5 years ago

Dynamic SQL is not standard C++. Is it implemented using macros, a special compiler, or a preprocessor?

We don't support this syntax. We could consider this a feature request..

yedane commented 5 years ago

It's preprocessor.

Is it possible to ignore it during intellisense parsing ?

sean-mcmanus commented 5 years ago

@yedane You could surround the SQL code in

#ifndef __INTELLISENSE__
#endif

...but I don't think there's any way for us to auto-detect this.

Colengms commented 5 years ago

Hi @yedane,

I think if the Dynamic SQL were C++ preprocessor based, squiggles would be correct. IntelliSense parsing should consider macro contents. However, it's unclear to me what could be within a preceding macro that would make a ":" valid before a variable name. My suspicion is that it's not preprocessor based.

yedane commented 5 years ago

@Colengms

Dynamic SQL is implemented by using PRO C, it's finally a precompiler that transform into C code: PRO C More information

Here is an code example before and after compilation: Simple example

Colengms commented 5 years ago

Thanks @yedane. Since the syntax is processed by an alternate (pre)compiler and not C++ preprocessor macros, that would explain the squiggle. Let's keep this issue open as a feature request to support (or at least not squiggle) Dynamic SQL syntax.

github-actions[bot] commented 4 years ago

This feature request is being closed due to insufficient upvotes. When enough upvotes are received, this issue will be eligible for our backlog.

pbderr commented 3 years ago

If getting the C/C++ extension to understand embedded SQL is out of the question, perhaps you could add an option to ignore certain statements based on a regular expression. Then at least the embedded SQL statements wouldn't be flagged as problems or errors.

My project has lots of C code with embedded SQL processed by the Oracle ProC precompiler. (https://en.wikipedia.org/wiki/ProC) The SQL code is prefixed by "exec sql" (case insensitive) and terminated by a semi-colon (;), possibly multiple lines.

For example: exec sql select count(*) into :PayerCnt from t_re_pat_liab where sak_recip = :sakRecip;

I have a team of C developers that I'd like to convince to use VS code, but this is going to be a problem. How do I vote for this feature?

sean-mcmanus commented 3 years ago

@pbderr Voting is via image

Our parser doesn't have the ability to skip over code based on a regular expression. You could potentially use a regular expression to surround the calls with #ifndef __INTELLISENSE__.

github-actions[bot] commented 2 years ago

This feature request has received enough votes to be added to our backlog.