Example 9: Text and image routines

The example9.c sample program generates a random image, inserts it into a table, then selects the image and compares it to the original by following these steps:

  1. insert all data into the row except the text or image value.

  2. update the row, setting the value of the text or image to NULL. This step is necessary because a text or image column row that contains a null value will have a valid text pointer only if the null value was explicitly entered with the update statement.

  3. select the row. You must specifically select the column that is to contain the text or image value. This step is necessary to provide the application’s DBPROCESS with correct text pointer and text timestamp information. The application should throw away the data returned by this select.

  4. Call dbtxtptr to retrieve the text pointer from the DBPROCESS. dbtxtptr’s column parameter is an integer that refers to the select performed in step 3. For example, if the select is:

    select date_column, integer_column, text_column
    
         from bigtable
    

    and text_column is the name of the text column, dbtxtptr requires the column parameter to be passed as 3.

  5. Call dbtxtimestamp to retrieve the text timestamp from the DBPROCESS. dbtxtimestamp’s column parameter refers to the select performed in step 3.

  6. Write the text or image value to Adaptive Server. An application can either:

    • Write the value with a single call to dbwritetext, or

    • Write the value in chunks, using dbwritetext and dbmoretext.

  7. If you intend the application to make another update to this text or image value, it may want to save the new text timestamp that is returned by Adaptive Server at the conclusion of a successful dbwritetext operation. Access the new text timestamp by using dbtxtsnewval, and stored for later retrieval using dbtxtsput.

NoteAccess to an Adaptive Server that contains the pubs2 database is required.