Scalable Database Server, HiRDB Version 8 UAP Development Guide

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

8.2.4 Validating preprocessor declaration statements

Organization of this subsection
(1) Overview
(2) Usage examples

(1) Overview

The preprocessor features an option that allows you to use preprocessor declaration statements of the C compiler.

By specifying the -E option, you can execute the following functions with the preprocessor:

* SQL statements and SQL TYPE IS-type variable declarations cannot be specified in include files. (Otherwise, an error occurs during compilation because the preprocessor does not generate a header post source.)

(2) Usage examples

(a) Literal usage

Assume that the following embedded variable declaration is specified in a UAP source file:

 
#include "user.h"
EXEC SQL BEGIN DECLARE SECTION;
  char xchar1[MAX_CHAR_LEN];
EXEC SQL END DECLARE SECTION;
 

Also assume that the following literal is defined in the header file (user.h) that the UAP has included:

 
#define MAX_CHAR_LEN 256
 

In this case, the preprocessor reads the include file and uses the MAX_CHAR_LEN definition value to convert the embedded variable declaration to char xchar1[256]; before analyzing the UAP source file. However, macro literals cannot be used between the SQL prefix and the SQL terminator (in SQL statements).

Specify the directory path for include file retrieval as an option argument. The default directory of the C compiler does not need to be specified.

(b) Conditional compilation

You can use the #ifdef statement to select the SQL statement to be preprocessed. An example is shown as follows.

 
#ifdef DEF_SWITCH
    EXEC SQL DECLARE CUR1 CURSOR FOR SELECT * FROM TABLE1;
#else
    EXEC SQL DECLARE CUR1 CURSOR FOR SELECT * FROM TABLE2;
#endif
 

However, preprocessor declaration statements of the C compiler cannot be specified between the SQL prefix and SQL terminator (in SQL statements).