I am trying to port a ~2000 line Pro*C program to C++ (Pro*C++). It is full of global variables being used as host variables in SQL queries:
char var1;
char var2;
int execute_query() {
// some code
EXEC SQL SELECT ... INTO :var1
EXEC SQL SELECT ... INTO :var2
// some code
}
However, with code=cpp
in the precompiler options, the PARSE
option is set to PARTIAL
, meaning the precompiler only recognises host variables declared in a DECLARE
section.
Can I just surround the global variables with a declare section?
EXEC SQL BEGIN DECLARE SECTION
char var1;
char var2;
EXEC SQL END DECLARE SECTION
int execute_query() {
// some code
EXEC SQL SELECT ... INTO :var1
EXEC SQL SELECT ... INTO :var2
// some code
}
If not, is there another way to make the precompiler recognise the global variables without doing a lot of refactoring?
Yes, you can.
After much fiddling around, I finally managed to create a standalone Pro*C program to test this out, and I can confirm that it works.