SQL/MX Programming Manual for C and COBOL (G06.24+, H06.03+)
Program and Module Management
HP NonStop SQL/MX Programming Manual for C and COBOL—523627-004
17-13
Effect of the Target Attribute
Effect of the Target Attribute
The SQL preprocessor checks for the presence of a Module TableSet Specification
String (MTSS), which is a regular or delimited identifier that you specify with
preprocessor options. For information on how to specify an MTSS, see Running the
SQL/MX C/C++ Preprocessor on page 15-8 and Running the SQL/MX COBOL
Preprocessor on page 16-9. For information on identifiers, see the SQL/MX Reference
Manual.
Targeting Example for C: Using ModuleTableSet (MTSS)
In the next example, a C application that counts employees in various departments is
prepared twice to use different sets of tables. One set of tables is for a test
environment, and the other set of tables is for a production environment. In the source
file empcnt.sql, the application’s SQL statements are coded with class MAP
DEFINEs.
EXEC SQL DECLARE COUNT_EMP_BY_DEPT CURSOR FOR
SELECT D.DEPT_NUM, COUNT(E.EMP_NUM)
FROM =DEPT AS D, =EMPLOYEE AS E
WHERE D.DEPT_NUM = E.EMP_DEPTNUM GROUP BY D.DEPT_NUM;
The application has a MODULE directive:
EXEC SQL MODULE CAT.SCH.EMP_CNT_MODULE NAMES ARE ISO88591;
To build the application, targeting a set of tables on a test system:
1. Use the OSS add_define command to give =DEPT and =EMPLOYEE the desired
values:
add_define =DEPT class=MAP file=\\TEST.\$DATA.HR1.DEPT
add_define =EMPLOYEE class=MAP \
file=\\TEST.\$DATA.HR1.EMPLOYEE
2. Invoke the preprocessor, specifying a module-tableset-specification-
string with the -g option:
mxsqlc empcnt.sql -c empcnt.c -m empcnt.m \
-g moduleTableSet=TEST
3. The previous preprocessor step produces a pure C file (empcnt.c) and a module
definition file (empcnt.m). The c89 utility compiles and links the C file, producing
an executable empcnt.exe, and the SQL/MX compiler compiles empcnt.m.
Because the module-tableset-specification-string is specified as
TEST, the module file produced by the SQL/MX compiler is:
/usr/tandem/sqlmx/USERMODULES/CAT.SCH.^EMP_CNT_MODULE^TEST^
To indicate that the executable was built to use the TEST compiled module file, the
executable is named empcnt_test.exe.
C