Scalable Database Server, HiRDB Version 8 UAP Development Guide

[Contents][Index][Back][Next]

8.2.2 Preprocessing in UNIX

Organization of this subsection
(1) C
(2) COBOL

(1) C

(a) Environment variable setting

The following environment variable can be set before a UAP is preprocessed:

PDDIR
This environment variable specifies the absolute path name for the installation directory for HiRDB (server or client); the default directory is /HiRDB.
This variable need not be specified when the installation destination is /HiRDB.

LANG
This environment variable specifies the character code classification of the HiRDB client environment. Table 8-1 shows the character codes that can be specified for LANG.

Table 8-1 Character codes that can be specified for LANG

Server character code classification set with pdsetup command Value of LANG environment variable
HP-UX Solaris AIX 5L Linux1
sjis ja_JP.SJIS ja_JP.PCK Ja_JP Any value2
chinese chinese-s chinese-s chinese-s chinese-s
ujis ja_JP.eucJP ja ja_JP ja_JP.eucJP, ia_JP, or Ja_JP.ujis
lang-c Single-byte character codes of each language
utf-8 Any value2
No specification ja_JP.SJIS ja Ja_JP ja_JP.eucJP, ia_JP, or Ja_JP.ujis

Legend:
[Figure]: Cannot be specified.

Note
If the character code classification of the character strings described in a UAP does not match the character code classification for UAP execution, the UAP does not operate correctly. Therefore, the value of the LANG environment variable specified for UAP creation must be the same as the LANG value specified for UAP execution.

1 For locales that are not supported by HiRDB, lang-c is assumed.

2 Hitachi recommends that you set the LANG environment variable to a character code classification that can be used by the corresponding HiRDB server. If the HiRDB server cannot use the target character code classification, specify the lang-c value.
If this environment variable is not specified, or if the specified value is different from the value that was set to the environment variable, ja_SP.SJIS is assumed. In the HP-UX environment, only ja_JP.SJIS can be specified.
For details about the pdsetup command, see the HiRDB Version 8 Command Reference manual.

PDCLTLANG
This environment variable specifies the character code classification to be used in preprocessing instead of the character code classification specified by the LANG environment variable. For details about the PDCLTLANG operand, see 6.6.4 Environment definition information.

Example 1: Setting the environment in sh (Bourne shell)
  • HiRDB is being installed in the /prdb directory.
$ PDDIR="/prdb"$ export PDDIR

Example 2: Setting the environment in csh (C shell)
  • HiRDB is being installed in the /prdb directory
% setenv PDDIR "/prdb"
(b) SQL preprocessor activation

To activate the SQL preprocessor, use the pdcpp command (for C) or the pdocc command (for C++).

Following is the input format for starting the SQL preprocessor:

pdcpp input-file-name [options [output-file-name|authorization-identifier]]

Note
In the case of C++, the underlined section must be changed to pdocc.

input-file-name
Specifies the name of the C source file. .ec must be used as the file identifier.

output-file-name
Specifies the name of the C source file. If the output filename is omitted, .c is used as the file identifier.

authorization-identifier
Specifies the default authorization identifier to be used when an authorization identifier is omitted in the SQL. This specification is invalid when the distributed database facility is used and when remote database access is involved.
If the authorization identifier is omitted, the user identifier used during CONNECT is assumed.

options
Specifies, as necessary, the options shown in Table 8-2. Upper-case and lower-case characters are not discriminated in the options.

Table 8-2 Preprocessing options (for C in the UNIX environment)

Preprocessing option Description
-s Specifies that only syntax is checked and that no post source is to be output; when this option is omitted, the post source is output.
-o file-name Specifies a filename for the post source that is to be output; when this option is omitted, the input filename with its file identifier changed to .c is used as the output filename.
-A authorization-identifier Specifies that the default authorization identifier, which is used when no authorization identifier is specified in a static SQL statement, is to be changed.
A static SQL statement refers to the INSERT, UPDATE, DELETE, single-row SELECT, OPEN (format 1), CALL, LOCK, or PURGE TABLE statement.
-h64 Specifies that a post source for 64-bit mode is to be created. If an embedded variable that uses the long type is declared, an error occurs.
-P Specifies that no syntax check is to be executed on the SQL. This option can be specified when one of the following UAPs is preprocessed:
  • UAP for XDM/RD E2 connection
  • UAP that uses the SQL reserved word deletion facility
If this option is not specified, the reserved words to be deleted by the SQL reserved word deletion facility and the SQL statements that can be used by XDM/RD E2 may cause syntax errors.
-Xo Specifies that the SQL statements extracted from the UAP are to be output to standard output. The output method for outputting the SQL statements is described below.
  • Embedded variables in SQL statements are replaced with the ? parameter.
  • INTO clauses in single-row SELECT statements are deleted.
  • Multiple space characters between word clauses in SQL statements are replaced with one space character.
  • Any SQL statement that is split across several lines is consolidated into a single line.
  • Only SQL statements that are sent to the server during execution are output. SQL statements that are not executed (such as WHENEVER statements and BEGIN DECLARE SECTION) are not output.
  • A semicolon (;) is added to the end of an SQL statement.
  • Declarations of embedded variables are not output.
  • A dynamic SQL statement is output only if the SQL is specified with a literal. In all other cases, dynamic SQL statements are not output.
  • An OPEN statement outputs a query expression only if a format 1 cursor is used.
  • A post source is not generated.
-Xe{y|n} Specifies whether the cursor for PREPARE statement execution is to be closed automatically.
y: Creates a post source that closes the cursor automatically.
n: Creates a post source that does not close the cursor automatically.
If this option is omitted, the preprocessor creates a post source according to the specification value in the PDPRPCRCLS client environment definition.
-Xv Specifies that VARCHAR- and BINARY-type structures are to be analyzed as normal structures when the -E2 option is specified. To declare VARCHAR- and BINARY-type embedded variables, use the SQL TYPE IS-type variable declaration. This option must be specified together with the -E2 option. Do not specify this option if the UAP uses macros for repetition columns.
-E{1|2|3} ["option-character-string"] Specifies that preprocessor declaration statements used in the UAP are to be validated or that embedded variables are to be used without being declared in the embedded SQL declare section, or both.
-E1: Specifies that preprocessor declaration statements are to be validated.
-E2: Specifies that embedded variables are to be used without being declared in the embedded SQL declare section. This value can also specify that pointers or structure references are to be used as embedded variables.
-E3: Specifies that both -E1 and -E2 apply.
"option-character-string":
Specifies the path name of the directory from which the file to be included is to be retrieved. Specify the path name in the format of the -I option specified in the C compiler. When specifying multiple options in option-character-string, use semicolons to separate the options. You can also specify any C compiler. When the -E2 option is specified, this value ignored.
When the -E1 option is specified, the path name to the compiler must be specified in the PATH environment variable because the preprocessor calls the C compiler internally.
Note 1
The following table shows the functions that can be used when the -E option is specified.
Function Omitted -E1 -E2 -E3
Validate the macro defined with #define. N Y N Y
Validate the header file that was included with #include. N Y N Y
Enable conditional compilation with #if, #ifdef, and other statements. N Y N Y
Use variables declared anywhere in the UAP as embedded variables. N N Y Y
Use structures as embedded variables. N N Y Y
Use pointers as embedded variables. N N Y Y
Legend:
Y: The function can be used.
N: The function cannot be used.
Note 2
When the -E option is specified, the preprocessor calls the C compiler internally. The following table shows the C compiler for each platform.
Platform Compiler type Load name for calling
HP-UX HP-C compiler cc
Solaris SUN Workshop compiler cc
AIX C for AIX compiler xlc
Linux gcc compiler gcc
Windows Microsoft Visual C++ compiler CL.EXE
If you wish to use any other C compiler, specify the absolute path name of the compiler, including the load directory, at the beginning of the option-character-string value. The directory name and the load name cannot include spaces or semicolons. If a path name has been added to the PATH environment variable, the path name does not have to be the absolute path name.
When specifying a load name, separate the load name and the options with a semicolon.
The compiler to be used must support the -C and -E options. This is because to process pseudo-instructions such as #define and #include, the preprocessor internally specifies the -C and -E options to the C compiler and creates temporary work files. In Linux, the preprocessor uses the -xc option in addition to the -C and -E options. In Solaris, the preprocessor also uses the -Xs option.
The other options that can be specified in option-character-string depend on the specifications of the compiler to be used. However, if an option that is incompatible with the -C or -E option is specified, the preprocessor produces an error. If an option that displays help information is used, the operation is not guaranteed.
Examples are shown as follows.
Example 1: If the C compiler is not to be used
 
pdcpp connect.ec -E1"-I$PDDIR/include;-DDEBUG"
 
Example 2: If a user-specified C compiler is to be used
 
pdcpp connect.ec -E1"/usr/bin/gcc;-I$PDDIR/include;-DDEBUG"
 
Note 3
SQL statements and SQL TYPE IS-type variable declarations cannot be specified in the included header file. If the preprocessor finds an SQL statement or an SQL TYPE IS-type variable declaration in the header file, it displays an error message and continues processing but does not generate a post source. If you specify the -E1 option and also specify an embedded SQL declare section in the header file, that section becomes invalid. To use variables defined in the header file as embedded variables, specify the -E3 option. However, in this case as well, SQL TYPE IS-type variable declarations cannot be specified in the include file.
  1. Examples of command specification in C
    Example 1
    The C source filename is sample and post source is not to be output.
    pdcpp sample.ec -s
    Example 2
    The C source filename is sample and the filename of the post source to be output is main.
    pdcpp sample.ec -o main.c
  2. Examples of command specification in C++
    Example 1
    The C source filename is sample and post source is not to be output.
    pdocc sample.EC -s
    Example 2
    The C source filename is sample and the filename of the post source to be output is main.
    pdocc sample.EC -o main.C
(c) SQL preprocessor return codes

The SQL preprocessor returns a return code to the OS when the processing is complete. The return code can be referenced by displaying the contents of the $? shell variable (in the case of Bourne shell) or the $status shell variable (in the case of C shell).

Table 8-3 lists the return codes.

Table 8-3 SQL preprocessor return codes (for C programs in a UNIX environment)

Return code Explanation
0 Normal termination
4, 8 Error (preprocessing was completed)
12, 16 Error (preprocessing terminated abnormally)
(d) Error output

When a syntax error is detected in an SQL statement, the SQL preprocessor ignores the SQL statement and continues processing. If an error is detected in an option specification, however, processing is suspended. Processing terminates abnormally when a system error, such as a memory shortage or a file I/O error, occurs and processing cannot be continued.

For a syntax error in an SQL statement, the SQL preprocessor outputs an error message to the standard error output. By redirecting the standard error output, the error message can be stored in a file. This file can be referenced for the error content, the UAP source filename, and the error location (line number in the SQL statement).

Table 8-4 shows the standard input and output for the SQL preprocessor.

Table 8-4 SQL preprocessor standard input and output (for C programs in a UNIX environment)

File Application
Standard input File input (cannot be used by the user)
Standard output File output (cannot be used by the user)
Standard error output Output of error messages

(2) COBOL

(a) Environment variable setting

The following environment variables can be set before a UAP is preprocessed:

PDDIR
This environment variable specifies the absolute path name for the installation directory for HiRDB (server or client); the default directory is /HiRDB.
This variable need not be specified if the installation destination is /HiRDB.

PDCBLFIX
This environment variable specifies an optional file identifier other than the standard identifier of the COBOL source file.
The specification must be a character string of 1-4 alphabetic characters beginning with a period. The file identifier specified in this environment variable can be used only for the input file.

PDCBLLIB
This environment variable specifies directories from which library texts to be included in the source file are to be retrieved by the SQL COPY statement. Multiple directories must be separated by a colon. When this environment variable is omitted, only the current directory is retrieved.

LANG
This environment variable specifies the character code classification of the HiRDB client environment.
For details about the character code classifications that can be specified in LANG, see Table 8-1.
If you do not specify this environment variable or if you specify a different value from the value that is specified in the environment variable, ja_JP.SJIS is assumed.

PDCLTLANG
This environment variable specifies the character code classification to be used in preprocessing instead of the character code classification specified by the LANG environment variable. For details about the PDCLTLANG operand, see 6.6.4 Environment definition information.

Example 1: Setting the environment in sh (Bourne shell)
$ PDDIR="/prdb"                                       1
$ PDCBLFIX=".Cob"                                     2
$ PDCBLLIB=$HOME/cobol/include:$HOME/cobol/source     3
$ export PDDIR PDCBLFIX PDCBLLIB                      4
  1. Specifies the installation directory (/prdb in this example).
  2. Specifies .Cob as the COBOL language source file identifier.
  3. Specifies the two directories ($HOME/cobol/include and $HOME/cobol/source) from which library text is to be retrieved.
  4. Enables referencing by the SQL preprocessor.

Example 2: Setting the environment in csh (C shell)
% setenv PDDIR "/prdb"                                     1
% setenv PDCBLFIX ".Cob"                                   2
% setenv PDCBLLIB $HOME/cobol/include:$HOME/cobol/source   3
  1. Specifies the installation directory (/prdb in this example).
  2. Specifies .Cob as the COBOL language source file identifier.
  3. Specifies two directories ($HOME/cobol/include and $HOME/cobol/source) from which library text is to be retrieved.
(b) SQL preprocessor activation

To activate the SQL preprocessor, use the pdcbl command (for COBOL) or the pdocb command (for OOCOBOL).

Following is the input format for starting the SQL preprocessor:

pdcbl input-file-name [options [output-file-name|authorization-identifier]]

Note
In the case of OOCOBOL, the underlined section must be changed to pdocb.

input-file-name
Specifies the name of the COBOL source file. .ecb, .cob, or .cbl must be used as the file identifier. If any other file identifier was registered during environment setting, that identifier can also be used.

output-file-name
Specifies the name of the COBOL source file. If the output filename is omitted, .cbl is used as the file identifier.

authorization-identifier
Specifies the default authorization identifier to be used when an authorization identifier is omitted in the SQL. This specification is invalid when the distributed database facility is used and when remote database access is involved.
If the authorization identifier is omitted, the user identifier used during CONNECT is assumed.

options
Specifies, as necessary, the options shown in Table 8-5. Upper-case and lower-case characters are not discriminated in the options.

Table 8-5 Preprocessing options (for COBOL in the UNIX environment)

Preprocessing option Description
-s Specifies that only syntax is checked and that no post source is output; when this option is omitted, the post source is output.
-o file-name Specifies a filename for the post source; when this option is omitted, the input filename with its file identifier changed to .cbl is used as the output filename.
If the input file identifier is .cbl, this option must be specified to change the post source filename to an identifier other than .cbl.
-Xc Specifies that the double quotation mark is used as the quotation mark in the character string created by the SQL preprocessor; the default quotation mark is the apostrophe.
-A authorization-identifier Specifies that the default authorization identifier, which is used when no authorization identifier is specified in a static SQL statement, is to be changed.
A static SQL statement refers to the INSERT, UPDATE, DELETE, single-row SELECT, OPEN (format 1), CALL, LOCK, or PURGE TABLE statement.
-P Specifies that no syntax check is to be executed on the SQL. This option can be specified when one of the following UAPs is preprocessed:
  • UAP for XDM/RD E2 connection
  • UAP that uses the SQL reserved word deletion facility
If this option is not specified, the reserved words to be deleted by the SQL reserved word deletion facility and the SQL statements that can be used by XDM/RD E2 may cause syntax errors.
-Xo Specifies that the SQL statements extracted from the UAP are to be output to standard output. The output method for outputting the SQL statements is described below.
  • Embedded variables in SQL statements are replaced with the ? parameter.
  • INTO clauses in single-row SELECT statements are deleted.
  • Multiple space characters between word clauses in SQL statements are replaced with one space character.
  • Any SQL statement that is split across several lines is consolidated into a single line.
  • Only SQL statements that are sent to the server during execution are output. SQL statements that are not executed (such as WHENEVER statements and BEGIN DECLARE SECTION) are not output.
  • A semicolon (;) is added to the end of an SQL statement.
  • Declarations of embedded variables are not output.
  • A dynamic SQL statement is output only if the SQL is specified with a literal. In all other cases, dynamic SQL statements are not output.
  • An OPEN statement outputs a query expression only if a format 1 cursor is used.
  • A post source is not generated.
-c {m|s} Specifies the COBOL compiler type.
m: Micro Focus COBOL
s: SUN Japanese COBOL
-Xe{y|n} Specifies whether the cursor for PREPARE statement execution is to be closed automatically.
y: Creates a post source that closes the cursor automatically.
n: Creates a post source that does not close the cursor automatically.
If this option is omitted, the preprocessor creates a post source according to the specification value in the PDPRPCRCLS client environment definition.
-E2 Specifies that embedded variables are to be used without being declared in the embedded SQL declare section.
  1. Examples of command specification in COBOL
    Example 1
    The UAP source filename is sample and no post source will be output.
    pdcbl sample.ecb -s
    Example 2
    The UAP source filename is sample and the filename of the post source to be output is main.
    pdcbl sample.ecb -o main.cbl
  2. Examples of command specification in OOCOBOL
    Example 1
    The UAP source filename is sample and no post source will be output.
    pdocb sample.eoc -s
    Example 2
    The UAP source filename is sample and the filename of the post source to be output is main.
    pdocb sample.eoc -o main.ocb
(c) SQL preprocessor return codes

The SQL preprocessor returns a return code to the OS when the processing is completed. The return code can be referenced by displaying the contents of the $? shell variable (in the case of Bourne shell) or the $status shell variable (in the case of C shell).

Table 8-6 lists the return codes.

Table 8-6 SQL preprocessor return codes (for COBOL programs in a UNIX environment)

Return code Explanation
0 Normal termination
4, 8 Error (preprocessing was completed)
12, 16 Error (preprocessing terminated abnormally)
(d) Error output

When a syntax error is detected in an SQL statement, the SQL preprocessor ignores that SQL statement and continues processing. If an error is detected in an option specification, however, processing is suspended. Processing terminates abnormally when a system error, such as a memory shortage or a file I/O error, occurs and processing cannot be continued.

For a syntax error in an SQL statement, the SQL preprocessor outputs an error message to the standard error output. By redirecting the standard error output, the error message can be stored in a file. This file can be referenced for the error content, the UAP source filename, and the error location (line number in the SQL statement).

Table 8-7 shows the standard input and output of the SQL preprocessor.

Table 8-7 SQL preprocessor standard input and output (for COBOL programs in a UNIX environment)

File Application
Standard input File input (cannot be used by the user)
Standard output File output (cannot be used by the user)
Standard error output Output of error messages