15.10 - Dynamic SQL - Preprocessor2 for Embedded SQL

Teradata Preprocessor2 for Embedded SQL Programmer Guide

Preprocessor2 for Embedded SQL
Programming Reference

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)

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