1 SQLPRE72 The SQL precompiler provides special keywords and syntax that allow you to include (embed) simple and compound statements directly into host language programs. Then you can use the SQL precompiler to process the combined embedded statements and host language code to produce an object file for linking and execution. 2 Environment You can use SQL precompiler syntax only in Ada, C, COBOL, FORTRAN, Pascal, and PL/I host language source files. The SQL precompiler supports no other host languages. If you use a host language other than the ones mentioned for embedded SQL and you want to use the SQL interface with it, you must use the SQL module processor. 2 Format (B)0EXEC SQL qqwqq> simple-statement qqqqwqqwqqqqqqqqqqqqqqqqqqqqqwqqq>  mqq> compound-statement qqj mqq> ending-symbol qqqj    (B)0ending-symbol =    qqqqqwq> ; qqqqqqqqwq>   mq> END-EXEC qj    (B)0simple-statement =    qqqq> SQL statement qqqq>  (B)0compound-statement =     qqwqqqqqqqqqqqqqqqqqqqqqqqwq> BEGIN qqwqqqqqqqqqqqqqqqqqqqqwqqqk  mq> <beginning-label>: qj mq> pragma-clauses qqj x   lqqqqqqqqqqqqqqqqqqqqqqqqqqqqqq variable-declaration qwj x   mqqqqqqqqqqqqqqqqqqqqqqqqqqj x   lqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqj   mqwqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqwqq> END qqwqqqqqqqqqqqqqqqqqqqqwqq>  mwq>  compound-use-statement qwj mq> <ending-label>: qj  mqqqqqqqqqq pragma-option qqwqqqqqqqqqqqqqqqqqqwqqq> x mqqqqqqq PRAGMA ( qwq> pragma-option qwq> ) qj mqqqqqqqq , ATOMIC qqqqqqqqqqqqqqqqqqqqqqwqq> tq> NOT ATOMIC qqqqqqqqqqqqqqqqqqu tq> ON ALIAS <alias-name> qqqqqqqu tq> with-clause qqqqqqqqqqqqqqqqqu mq> optimize-clause qqqqqqqqqqqqqj   (B)0with-clause =    qqq> WITH qq> HOLD qwqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqwq>   mq> PRESERVE qqwq> ON COMMIT qqqu   tq> ON ROLLBACK qu   tq> ALL qqqqqqqqqu   mq> NONE qqqqqqqqj    (B)0optimize-clause =            qqwqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqwqqq>   mq> OPTIMIZE qqwqwq> FOR qwq> FAST FIRST qqqqqqqqwqqqqqqqqqqwqwqj   x x tq> TOTAL TIME qqqqqqqqu   x x  x x mq> SEQUENTIAL ACCESS qj x x  x tq> USING <outline-name> qqqqqqqqqqqqqqqqqqu x  x tq> WITH qwq> DEFAULT qqwq> SELECTIVITY qu x x x tq> SAMPLED qqu x x x x mq> AGGRESSIVE j x x  x mq> AS <query-name> qqqqqqqqqqqqqqqqqqqqqqqj x   mqqqqqqqqqqqqqqqq pre-host-file-spec o If you invoke the SQL precompiler with a host language program file as part of the DCL command line, SQL starts processing your file immediately after you press the Return key. For example: $ SADA pre-host-file-spec pre-qualifiers Whichever method you choose to invoke the precompiler, you have the option to specify a wide range of qualifiers that control how the SQL precompiler processes the module file. The syntax diagrams show the format for the qualifiers that you can include with the host language program file specification. 3 Format (B)0pre-host-file-qual =    SQLPRE qq> pre-host-file-spec qwqqqqqqqqqqqqqqqqqqqqqqqqwqk   mq> <context-file-name> qj x  lqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqj  mq> pre-lang-qualifiers qqqqwqqqqqqqqqqqqqqqqqqqqqwqqqqqq>   mqq> pre-qualifiers qqj    (B)0pre-lang-qualifiers =    qqq> / qwq> ADA qqqqqqqqqqqqqqqqqqqqwqq>   tq> CC qqwqqqqqqqqqqqqqqqqwqu   x tq> =VAXC qqqqqqqu x   x mq> =DECC qqqqqqqj x   tq> COBOL qqqqqqqqqqqqqqqqqqu   tq> FORTRAN qqqqqqqqqqqqqqqqu   tq> PASCAL qqqqqqqqqqqqqqqqqu   mq> PLI qqqqqqqqqqqqqqqqqqqqj    (B)0pre-qualifiers =  qqqwwq> / ARCHITECTURE= architecture_options qqqqqqqqqqqqqqwwqq>   xtq> / qwqqqqqqwqqwq> ANSI_FORMAT qqqqqqqqqqqqqqqqqqqqqqux    xx mq NO qj tq> EXTEND_SOURCE qqqqqqqqqqqqqqqqqqqqux   xx tq> G_FLOAT qqqqqqqqqqqqqqqqqqqqqqqqqqux   xx tq> LIST qqwqqqqqqqqqqqqqqqqqqwqqqqqqqux  xx x mq> = <file-spec> qj xx  xx tq> MACHINE_CODE qqqqqqqqqqqqqqqqqqqqqux   xx mq> OBJECT qwqqqqqqqqqqqqqqqqqqwqqqqqqux   xx  mq> = <file-spec> qj xx  xtq> / FLOAT= qwq> D_FLOAT qqqwqqqqqqqqqqqqqqqqqqqqqqqux xx tq> G_FLOAT qqqqu xx xx mq> IEEE_FLOAT qqj xx xx xx  xmq> / SQLOPTIONS= ( qwwq> opt-no-qualifiers qwwq> ) qqqjx   x xmq> opt-qualifiers qqqqjx x   x mqqqqqqqqq , GENERIC qwqq>  tq> HOST qqu   tq> EV4 qqu   tq> EV5 qqu   tq> EV56 qqu  tq> PCA56 qqu tq> EV6  qqu tq> EV67 qqu tq> EV68 qqu mq> EV7 qqj       (B)0opt-no-qualifiers =    qwqqqqqqqqwqwq> CONNECT qqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqwqq>   mq> NO qqj tq> DECLARE_MESSAGE_VECTOR qqqqqqqqqqqqqqqqqqqqqu   tq> EXTERNAL_GLOBALS qqqqqqqqqqqqqqqqqqqqqqqqqqqu   tq> FLAG_NONSTANDARD qqqwqqqqqqqqqqqqqqqqqqqwqqu   x tqq> = SQL92_ENTRY qu x   x tqq> = SQL89 qqqqqqqu x   x mqq> = MIA qqqqqqqqqj x   tq> INITIALIZE_HANDLES qqqqqqqqqqqqqqqqqqqqqqqqqu  tq> PRAGMA = ( qq> IDENT = string-literal q> ) qu tq> QUERY_EXTIMATES qqqqqqqqqqqqqqqqqqqqqqqqqqqqu  tq> QUIET_COMMIT qqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqu   tq> TRANSACTION_DEFAULT qwqqqqqqqqqqqqqqqqqqwqqqu   x tq> = IMPLICIT qqqqu x   x mq> = DISTRIBUTED qj x   mq> WARN wqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqwqqj     m> = ( qwq> warning-option qwq> ) qj       mqqqqqq , WARNING qqqqqqwqqwq>   x tq> NOWARNING qqqqu x   x tq> DEPRECATE qqqu x   x mq> NODEPRECATE qj x   mqqqqqqqqq , C_STRING = c-string-options qqqqqqqqqqqqqqqqqqqqqqqqwqq>   tq> constraint-options qqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqu   tq> database-options qqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqu   tq> optimization-options qqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqu   tq> QUERY_TIME_LIMIT = qqqqqqqqqqqqqqqqqu   tq> QUERY_MAX_ROWS = qqqqqqqqqqqqqqqqqqqqqqu   tq> QUERY_CPU_TIME_LIMIT = qqqqqqqqqqqqqu   tq> USER_DEFAULT = qqqqqqqqqqqqqqqqqqqqqqqqqqu   tq> PASSWORD_DEFAULT = qqqqqqqqqqqqqqqqqqqqqqu   mq> ROLLBACK_ON_EXIT qqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqj    (B)0c-string-options =    qwwqqwqqqqqqw> BLANK_FILL qqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqw>  xx m> NO qj x   xmqqwqqqqqqw> FIXED_CDD_STRINGS qqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqu   x m> NO qj x   m> ( wqqqqqw> BLANK_FILL q> , wqqqqqqw> FIXED_CDD_STRINGS q> ) j   m> NO j m> NO qj    (B)0constraint-options =    qqqqq> CONSTRAINT_MODE = qwq> IMMEDIATE qqqqqqqqqqqqqqqqqwq>   tq> DEFERRED qqqqqqqqqqqqqqqqqqu   tq> ON qqqqqqqqqqqqqqqqqqqqqqqqu   mq> OFF qqqqqqqqqqqqqqqqqqqqqqqj    (B)0database-options =    qqwqq> ELN qqqqqqqqqqqqqqqqqqqqqwqq>   tqq> NSDS qqqqqqqqqqqqqqqqqqqqu   tqq> rdb-options qqqqqqqqqqqqqu   tqq> VIDA qqqqqqqqqqqqqqqqqqqqu   tqq> VIDA=V1 qqqqqqqqqqqqqqqqqu   tqq> VIDA=V2 qqqqqqqqqqqqqqqqqu   tqq> VIDA=V2N qqqqqqqqqqqqqqqqu   tqq> NOVIDA qqqqqqqqqqqqqqqqqqu   tqq> DBIV1 qqqqqqqqqqqqqqqqqqqu   tqq> DBIV31 qqqqqqqqqqqqqqqqqqu   mqq> DBIV70 qqqqqqqqqqqqqqqqqqj    (B)0 rdb-options =    qwq> RDBVMS qqwqq>  tq> RDB030 qqu   tq> RDB031 qqu   tq> RDB040 qqu   tq> RDB041 qqu  tq> RDB042 qqu tq> RDB050 qqu tq> RDB051 qqu tq> RDB060 qqu tq> RDB061 qqu tq> RDB070 qqu mq> RDB071 qqj (B)0       optimization-options=  qqqq> OPTIMIZATION_LEVEL= qwqqqq> DEFAULT qqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqwq>  mqq> ( qwwq> AGGRESSIVE_SELECTIVITY qqwqqwq ) qj   xtq> FAST_FIRST  qqu x     xtq> SAMPLED_SELECTIVITY qqqqu x     xmq> TOTAL_TIME  qqqqqqqqqqqqj x   mqqqqqq , int16 SMALLINT Requires #include __int16SMALLINT int32 INTEGER Requires #include __int32INTEGER int64 BIGINT Requires #include __int64BIGINT $SQL_VARCHAR (n) The CHARACTER SET clause is optional. SQL_DATE The SQL precompiler will transform the SQL_DATE_ANSI pseudo types in natvie C datatypes SQL_DATE_VMS SQL_TIME SQL_TIMESTAMP SQL_INTERVAL (DAY Use this data type for variables that TO SECOND) represent the difference between two dates or times. Precompiler Date-Time Data Mapping lists all the supported INTERVAL data types. 3 COBOL_Variables The following list describes the variable declaration syntax for character data types that the SQL precompiler supports in COBOL: o PICTURE IS can be abbreviated as PICTURE or PIC. o CHARACTER SET character-set-name PICTURE IS. o PICTURE clauses for numeric variables must begin with S (must be signed) and cannot include P characters. o PICTURE clauses cannot include editing characters. For information about the supported character sets, see the Oracle Rdb SQL Reference Manual. The following list describes the variable declaration syntax that the SQL precompiler supports in COBOL: o PICTURE IS clause - PICTURE IS can be abbreviated as PICTURE or PIC. - PICTURE clauses for numeric variables must begin with S (must be signed) and cannot include P characters. - PICTURE clauses cannot include editing characters. o USAGE IS clause - USAGE IS must immediately follow a PICTURE clause. - USAGE IS can be abbreviated as USAGE or omitted completely. - USAGE IS must have as an argument BINARY, COMPUTATIONAL, COMPUTATIONAL-1, COMPUTATIONAL-2, or COMPUTATIONAL-3. COMPUTATIONAL can be abbreviated as COMP in all USAGE IS or DISPLAY declarations. BINARY is a synonym for COMPUTATIONAL or COMP. o VALUE IS clause VALUE IS can be abbreviated as VALUE and is allowed without restriction. o IS EXTERNAL clause IS EXTERNAL can be abbreviated as EXTERNAL and is allowed without restriction. o IS GLOBAL clause IS GLOBAL can be abbreviated as GLOBAL and is allowed without restriction. o SIGN clause SIGN is allowed but must immediately follow a PICTURE clause or a USAGE IS clause. o Group data items - Group data items are allowed without restriction. - Variables associated with the SQL VARCHAR and LONG VARCHAR data types must be declared as group data items with two elementary items at level 49. The first elementary item must be a small integer to contain the actual length of the character string. The second elementary item must be a character string long enough to contain the string itself. * Declaration for an SQL column * defined as VARCHAR (80): * 01 VARYING_STRING. 49 STRING_LENGTH PIC S9(4) USAGE IS COMP. 49 STRING_TEXT PIC X(80). o OCCURS n TIMES clause - OCCURS clauses are permitted only for declarations of indicator arrays. Although you can use any data type for indicator array elements, Oracle Rdb recommends that you declare them as integers (PIC S9(9) COMP). - Multidimension tables (nested OCCURS clauses) and variable- occurrence data items (OCCURS DEPENDING ON clause) are not supported. o REDEFINES clauses You can refer to host language variables that have a REDEFINES clause or that are subordinate to a REDEFINES clause. o SQL date-time data types - SQL_DATE, SQL_DATE_ANSI, SQL_DATE_VMS - SQL_TIME, SQL_TIMESTAMP - SQL_INTERVAL (DAY TO SECOND) Use this data type for variables that represent the difference between two dates or times. (Precompiler Date- Time Data Mapping lists all the supported INTERVAL data types.) The precompiler replaces these data types with host language data declarations that are supported in the compilers themselves. 3 FORTRAN_Variables The following list describes the variable declaration syntax for character data types that the SQL precompiler supports in FORTRAN: o CHARACTER o CHARACTER character-set-name For information about the supported character sets, see the Oracle Rdb SQL Reference Manual. The following list describes the variable declaration syntax that the SQL precompiler supports in FORTRAN: o Declarations - See the following table o Initial values assigned in the declaration o STRUCTURE declarations o UNION declarations within structures o RECORD statements o DIMENSION statements - DIMENSION statements are permitted only for declarations of indicator arrays. Although you can use any data type for indicator array elements, Oracle Rdb recommends that you use variables of the INTEGER data type. - Multidimension arrays and dynamic-sized arrays are not supported. Table 8 Supported FORTRAN Datatypes FORTRAN type SQL type Comments and Restrictions BYTE TINYINT CHARACTER*n CHAR The n represents a positive integer literal INTEGER INTEGER INTEGER*1 TINYINT INTEGER*2 SMALLINT INTEGER*4 INTEGER INTEGER*8 BIGINT LOGICAL INTEGER LOGICAL*1 TINYINT LOGICAL*2 SMALLINT LOGICAL*4 INTEGER LOGICAL*8 BIGINT REAL REAL REAL*4 REAL REAL*8 DOUBLE PRECISION STRUCTURE VARCHAR The named structure can be used /name/ to define other FORTRAN host integer*2 variables. The len component of len the structure must be set to the character*n correct length of the string before body use as a parameter to SQL. The END n represents a positive integer STRUCTURE literal SQL_DATE The SQL precompiler will transform SQL_DATE_ the pseudo types in native FORTRAN ANSI datatypes. SQL_DATE_VMS SQL_TIME SQL_ TIMESTAMP SQL_INTERVAL Use this data type for variables (DAY TO that represent the difference SECOND) between two dates or times. Precompiler Date-Time Data Mapping lists all the supported INTERVAL data types. Implicit declarations are not supported. SQL generates a "host variable was not declared" error when it encounters an implicitly declared variable in an SQL statement. 3 Pascal_Variables The following list describes the variable declaration syntax that the SQL precompiler supports in Pascal: o Data type keywords Declarations can include only the following Pascal data types: - INTEGER8, INTEGER16, INTEGER32, and INTEGER64 - REAL - SINGLE - DOUBLE - F_FLOAT - D_FLOAT - G_FLOAT - S_FLOAT - T_FLOAT - CHAR - PACKED ARRAY [1..n] OF CHAR; - VARYING [u] OF CHAR - [BYTE] -128..127; - [WORD] -32768..32767; - Date-time data types (Precompiler Date-Time Data Mapping lists these data types.) In addition, the SQL Pascal precompiler provides the following data types: - SQL_LONG_VARCHAR - SQL_DATE - SQL_SMALLINT - SQL_INDICATOR - SQL_BIGINT - SQL_QUAD - SQL_DATE, SQL_DATE_ANSI, SQL_DATE_VMS - SQL_TIME, SQL_TIMESTAMP - SQL_INTERVAL (DAY TO SECOND) Use this data type for variables that represent the difference between two dates or times. (Precompiler Date- Time Data Mapping lists all the supported INTERVAL data types.) o Records The SQL precompiler supports Pascal record definitions. It also supports nested records such as the following: type_record_type = record employee_id : employee_id_str; last_name : last_name_str; first_name : first_name_str; middle_init : middle_init_str; address_dat1: address_str; address_dat2: address_str; city : city_str; state : state_str; postal_code : postal_code_str; sex : sex_str; status_code : status_code_str; end; name_rec = record last_name : last_name_str; first_name : first_name_str; middle_init : middle_init_str; end; address_rec = record address_dat1 : address_str; address_dat2 : address_str; city : city_str; state : state_str; postal_code : postal_code_str; end; rec_in_rec = record employee_id : employee_id_str; emp_name : name_rec; emp_addr : address_rec; sex : sex_str; status_code : status_code_str; end; rec_in_rec_in_rec = record nested_again : rec_in_rec; end; A record that is used in an SQL statement cannot contain a pointer to another record. The SQL precompiler does not support variant records. o Initial value assignments The SQL precompiler supports initial values assigned in the declaration: dateind : SQL_INDICATOR:=0; o Arrays Packed arrays are supported to declare SQL character strings. Single-dimension arrays are supported to declare an indicator array to refer to a structure in SQL statements. The elements of the array must be declared as word integers [WORD]- 32768..32767 or SQL_INDICATOR. o Pointers The SQL precompiler for Pascal supports one level of pointers. type a = ^integer; var b : a; (* the use of the variable b is supported *) c : ^a; (* do not use any form of variable c in an SQL statement) NOTE The Pascal precompiler for SQL gives an incorrect %SQL-I- UNMATEND error when it parses a declaration of an array of records. It does not associate the END with the record definition, and the resulting confusion in host variable scoping causes a fatal error. To avoid the problem, declare the record as a type and then define your array of that type. For example: main.spa: program main (input,output); type exec sql include 'bad_def.pin'; !gives error exec sql include 'good_def.pin'; !ok var a : char; begin end. --------------------------------------------------------------- bad_def.pin x_record = record y : char; variable_a: array [1..50] of record a_fld1 : char; b_fld2 : record; t : record v : integer; end; end; end; end; --------------------------------------------------------------- good_def.pin good_rec = record a_fld1 : char; b_fld2 : record t : record v: integer; end; end; end; x_record = record y : char variable_a : array [1..50] of good_rec; end; 3 PLI_Variables The following list describes the variable declaration syntax that the SQL precompiler supports in PL/I: o Declarations Declarations can include only the following PL/I data types: - CHARACTER CHARACTER can be abbreviated as CHAR. - CHARACTER VARYING CHARACTER VARYING can be abbreviated as CHAR VAR. - Date-time data types (Precompiler Date-Time Data Mapping lists these data types.) - TINYINT TINYINT is FIXED BINARY(7). - FIXED BINARY, FIXED DECIMAL BINARY can be abbreviated as BIN, and DECIMAL can be abbreviated as DEC. Scale factors are not allowed on FIXED BINARY declarations. - FLOAT BINARY, FLOAT DECIMAL - SQL_DATE, SQL_DATE_ANSI, SQL_DATE_VMS - SQL_TIME, SQL_TIMESTAMP - SQL_INTERVAL (DAY TO SECOND) Use this data type for variables that represent the difference between two dates or times. (Precompiler Date- Time Data Mapping lists all the supported INTERVAL data types.) - DECIMAL data type is converted to FIXED - NUMERIC data type is converted to PACKED o Storage class attributes Any of the storage class attributes (BASED, AUTOMATIC, DEFINED, STATIC, variable, EXTERNAL, and INTERNAL) is allowed. The BASED attribute declarations must include a location reference. o INITIAL attribute o Structures Structures are allowed without restriction. o Arrays Arrays are permitted only for declarations of indicator arrays. Although you can use any data type for indicator array elements, Oracle Rdb recommends that you declare them as INTEGER variables. Multidimension array items are not supported. Arrays of structures are not supported. Arrays that are in a group that is itself an array are not supported. Dynamic-sized arrays are not supported.