SQL/MX 3.2.1 Programming Manual for C and COBOL (H06.26+, J06.15+)

Program and Module Management
HP NonStop SQL/MX Release 3.2.1 Programming Manual for C and COBOL663854-005
17-17
Targeting Example for C: Using Build Subdirectory
After building the application for both sets of tables, you can execute, in any order,
either compiled executable (empcnt_test.exe or empcnt_prod.exe) with its
compiled SQL.
When empcnt_test.exe is run for the first set of tables, you must set up DEFINEs
=DEPT to reference \TEST.$DATA.HR1.DEPT and =EMPLOYEE to reference
\TEST.$DATA.HR1.EMPLOYEE.
When empcnt_prod.exe is run, you must set up DEFINE’s =DEPT to reference
\PROD.$DATA.HR1.DEPT and =EMPLOYEE to reference
\PROD.$DATA.HR1.EMPLOYEE.
You can set up DEFINEs to reference the production environment set of tables, and
then use the empcnt_test.exe executable (or vice versa). The result of this action is
that the compiled SQL plans are read from empcnt_test.exe module
/usr/tandem/sqlmx/USERMODULES/CAT.SCH.^EMP_CNT_MODULE^TEST^.
These plans refer to the test environment tables, \TEST.$DATA.HR1.DEPT and
\TEST.$DATA.HR1.EMPLOYEE. However, the SQL/MX executor performs late name
resolution (see Late Name Resolution on page 8-6). Because the run-time tables
(specified by setting up the DEFINEs for the production system), are different from the
compile-time tables, the executor performs a similarity check. If the two sets of tables
are similar, the plan is used. If the two set of tables are dissimilar, the plan is
recompiled. The advantage of compile-time name resolution is lost if DEFINEs are set
differently at run time than at compile-time.
Targeting Example for C: Using Build Subdirectory
To avoid the problem where intermediate files and even the executable can be
overwritten when rebuilding for a new target, use OSS environment variables. In this C
example, the same source file empcnt.sql is built twice using an OSS shell script
named empcnt.sh:
Set up class MAP DEFINEs. Then set up an OSS environmental variable,
TableSet, to supply both a module-tableset-specification-string and
the name of a subdirectory to which the intermediate files (including the before-link
object file) and executable can be written:
export TableSet=TEST
add_define =DEPT class=MAP file=\\TEST.\$DATA.HR1.DEPT
add_define =EMPLOYEE class=MAP
file=\\TEST.\$DATA.HR1.EMPLOYEE
Invoke the shell script empcnt.sh. The shell script includes the lines:
mkdir ./$TableSet
mxsqlc empcnt.sql -c $TableSet/empcnt.c \
-m $TableSet/empcnt.m \
-g moduleTableSet=$TableSet
c89 –o ./$TableSet/empcnt.o ./$TableSet/empcnt.c
nld –set systype oss \