INFORMIX DataBlade Developers Kit Tutorial

List of Exercises

Exercise 7: Using Smart Large Objects, Continued


5

Modify source code.

The source code for the Poem DataBlade module is in the Poem.c file in the src/c directory.

The following table lists the internal support functions for the Poem opaque data type.

Support Routine Category Smart Large Object Handling

Text Input and Output Functions

The PoemInput() function creates a smart large object handle and inserts it in the database table column. Then the function assigns a location in the sbspace for the data file and copies the file to that location.

The PoemOutput() function reads the smart large object handle and generates a random filename for the data file. Then the function creates a file on the client computer and copies the smart large object data into it.

Binary Send and Receive Functions

The PoemSend() and PoemReceive() functions move the binary format of the smart large object handle between the database server and client computers.

Binary File Import and Export Functions

The PoemImportBinary() and PoemExportBinary() functions perform bulk copies of the binary format of the smart large object handle between the database server and external files.

Text File Import and Export Functions

The PoemImportText() and PoemExportText() functions perform bulk copies of the text format of the smart large object handle between the database server and external files.

Contains Large Objects Routines

The PeomLOhandles() function returns a list of the MI_LO_HANDLES structures in an opaque data type. The database server calls this function when archiving or performing oncheck operations.

The PoemAssign() function adds to the reference count for the smart large object before it saves the handle in the database and the data in the sbspace (if it is not already present).

The PoemDestroy() procedure decrements the reference count for the smart large object before deleting the handle from the database and the data from the sbspace (if the reference count is zero).

Type Compare Functions

The PoemCompare() function compares the handles of two opaque data types and determines whether they are the same.

The PoemEqual() and PoemNotEqual() functions call the PoemCompare() function.

The default behavior for the PoemOutput() function is to generate a random number filename. However, you can modify the source code for this function so that it generates a meaningful filename: the title of the poem. The data files for the Poem DataBlade module are XML files containing poems by Edgar Allan Poe. The title of the poem appears in the beginning of the file; you can extract the title and use it to create the filename. You use DataBlade API functions to open and read smart large objects; the process is similar to opening and reading a file.

In the PoemOutput() function, add the following code after the /* Format the attribute value into the output string. */ comment:

         {
    char PoemStart[128];
    char * pTag1 = NULL;
    char * pTag2 = NULL;
    MI_LO_FD LO_fd;
    
    /* 
    * Get the poem title: open the smart large object, read the first 127 bytes,
    * look for the begin-title and end-title XML tags, then close the object.
    */
    LO_fd = mi_lo_open( Gen_Con, &Gen_InData->poem, MI_LO_RANDOM | MI_LO_RDONLY );
    if (LO_fd != MI_ERROR)
         {
         mi_lo_read( Gen_Con, LO_fd, PoemStart, 127);
         PoemStart[127] = 0;
         pTag1 = strstr( PoemStart, "<title>" );
         pTag2 = strstr( PoemStart, "</title>" );
         if (pTag2 != NULL)
              *pTag2 = 0;
         mi_lo_close( Gen_Con, LO_fd );
         }
    
    /*
    * Build the filename: if the title tags are found, use the poem title plus an
    * ".xml" extension as the filename, otherwise, use the name "poem.xml". 
    */
    if (pTag1 != NULL)
         {
         strcpy( Gen_LOFile, pTag1 + 7 );
         strcat(Gen_LOFile, ".xml!" );
         /* The "!" indicates that the filename need not be unique. */
         }
    else
         strcpy( Gen_LOFile, "poem.xml" );
    
         }
    
    

For more information on the mi_lo_open(), mi_lo_read(), and mi_lo_close() functions, see the DataBlade API Programmer's Manual. The Gen_LOFile() function is a BladeSmith utility function that calls the mi_lo_to_file() DataBlade API function. For information on the mi_lo_to_file() function and the ! filename wildcard symbol, see the DataBlade API Programmer's Manual.

Remove the following statement after the /* Save the large object to disk. */ comment:

    strcpy( Gen_LOFile, LO_FN_MASK );
    
    

Check your source code against the final version of Poem.c.

Save the changes to Poem.c.


Copyright © 1998, Informix Software, Inc. All rights reserved.