2. Embedded SQL for C : Advanced Processing : Sample Programs : Get Handler
 
Share this page                  
Get Handler
This example shows how to get the long varchar chapter_text from the database and write it to a text file.
Get_Handler(hdlr_arg)
 HDLR_PARAM *hdlr_arg;
 {
    /* Host variables in the get data statement must
    ** be declared to the ESQL preprocessor
    */
    exec sql begin declare section;
        char seg_buf[2000];
        int seg_len;
        int data_end;
        int max_len;
    exec sql end declare section;
    . . .
    process information passed in via the
         hdlr_arg...
    open file...
    /* Get a maximum segment length of 2000 bytes. */
    max_len = 2000;
    data_end = 0;
    while (data_end == 0)
    {
    /*
    ** segmentlength: will contain the length of the
    ** segment retrieved
    ** seg_buf: will contain a segment of the column
    ** chapter_text
    ** data_end: will be set to '1' when the entire
    ** value in chapter_text has been retrieved
    */
    exec sql get data (:seg_buf = segment,
                       :seg_len = segmentlength,
                       :data_end = dataend)
                        with maxlength = :max_len;
    write segment to a file...
    }
    . . .
    set hdlr_arg fields to return appropriate
         values...
    . .
}