INFORMIX
Informix-ESQL/C Programmer's Manual
Chapter 8: Working with Simple Large Objects
Home Contents Index Master Index New Book

Programming with Simple Large Objects

ESQL/C supports the SQL simple large objects, the data types TEXT and BYTE, with the loc_t data type.

Tip: You cannot use literal values within an INSERT or UPDATE statement to put simple-large-object data within a TEXT or BYTE column. To insert values into a simple large object, you can use the LOAD statement from DB-Access or loc_t host variables from within an ESQL/C client application.
Because of the potentially huge size of simple-large-object data, the ESQL/C program does not store the data directly in a loc_t host variable. Instead, the loc_t structure is a locator structure. It does not contain the actual data; it contains information about the size and location of the simple-large-object data. You choose whether to store the data in memory, an operating-system file, or even user-defined locations.

To use simple-large-object variables in an ESQL/C program, take the following actions:

Declaring a Host Variable for a Simple Large Object

Use the loc_t data type to declare host variables for database values of type TEXT or BYTE. You declare a host variable for a simple-large-object column with the data type loc_t, as shown in the following example:

A locator variable with a TEXT data type has the loc_type field of the locator structure set to SQLTEXT. For a BYTE variable, loc_type is SQLBYTE. For more information on the fields of the locator structure, see "The Fields of the Locator Structure".

Tip: The sqltypes.h header file defines both SQLTEXT and SQLBYTE. Therefore, make sure you include sqltypes.h before you use these constants.
From an ESQL/C program, you can both select and insert simple-large-object data into loc_t host variables. You can also select only portions of a simple-large-object variable with subscripts on the simple-large-object column name. These subscripts can be coded into the statement as shown in the following example:

Subscripts can also be passed as input parameters as the following code fragment shows:

Accessing the Locator Structure

In an ESQL/C program, you use a locator structure to access simple-large-object values. The locator structure is the host variable for TEXT and BYTE columns when they are stored in or retrieved from the database. This structure describes the location of a simple-large-object value for the following two database operations:

The locator.h header file defines the locator structure, called loc_t. Figure 8-1 shows the definition of the loc_t locator structure from the locator.h file.

Figure 8-1
Declaration of loc_t in the locator.h Header File

In Figure 8-1, the following comments in the locator.h file indicate how the fields are used in the locator structure.

Comment Description

USER

The ESQL/C program sets the field, and the ESQL/C libraries inspect the field.

SYSTEM

The ESQL/C libraries set the field, and the ESQL/C program inspects the field.

INTERNAL

The field is a work area for the ESQL/C libraries, and the ESQL/C program does not need to examine the field.

ESQL/C does not automatically include the locator.h header file in an ESQL/C program. You must include the locator.h header file in any ESQL/C program that defines simple-large-object variables.

The Fields of the Locator Structure

The locator structure has the following parts:

Figure 8-2 lists the fields in the locator structure common to all simple-large-object locations.

Figure 8-2
Fields in Locator Structure Common to all Simple-Large-Object Data Locations

Field Data Type Description

loc_indicator

long

A value of -1 in the loc_indicator field indicates a null simple-large-object value. The ESQL/C program can set the field to indicate insertion of a null value; ESQL/C libraries set it on a select or fetch.

You can also use the loc_indicator field to indicate an error when your program selects into memory. If the simple large object to be retrieved does not fit in the space provided, the loc_indicator field contains the actual size of the simple large object.

loc_size

long

Contains the size of the simple-large-object data in bytes. This field indicates the amount of simple-large-object data that the ESQL/C libraries read or write. The ESQL/C program sets loc_size when it inserts a simple large object in the database; the
ESQL/C libraries set loc_size after it selects or fetches a simple large object.

loc_status

int

Indicates the status of the last locator operation. The ESQL/C libraries set loc_status to zero when a locator operation is successful and to a negative value when an error occurs. The SQLCODE variable also contains this status value.

loc_type

long

Specifies whether the data type of the variable is TEXT (SQLTEXT) or BYTE (SQLBYTES). The sqltypes.h header file defines SQLTEXT and SQLBYTES.

Locations for Simple-Large-Object Data

Before your ESQL/C program accesses a simple-large-object column, it must determine where the simple-large-object data is located. To specify whether the simple large object is located in memory or in a file, specify the contents of the loc_loctype field of the locator structure. Figure 8-3 shows the possible locations for simple-large-object data.

Figure 8-3
Possible Locations for Simple-Large-Object Data

Value of loc_loctype Field Location of Simple-Large-Object Data Reference

LOCMEMORY

In memory

page 8-11

LOCFILE

In an open file

page 8-21

LOCFNAME

In a named file

page 8-26

LOCUSER

At a user-defined location

page 8-31

Set loc_loctype after you declare the locator variable and before this declared variable receives a simple-large-object value.

The locator.h header file defines the LOCMEMORY, LOCFILE, LOCFNAME, and LOCUSER location constants. In your ESQL/C program, use these constant names rather than their constant values when you assign values to loc_loctype.

In a client-server environment, ESQL/C locates the simple large object on the client computer (the computer on which the application runs).




Informix-ESQL/C Programmer's Manual, version 9.1
Copyright © 1998, Informix Software, Inc. All rights reserved.