Sybase Technical Library - Product Manuals Home
[Search Forms] [Previous Section with Hits] [Next Section with Hits] [Clear Search] Expand Search

Host variable descriptions in the SQLDA [Table of Contents] Using stored procedures in Embedded SQL

ASA Programming Interfaces Guide

[-] Chapter 2: The Embedded SQL Interface
[-] The SQL descriptor area (SQLDA)
[-] Length field values

Length field values

The sqllen field length of the sqlvar structure in a SQLDA is used in three different kinds of interactions with the database server. The following tables detail each of these interactions. These tables list the interface constant types (the DT_ types) found in the sqldef.h header file. These constants would be placed in the SQLDA sqltype field. The types are described in Embedded SQL data types .

In static SQL, a SQLDA is still used but it is generated and completely filled in by the SQL preprocessor. In this static case, the tables give the correspondence between the static C language host variable types and the interface constants.

DESCRIBE

The following table indicates the values of the sqllen and sqltype structure members returned by the DESCRIBE command for the various database types (both SELECT LIST and BIND VARIABLE DESCRIBE statements). In the case of a user-defined database data type, the base type is described.

Your program can use the types and lengths returned from a DESCRIBE, or you may use another type. The database server will perform type conversions between any two types. The memory pointed to by the sqldata field must correspond to the sqltype and sqllen fields.

For information on Embedded SQL data types, see Embedded SQL data types .

Database field type

Embedded SQL type returned

Length returned on describe

BIGINT

DT_BIGINT

8

BINARY(n)

DT_BINARY

n

BIT

DT_BIT

1

CHAR(n)

DT_FIXCHAR

n

DATE

DT_DATE

length of longest formatted string

DECIMAL(p,s)

DT_DECIMAL

high byte of length field in SQLDA set to p, and low byte set to s

DOUBLE

DT_DOUBLE

8

FLOAT

DT_FLOAT

4

INT

DT_INT

4

LONG BINARY

DT_LONGBINARY

32767

LONG VARCHAR

DT_LONGVARCHAR

32767

REAL

DT_FLOAT

4

SMALLINT

DT_SMALLINT

2

TIME

DT_TIME

length of longest formatted string

TIMESTAMP

DT_TIMESTAMP

length of longest formatted string

TINYINT

DT_TINYINT

1

UNSIGNED BIGINT

DT_UNSBIGINT

8

UNSIGNED INT

DT_UNSINT

4

UNSIGNED SMALLINT

DT_UNSSMALLINT

2

VARCHAR(n)

DT_VARCHAR

n

Supplying a value

The following table indicates how you specify lengths of values when you supply data to the database server in the SQLDA.

Only the data types shown in the table are allowed in this case. The DT_DATE, DT_TIME and DT_TIMESTAMP types are treated the same as DT_STRING when supplying information to the database; the value must be a NULL-terminated character string in an appropriate date format.

Embedded SQL Data Type

Program action to set the length

DT_BIGINT

No action required

DT_BINARY(n)

length taken from field in BINARY structure

DT_BIT

No action required

DT_DATE

length determined by terminating \0

DT_DECIMAL(p,s)

high byte of length field in SQLDA set to p, and low byte set to s

DT_DOUBLE

No action required

DT_FIXCHAR(n)

length field in SQLDA determines length of string

DT_FLOAT

No action required

DT_INT

No action required

DT_SMALLINT

No action required

DT_STRING

length determined by terminating \0

DT_TIME

length determined by terminating \0

DT_TIMESTAMP

length determined by terminating \0

DT_TIMESTAMP_STRUCT

No action required

DT_UNSBIGINT

No action required

DT_UNSINT

No action required

DT_UNSSMALLINT

No action required

DT_VARCHAR(n)

length taken from field in VARCHAR structure

DT_VARIABLE

length determined by terminating \0

Retrieving a value

The following table indicates the values of the length field when you retrieve data from the database using a SQLDA. The sqllen field is never modified when you retrieve data.

Only the interface data types shown in the table are allowed in this case. The DT_DATE, DT_TIME and DT_TIMESTAMP data types are treated the same as DT_STRING when you retrieve information from the database. The value is formatted as a character string in the current date format.

Embedded SQL Data Type

What the program must set length field to when receiving

How the database returns length information after fetching a value

DT_BIGINT

No action required

No action required

DT_BINARY(n)

maximum length of BINARY structure (n+2)

len 
field of BINARY structure set to actual length

DT_BIT

No action required

No action required

DT_DATE

length of buffer

\0 at end of string

DT_DECIMAL(p,s)

high byte set to p and low byte set to s

No action required

DT_DOUBLE

No action required

No action required

DT_FIXCHAR(n)

length of buffer

padded with blanks to length of buffer

DT_FLOAT

No action required

No action required

DT_INT

No action required

No action required

DT_SMALLINT

No action required

No action required

DT_STRING

length of buffer

\0 at end of string

DT_TIME

length of buffer

\0 at end of string

DT_TIMESTAMP

length of buffer

\0 at end of string

DT_TIMESTAMP_ STRUCT

No action required

No action required

DT_UNSBIGINT

No action required

No action required

DT_UNSINT

No action required

No action required

DT_UNSSMALLINT

No action required

No action required

DT_VARCHAR(n)

maximum length of VARCHAR structure (n+2)

len 
field of VARCHAR structure set to actual length


Host variable descriptions in the SQLDA [Table of Contents] Using stored procedures in Embedded SQL