Modifying the source code
About this task
The source code for the Poem DataBlade® module is in the Poem.c file in the src/c directory, which you can see in Visual C++ under the Source Files node of the File view.
Support routine category | Smart large object handling |
---|---|
Text Input and Output Functions |
|
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 |
|
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 file name. However, you can modify the source code for this function so that it generates a meaningful file name: 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 file name. You use DataBlade® API functions to open and read smart large objects; the process is similar to opening and reading a file.
To add code to the PoemOutPut() function:
Procedure
- Double-click PoemOutPut() in the Class view
and 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 about the mi_lo_open(), mi_lo_read(), and mi_lo_close() functions, see the Informix® DataBlade® API Programmer's Guide. The Gen_LOFile() function is a BladeSmith utility function that calls the mi_lo_to_file() DataBlade® API function. For information about the mi_lo_to_file() function and the ! file name wildcard symbol, see the Informix® DataBlade® API Programmer's Guide.
- 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.