Teradata Mode Communications Area - Teradata Preprocessor2

Teradata® Preprocessor2 for Embedded SQL Programmer Guide

Product
Teradata Preprocessor2
Release Number
17.00
Published
June 2020
Language
English (United States)
Last Update
2020-06-19
dita:mapPath
whb1544831946911.ditamap
dita:ditavalPath
obe1474387269547.ditaval
dita:id
B035-2446
lifecycle
previous
Product Category
Teradata Tools and Utilities

When writing C programs for Teradata mode, define a SQL communications area (SQLCA). PP2 generates statements that require the name sqlca.

See Teradata Vantage™ - SQL Stored Procedures and Embedded SQL , B035-1148 for details of the SQLCA fields.

Obtain the necessary SQLCA structure in one of these ways:
  • Code the SQLCA directly into the program. The structure must be named sqlca and must be unique.
  • Incorporate an EXEC SQL INCLUDE SQLCA; the statement causes PP2 to generate the structure.

Determine the appropriate storage class for the SQLCA structure when coding it directly into the application. The SQLCA structure obtained by the INCLUDE SQLCA statement is defined as an auto storage class variable. This classification permits use of a single SQLCA structure by all functions within a given compilation unit.

Always use a single, global SQLCA for each compilation unit because multiple SQLCA structures can cause communication problems.

The precompiler generates code using references to SQLCODE and SQLWARN0. This usage requires that those fields be accessible by all of the SQL statements within the compilation unit.

The code to generate an SQLCA structure for a C application is:

#ifndef SQLCODE
       struct sqlca {
                     unsigned char         sqlcaid[8];
                     int                   sqlcabc;
                     int                   sqlcode;
                     struct {
                             short         StrLen;
                             unsigned char Str[70];
                            } SqlErrm;
                     unsigned char         sqlerrp[8];
                     int                   sqlerrd[6];
                     unsigned char         sqlwarn[11];
                     unsigned char         sqlext[5];
                    };
#define     SQLCODE  sqlca.sqlcode
#define     SQLWARN0 sqlca.sqlwarn[0]
#define     SQLWARN1 sqlca.sqlwarn[1]
#define     SQLWARN2 sqlca.sqlwarn[2]
#define     SQLWARN3 sqlca.sqlwarn[3]
#define     SQLWARN4 sqlca.sqlwarn[4]
#define     SQLWARN5 sqlca.sqlwarn[5]
#define     SQLWARN6 sqlca.sqlwarn[6]
#define     SQLWARN7 sqlca.sqlwarn[7]
#define     SQLWARN8 sqlca.sqlwarn[8]
#define     SQLWARN9 sqlca.sqlwarn[9]
#define     SQLWARNA sqlca.sqlwarn[10]
#define     SQLCA    sqlca
#define     SqlCABC  sqlcabc
#define     SqlCode  sqlcode
#define     sqlerrml SqlErrm.StrLen
#define     sqlerrmc SqlErrm.Str
#define     SqlErrp  sqlerrp
#define     SqlErrd  sqlerrd
#define     SqlWarn0 SQLWARN0
#define     SqlWarn1 SQLWARN1
#define     SqlWarn2 SQLWARN2
#define     SqlWarn3 SQLWARN3
#define     SqlWarn4 SQLWARN4
#define     SqlWarn5 SQLWARN5
#define     SqlWarn6 SQLWARN6
#define     SqlWarn7 SQLWARN7
#define     SqlWarn8 SQLWARN8
#define     SqlWarn9 SQLWARN9
#define     SqlWarnA SQLWARNA
#define     SqlExt   sqlext
#endif

When coding the SQLCA for a program, use #define for SQLCODE; the precompiler generates code for the WHENEVER statement using an uppercase SQLCODE reference.

Likewise, use #define for SQLWARN0. Specify any other #defines as necessary.