informix
Informix DataBlade API Programmer's Manual
Using Smart Large Objects

Obtaining the Status of a Smart Large Object

To obtain the status information for an existing smart large object, take the following steps.

Step Task Smart-Large-Object Function For More
Information
1. Obtain a valid LO file descriptor for the smart large object whose status information you need. mi_lo_create(), mi_lo_copy(), mi_lo_expand(), mi_lo_from_file() mi_lo_open() page 6-80
2. Allocate and fill an LO-status structure. mi_lo_stat() page 6-80
3. Use the appropriate LO-status accessor function to obtain the status information that you need. Figure 6-22 on page 6-82 page 6-82
4. Free resources. mi_lo_stat_free() page 6-84

Figure 6-21 shows the first three of these steps that a DataBlade API module uses to obtain status information for the smart large object data in the emp_picture column of the employee table (Figure 6-3 on page 6-16).

Figure 6-21
Obtaining Status Information

Obtaining a Valid LO File Descriptor

You can obtain status information for any smart large object for which you have a valid LO file descriptor. To obtain an LO file descriptor, you can perform any of the following steps:

Obtaining an LO-Status Structure

The mi_lo_stat() function is the constructor for the LO-status structure. It performs the following tasks:

  1. It obtains either a new or existing LO-status structure.
  2. It initializes the LO-status structure with all status information for the smart large object that the specified LO file descriptor identifies.
  3. Important: Do not handle memory allocation for an LO-status structure with system memory-allocation routines (such as malloc() or mi_alloc()) or by direct declaration. You must use the LO-status constructor, mi_lo_stat(), to allocate a new LO-status structure.

Allocating Memory for an LO-Status Structure

The third argument to the mi_lo_stat() function indicates whether to allocate a new LO-status structure:

For example, in the following code fragment, the mi_lo_stat() function allocates memory for the LO-status structure only when the first_time flag is true:

After the execution of mi_lo_stat() in the preceding code fragment, the LO_stat variable points to an allocated LO-status structure that contains status information for the smart large object that the LO file descriptor, LO_fd, identifies.

Important: Before you use an LO-status structure, make sure that you either call mi_lo_stat() with the LO-status pointer set to NULL or that you initialized this pointer with a previous call to mi_lo_stat().

For more information, see Figure 6-22 on page 6-82. For the syntax of the mi_lo_stat() function, see its description in Chapter 15, DataBlade API Function Descriptions.

Accessing Status Information

Once you have a valid LO-status structure, you can use the accessor functions to obtain the status information from this structure. Figure 6-22 shows the status information that an LO-status structure contains and the corresponding LO-status accessor functions.

Figure 6-22
Status Information in the LO-Status Structure

Status Information LO-Status Accessor Function
Last-access time This value is available only if the last-access time attribute (MI_LO_ATTR_KEEP_LASTACCESS_TIME) is set for this smart large object. mi_lo_stat_atime()
Storage characteristics These characteristics are stored in an LO-specification structure. Use the LO-specification accessor functions (see Defining User-Specified Storage Characteristics) to obtain information from this structure. mi_lo_stat_cspec()
Last-change time mi_lo_stat_ctime()
Last-modification time mi_lo_stat_mtime_sec()
Reference count mi_lo_stat_refcnt()
Size mi_lo_stat_size()

Important: The LO-status structure, MI_LO_STAT, is an opaque structure to DataBlade API modules. Do not access its internal structure directly. Informix does not guarantee that the internal structure of MI_LO_STAT will not change in future releases. Therefore, to create portable code, always use the LO-status accessor functions for this structure.

The following code fragment obtains the reference count from an LO-status structure that the LO_stat variable references:

The mi_lo_open() function opens the smart large object that the LO handle, LO_hdl, identifies. The mi_lo_stat() function then obtains the status information for this open smart large object. The mi_lo_stat() function performs the following tasks:

  1. Allocates a new LO-status structure because the value of *LO_stat is NULL.
  2. The mi_lo_stat() function assigns a pointer to this new LO-status structure to the LO_stat variable.

  3. Initializes the LO_stat structure with the status information for the open smart large object that the LO file descriptor, LO_fd, identifies.

Once the LO-status structure contains the status information, the mi_lo_stat_refcnt() accessor function obtains the reference count from the LO-status structure and returns it into the ref_count variable. When the code no longer needs the LO-status structure, it frees this structure with the mi_lo_stat_free() function.

Freeing an LO-Status Structure

The mi_lo_stat() function allocates an LO-status structure in the current memory duration. Therefore, if an LO-status structure has a memory duration of PER_ROUTINE, the database server automatically frees it when the user-defined routine completes.

To explicitly free the resources assigned to an LO-status structure, use the mi_lo_stat_free() function. The mi_lo_stat_free() function is the destructor function for an LO-status structure. When the resources are freed, they can be reallocated to other structures that your program needs.


Informix DataBlade API Programmer's Manual, Version 9.2
Copyright © 1999, Informix Software, Inc. All rights reserved