2. Embedded SQL for C : Advanced Processing : Sample Programs : Put Handler
 
Share this page                  
Put Handler
This example shows how to read the long varchar chapter_text from a text file and insert it into the database a segment at a time.
Int
Put_Handler(hdlr_arg)
 HDLR_PARAM *hdlr_arg;
 {
    /*
    ** Host variables in the put data statement must
    ** be declared to the ESQL preprocessor
    */
    exec sql begin declare section;
        char seg_buf[1000];
        int seg_len;
        int data_end;
    exec sql declare section;
    int more_data;
    open file...
    data_end = 0;
    more_data = 1;
    while (more_data == 1)
    {
    read segment of less than 1000 chars from
    file into seg_buf...
    if (end_of_file)
    {
        data_end = 1;
        more_data = 0;
     }
    seg_len = number_of_bytes_read;
    exec sql put data (segment = :seg_buf,
                        segmentlength = :seg_len,
                        dataend = :data_end);
    };
    . .
    close file...
    set hdlr_arg fields to return appropriate
        values...
    . . .
 }