Requirements for Host Variables - 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

C Language and Host Variables

This section lists the requirements and limits for using host variables in a C program.

Any valid C host variable is permissible in a SQL statement. All variables are not valid, however. Host variables must meet certain requirements before PP2 accepts them in SQL statements. See Host Variable Declaration.

Any valid C variable name can be used as a host variable name, including names with embedded underscores ( _ ).

SQL and Host Variables

Declare host variables that will be used in SQL statements (that is, enclose host variables between BEGIN DECLARE/END DECLARE statements). Multiple declare sections are permissible. Variables declared elsewhere are not considered valid for SQL usage by PP2.

BEGIN DECLARE and END DECLARE are documented in “Embedded SQL” in Teradata Vantage™ - SQL Stored Procedures and Embedded SQL , B035-1148 .

Variable names used in SQL requests are case sensitive; for example, VAR1 is not equivalent to var1. Dynamic SQL, when executed in Teradata mode, returns a designation of character (452 or 453) to the SQLDA structure when a PREPARE...INTO or DESCRIBE is performed and no null terminator is supplied when the data is returned to the field.

Host variables that are not SQL strings represent data values only: they cannot be used to represent database, table, view, macro, or column names.

Indicator Variables

Use the form short [int] var1[x] only as an indicator array with a structure reference.

PP2 Issues

PP2 expects a terminating null character (‘\0’) on input and terminates the string with a ‘\0’ on output when used with a static request.

Change the type designation in the application to receive a null terminated field.

Declare a host variable as a variable character field by using the PP2 directive VARCHAR. This designation is replaced by a structure when the C code is generated.

Any terminating null is treated as part of the string, both when used as input and as output. For details, see "Varying Character Data" in Server to Host Assignment.

Host Variable Declaration

Use the following C type specifiers and declarations to define a host variable declaration:

auto
char
double
extern
float
int
long
short
static
struct (excluding tag type definitions)
unsigned char

A host variable that is defined as a “long” data type will be 4 bytes when compiled with the 32-bit compiler option and 8 bytes when compiled with the 64-bit compiler options on the Solaris, AIX or 64-bit Windows platforms.

When generating SQLDA for the static SQL statement, the PP2 precompiler assigns:
  • SQLTYPE to the INTEGER data type
  • SQLLEN to “sizeof(long)”

The following C type specifiers and declarations cannot be used to declare a host variable:

#define
enum
pointer designation (char *var1)
register
structure definition via tags
typedef
union
unsigned integer types
void

Specify C array dimensions by a numeric literal. Defined constants or numeric expressions are not allowed within a C array declaration.