6. Embedded SQL for BASIC : Advanced Processing : Sample Programs : Handler
 
Share this page                  
Handler
This program inserts a row into the book table using the data handler Put_Handler to transmit the value of column chapter_text from a text file to the database. Then it selects the column chapter_text from the table book using the data handler Get_Handler to process each row returned.
!main program
!*****************

    program handler
        exec sql include sqlca
! Do not declare the data handlers nor the data handler
! argument to the ESQL preprocessor
        external integer Put_Handler
        external integer Get_Handler
        record hdlr_arg
                string  argstr    
                integer argint
        end record hdlr_arg
        declare hdlr_arg hdlarg
! Null indicator for data handler must be declared to ESQL
        exec sql begin declare section
                word indvar
        exec sql end declare section
! INSERT a long varchar value chapter_text into the
! table book using the data handler put_handler. The
! argument passed to the data handler the record hdlarg.

    . . .

        exec sql insert into book (chapter_name, chapter_text) &
                values (5, 'One Dark and Stormy Night',
               data handler(Put_Handler(hdlarg)))

! SELECT the long varchar column chapter_text from
! The data handler (get_handler) will be invoked for
! each non-null value of column chapter_text retrieved.
! For null values the indicator variable will be set
! to "-1" and the data handler will not be called.

    ...
    exec sql select chapter)text into           &
                data handler(get_handler(hdlarg)):indvar from book
    exec sql begin
            process row...
    exec sql end
    ...
    
    end program