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-43
Examples of Building and Deploying Embedded SQL
C/C++ Programs
Examples of Building and Deploying
Embedded SQL C/C++ Programs
The examples in this subsection use SQL/MP tables and SQL/MX Release 2.x.
Building a C/C++ Program With Embedded SQL Statements on
Windows
You can build a C or C++ program by using the ETK product which is available on
Microsoft Windows. Although the following example does not use ETK components,
the ETK product is easy to use to create programs. For more information, see the ETK
documentation.
This example illustrates how to build a C or C++ program on Windows that has two or
more source files containing embedded SQL/MX statements that query SQL/MP tables
into a self-contained application executable file. Suppose that your catalog is named
FINANCE, and your schema is named WINDEV. Suppose that you want the location
independence of class MAP DEFINEs for your table names.
1. On your PC, create C or C++ source files (for example, sqlprog1.sql and
sqlprog2.sql) that contain embedded SQL/MX statements:
// 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 mxsqlc to expand =stocks to the SQL/MP
table named \pecan.$finance.assets.adrs and =bonds to the SQL/MP
table named \pecan.$finance.assets.munis. Suppose that you want
mxsqlc to connect to the NonStop system \pecan under Guardian user
finance.tomr, whose password is abc123. Suppose that you want mxsqlc to
generate code that assumes the application’s user modules will be in the schema
named ‘FINANCE.WINDEV’. At a Windows command prompt, enter:
set stocks =\pecan.$finance.assets.adrs
set bonds =\pecan.$finance.assets.munis