728x90

Question

A sample ESQL/C program to insert data into a BLOB (TEXT) column using ESQL/C.

Answer

The attached program can be used as a reference for understanding the locator structure and how one can insert blob data via an ESQL/C program. This program is meant to be used only as a reference and no error checking has been taken into consideration. For example, the program will not check if the specified col1 number is valid or not. It is up to the programmer to put error checks into the code.

The Locator Structure
In an ESQL/C program, a locator structure is used to access simple-large-object values. The locator structure is the host variable for TEXT and BYTE columns when they are stored in or retrieved from the database. This structure describes the location of a simple-large-object value for the following two database operations:


The locator.h header file defines the locator structure, called loc_t. ESQL/C does not automatically include the locator.h header file in an ESQL/C program. The locator.h header file must be explicitly included in any ESQL/C program that defines simple-large-object variables.

The loc_loctype identifies the location of the simple large object data. When you setloc_bufsize to -1, ESQL/C allocates the memory buffer on a fetch or select. ESQL/C uses themalloc() system call to allocate the memory buffer to hold a single simple-large-object value.

Compilation
    1. Save the attached program as getblob.ec.
    2. Compile using the following syntax:
      esql putblob.ec -o putblob

Sample Output

    > putblob
    Enter a Catalog number :1
    Enter the description :
    Test insert
    Successful insert
Disclaimer: This code has been tested on Solaris only. Behavior on any other operating system is not guaranteed.



putblob.ec.txt
0.0MB
728x90

+ Recent posts