15.10 - Host Variable Declaration - Preprocessor2 for Embedded SQL

Teradata Preprocessor2 for Embedded SQL Programmer Guide

prodname
Preprocessor2 for Embedded SQL
vrm_release
15.10
category
Programming Reference
featnum
B035-2446-035K

PP2 does not recognize every possible C variable declaration as valid for use in a SQL statement. For those types that have no direct C declaration, runtime processing allows the return of data to one of the other types.

Storage can be dynamically allocated for those data types not directly representable by a C declaration. This is useful when using dynamic SQLDA information returned by the Teradata Database.

The following table is a list of the equivalent C definitions for the Teradata Database data types.

 

Table 13: C Definitions for Teradata Database Data Types 

Data Type

Declaration

Notes

BYTE

No direct equivalent

1

VARBYTE

No direct equivalent

1

CHAR or CHAR (1)

char identifier;

 

CHAR (m)

char identifier [m+1];

2

VARCHAR (m)

VARCHAR identifier [m]

3

TIME

char identifier

9

TIMESTAMP

char identifier

10

DATE

long [int] identifier;

4

DECIMAL (m, n)

No direct equivalent

5

NUMERIC (m, n)

No direct equivalent

5

FLOAT*

float identifier;

 

REAL*

float identifier;

 

DOUBLEPRECISION*

float identifier;

 

FLOAT**

double identifier;

 

REAL**

double identifier;

 

DOUBLE PRECISION**

double identifier;

 

BYTEINT

No direct equivalent

6

SMALLINT

short [int] identifier;

7

INTEGER

long [int] identifier;

8

*single precision

**double precision

Note:  

1 )
Data can be returned to any valid host variable, although PP2 performs no data conversion.
2 )
The integer m must be positive, greater than one.
3 )
The integer m must be positive.

PP2 generates a structure with name identifier comprised of a short (2 bytes) len field and a character array field arr of length m.

No terminating null is expected or placed into the arr field.

4 )
The Teradata Database normally returns a DATE type field as integer.

It is possible to return the value in character string format, as long as the length of the receiving field is sufficient.

The DATEFORM=ANSIDATE format returns the DATE type field as CHAR (10).

5 )
Data can be returned to any valid numeric format, provided the value fits into the field specified.

It is possible to allocate sufficient storage dynamically to hold the decimal field.

In this case, the application must provide for the data returned.

6 )
Data can be returned to any valid numeric format, provided the value fits into the specified field.

It is possible to allocate sufficient storage dynamically to hold the byteint field.

In this case, the application must provide for the data returned.

7 )
PP2 allows specification of int identifier for a smallint on those systems where short and int are equivalent.

For a variable and statement it knows about, PP2 issues a warning about the size of the int field on a particular platform.

8 )
PP2 allows specification of int identifier for an integer on those systems where long and int are equivalent.

For a variable and statement it knows about, PP2 issues a warning about the size of the int field on a particular platform.

Note: The host variable 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, HP‑UX, 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)”
  • 9 )
    For TIME, the length of the char identifier should be 15.
    10 )
    For TIMESTAMP, the length of the char identifier should be 35.