6. Embedded SQL for BASIC : Advanced Processing : Sample Programs : Put Handler
 
Share this page                  
Put Handler
This user-defined handler shows how an application can use the put data handler to enter a chapter of a book from a text file into a database.
! Put_handler
! ************

100 function integer Put_handler(hdlr_arg info)

    record  hdlr_arg
        string argstr
        integer argint
    end record hdlr_arg
    exec sql begin declare section;
        declare sting segbuf
        declare integer seglen
        declare integer datend
    exec sql end declare sections
    process information passed in via the info record
    open file.....

    datend = 0
        while not end-of-file
            read segment from file into segbuf...
            
            if (end-of-file) then
                datend = 1
            end if
        exec sql put data (segment = :segbuf,           &
    segmentlength = :seglen, dataend = :datend)

    next
    ...
    close file...
    set info record to return appropriate values...
    ..
    Put_handler = 0
end function