Scalable Database Server, HiRDB Version 8 UAP Development Guide

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

8.2.3 Preprocessing in Windows

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

(1) C

(a) Environment variable setting

Before a UAP is preprocessed, the environment variable described below can be specified in the HiRDB.INI file, if necessary.

The HiRDB.INI file is installed in the %windir% directory.

PDCLTLANG
Specifies the character code classification to be used for preprocessing. If this environment variable is omitted, sjis is assumed. For details about the PDCLTLANG operand, see 6.6.4 Environment definition information.
(b) SQL preprocessor activation

Following are the three methods of activating the SQL preprocessor:

A command is entered in the following format:

PDCPP.EXE input-file-name [options [output-file-name|authorization-identifier]]

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

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. If the authorization identifier is omitted, the user identifier used during CONNECT is assumed.

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

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

Preprocessing option Description
/S Specifies that only syntax is checked and that no post source will be output; when this option is omitted, the post source is output. Note that the SQL preprocessor may not be able to detect all syntax errors in the SQL statements because it does not perform a rigorous SQL syntax check unless /Xp is also specified.
/O file-name Specifies a filename for the post source that is 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.
/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.
/XA Specifies that an X/Open-compliant API is to be used to create the UAP.
/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.
/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.
/Xp Specifies that a rigorous SQL syntax check is to be executed. However, do not specify this option when the SQL reserved word deletion facility is used.
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 Microsoft Visual C++ compiler (load name during calling: CL.EXE) internally.
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. 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.
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 variable 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 UAP source filename is SAMPLE and no post source will be output.
    PDCPP SAMPLE.EC /S
    Example 2
    The UAP 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 UAP source filename is SAMPLE and no post source will be output.
    PDOCC.EXE SAMPLE.ECP /S
    Example 2
    The UAP source filename is SAMPLE and the filename of the post source to be output is MAIN.
    PDOCC.EXE SAMPLE.ECP /O MAIN.CPP
(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 the OS batch command ERRORLEVEL.

Table 8-9 lists the return codes.

Table 8-9 SQL preprocessor return codes (for C programs in a Windows 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-10 shows the standard input and output for the SQL preprocessor.

Table 8-10 SQL preprocessor standard input and output (for C programs in a Windows 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 in the HIRDB.INI file before a UAP is preprocessed (the HIRDB.INI file is installed in the %windir% directory):

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 COPY statement. When specifying multiple directories, separate the directories with a colon. When this environment variable is omitted, only the current directory is retrieved.

PDCLTLANG
This environment variable should be specified if a specific type of character codes is to be used for preprocessing. The default is sjis. For details about the PDCLTLANG operand, see 6.6.4 Environment definition information.

Example
[HiRDB]                 1
PDCBLFIX=.AAA           2
PDCBLLIB=E:\USER\COPY   3
  1. Specifies [HiRDB].
  2. Specifies .AAA as a COBOL language source file identifier.
  3. Specifies a directory (E:\USER\COPY in this example) from which library text to be included by the COPY statement is to be retrieved.
(b) SQL preprocessor activation

Following are the three methods of activating the SQL preprocessor:

A command is entered in the following format:

PDCBL.EXE input-file-name [options [output-file-name|authorization-identifier]]

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

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. If the authorization identifier is omitted, the user identifier used during CONNECT is assumed.

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

Table 8-11 Preprocessing options (for COBOL in the Windows environment)

Preprocessing option Description
/S Specifies that only syntax is checked and that no post source will be output; when this option is omitted, the post source is output.
Note that the SQL preprocessor may not be able to detect all syntax errors in the SQL statements because it does not perform a rigorous SQL syntax check unless /Xp is also specified.
/O file-name Specifies that the filename for the output post source is to be changed.
When this option is omitted, the input filename with its file identifier changed to .CBL (for COBOL language) or .OCB (for OOCOBOL language) and is used as the output filename.
If the input file identifier is .CBL (for COBOL language) or .OCB (for OOCOBOL language), this option must be specified to change the post source filename to an identifier other than .CBL (for COBOL language) or .OCB (for OOCOBOL language).
/XC Specifies that the double quotation mark is used as the quotation mark in the character string to be 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.
/XD Specifies that a DLL is to be created.
The prerequisite compiler for creating a DLL is COBOL85 Version 4.0 04-02 or a later version. Do not create an application that contains both UAPs that were preprocessed by specifying the /XD option and UAPs that were preprocessed without specifying the /XD option. Otherwise, an error (KCCBO204R-S) occurs in the COBOL runtime library during application execution.
/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.
/XAD Specifies that a UAP that used an X/Open-compliant API is to be created as a DLL.
/XA Specifies that the UAP is to be created by using an X/Open-compliant API.
/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.
/E2 Specifies that embedded variables are to be used without being declared in the embedded SQL declare section.
/Xp Specifies that a rigorous SQL syntax check is to be executed. However, do not specify this option when the SQL reserved word deletion facility is used.
  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.EXE SAMPLE.EOC /S
    Example 2
    The UAP source filename is SAMPLE and the filename of the post source to be output is MAIN.
    PDOCB.EXE 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 the OS batch command ERRORLEVEL.

Table 8-12 lists the return codes.

Table 8-12 SQL preprocessor return codes (for COBOL programs in a Windows 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-13 shows the standard input and output of the SQL preprocessor.

Table 8-13 SQL preprocessor standard input and output (for COBOL programs in a Windows 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