Once you have an LO-specification structure that describes the storage characteristics for the new smart large object, you can create the smart large object with one of the smart-large-object creation functions: mi_lo_copy( ), mi_lo_create( ), mi_lo_expand( ), or mi_lo_from_file( ). These smart-large-object creation functions perform the following tasks to create a new smart large object:
You provide a pointer to an LO handle as an argument to these functions. The creation functions initialize the LO handle with information about the location of the new smart large object.
You provide a pointer to an LO-specification structure as an argument to these functions. For more information, see Obtaining the LO-Specification Structure.
You provide the open mode as an argument to the mi_lo_create( ), mi_lo_copy( ), or mi_lo_expand( ) function. The mi_lo_from_file( ) function opens a smart large object in read/write mode. For more information, see Opening a Smart Large Object.
The mi_lo_copy( ), mi_lo_expand( ), and mi_lo_from_file( ) function specifies data to write to the sbspace of the new smart large object.
The LO file descriptor is needed for most subsequent operations on the smart large object. However, this LO file descriptor is only valid within the current database connection.
These smart-large-object creation functions initialize the following data type structures for a smart large object:
A DataBlade API module can obtain an LO handle with any of the following methods:
For more information, see Selecting the LO Handle.
Any of the smart-large-object creation functions (Table 29) can allocate memory for an LO handle when you specify a NULL-valued pointer for the last argument. For example, the following code fragment declares a pointer to an LO handle named LO_hdl, initializes it to NULL, and then calls the mi_lo_create( ) function to allocate memory for this LO handle:
MI_CONNECTION *conn; MI_LO_SPEC *LO_spec; MI_LO_HANDLE *LO_hdl = NULL; /* request allocation */ MI_LO_FD LO_fd; mi_integer flags; ... LO_fd = mi_lo_create(conn, &LO_spec, flags, &LO_hdl);
After the execution of mi_lo_create( ), the LO_hdl variable is a pointer to the new LO handle, which identifies the location of the new smart large object.
This new LO handle has a default memory duration of PER_ROUTINE. If you switch the memory duration, the creation function uses the current memory duration for the LO handle that it allocates.
If you provide an LO-handle pointer that does not point to NULL, the smart-large-object creation function assumes that memory has already been allocated for the LO handle and it uses the LO handle that you provide.
You can explicitly allocate an LO handle in either of the following ways:
MI_LO_HANDLE *LO_hdl = mi_alloc(sizeof(MI_LO_HANDLE));
MI_LO_HANDLE my_LOhndl; MI_LO_HANDLE *LO_hdl2, &my_LOhndl;
However, this LO handle is still an opaque C data structure; that is, it is declared as a flat array of undifferentiated bytes and its fields are not available to the DataBlade API module.
The smart-large-object creation functions (Table 29) return an LO file descriptor for a smart large object. The LO file descriptor is needed for most subsequent operations on the smart large object. However, this LO file descriptor is only valid within the current database connection.
The following code fragment uses the mi_lo_create( ) function to generate an LO file descriptor for a new smart large object:
MI_LO_FD LO_fd; MI_LO_HANDLE *LO_hdl; MI_LO_SPEC *LO_spec; MI_CONNECTION *conn; ... LO_fd = mi_lo_create(conn, LO_spec, MI_LO_RDONLY, &LO_hdl);