Dynamic SQL - Preprocessor2 for Embedded SQL

Teradata Preprocessor2 for Embedded SQL Programmer Guide

Product
Preprocessor2 for Embedded SQL
Release Number
15.00
Language
English (United States)
Last Update
2018-09-27
dita:id
B035-2446
lifecycle
previous
Product Category
Teradata Tools and Utilities

Dynamic SQL

C supports dynamic SQL, and the application must contain the necessary SQL Descriptor Area (SQLDA) structures.

The SQLSTATE and SQLCODE variables are documented in “Result Code Variables” in SQL Stored Procedures and Embedded SQL (B035‑1148).

Include an SQLDA structure in one of the following ways:

  • Embed EXEC SQL INCLUDE SQLDA; the statement in the application causes PP2 to generate the structure.
  • Code the SQLDA directly into the program using any name.
  • The generated SQLDA structure for a C program is:

    #ifndef SQLDASIZE {
       struct sqlda {
          unsigned char sqldaid[8];
          int sqldabc;
          short sqln;
          short sqld;
          struct sqlvar {
             short sqltype;
             unsigned short sqllen;
             unsigned char *sqldata;
             short *sqlind;
             struct sqlname {
                short length;
                unsigned char data[30];
                } sqlname;
             } sqlvar[1];
          };
    #define SQLDASIZE(n)\
    (sizeof(struct sqlda) + ((n)-1)*sizeof(struct sqlvar)
    #endif

    The second example dynamic program at the end of this chapter shows how to use the INCLUDE SQLDA statement.