SQL/MX Programming Manual for C and COBOL (G06.24+, H06.03+)

C/C++ Program Compilation
HP NonStop SQL/MX Programming Manual for C and COBOL523627-004
15-45
Developing a Native C/C++ Program With
Embedded SQL/MX Statements on OSS
contained application executable file. Suppose that your schema is named OSSDEV
under the catalog named FINANCE.
1. Create C or C++ source files (for example, sqlprog1.sql and sqlprog2.sql)
that contain embedded SQL/MX statements (and use SQL/MP tables):
// sqlprog1.sql
EXEC SQL MODULE sqlprog1mod; // externally qualified at SQL
preprocess-time
int main() {
EXEC SQL INVOKE =stocks AS stocks_type;
EXEC SQL DECLARE CURSOR s FOR SELECT * FROM =stocks;
...
}
// sqlprog2.sql
EXEC SQL MODULE sqlprog2mod; // externally qualified at SQL
preprocess-time
int prog2() {
EXEC SQL INVOKE =bonds AS bonds_type;
EXEC SQL DECLARE CURSOR b FOR SELECT * FROM =bonds;
...
}
2. Run the SQL/MX C/C++ preprocessor on each source file that has embedded SQL
statements. Suppose that you want to place these application’s user modules in
the schema named ‘FINANCE.OSSDEV’ to distinguish your OSS-developed
application modules from Windows-developed versions. As a result, you and the
Windows-based developers can test your respective versions of sqlprog on the
same NonStop system at the same time. Use class MAP DEFINEs for mxsqlc to
correctly process the INVOKEs of table DEFINEs found in the sources.
add_define =stocks \
class=map file=\\pecan.\$finance.assets.adrs
add_define =bonds \
class=map file=\\pecan.\$finance.assets.munis
mxsqlc sqlprog1.sql -c sqlprog1.cpp -g \
moduleCatalog=FINANCE -g moduleSchema=OSSDEV
mxsqlc sqlprog2.sql -c sqlprog2.cpp -g \
moduleCatalog=FINANCE -g moduleSchema=OSSDEV
These commands create two annotated source files (sqlprog1.cpp and
sqlprog2.cpp) that contain the SQL/MX CLI call translations of the embedded
SQL statements and extra C/C++ source constructs that represent the module
definitions. These files have hard-coded references to the modules named
FINANCE.OSSDEV.sqlprog1mod and FINANCE.OSSDEV.sqlprog2mod. For
security reasons, these module references cannot be remapped at run time.
3. Run the C/C++ compiler to compile the annotated source files into object files:
c89 -Wversion2 -I /usr/tandem/sqlmx/include -c sqlprog1.cpp
c89 -Wversion2 -I /usr/tandem/sqlmx/include -c sqlprog2.cpp