Get Handler
This user defined datahandler shows how an application can use the get data handler to enter a chapter of a book from a text file into a database.
function Get_Handler(info: hdlr_rec) :Integer;
begin
...
process information passed in via the info record...
open file ....
data_end := 0;
while (data_end = 0) do
begin
exec sql get data (:seg_buf=segment,
:seg_len = segmentlength,
:data_end = dataend)
with maxlength = :max_len;
write segment to file...
end;
. . .
set info record to return appropriate values...
...
Get_Handler := 0; {return value ignored }
end;
begin
-- INSERT a long varchar value chapter_text into
-- the table book using the datahandler Put_Handler
-- The argument passed to the datahandler the record
-- hdlr_arg.
--
...
...
exec sql insert into book (chapter_num, chapter_name, chapter_text)
values (5, 'One Dark and Stormy Night',
datahandler(Put_Handler(hdlr_arg)));
...
-- Select the long varchar column chapter_text from the table book.
-- The Datahandler (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 datahandler will not be called.
...
...
exec sql select chapter_text into
datahandler(Get_Handler(hdlr)arg)):indvar
from book;
exec sql begin;
process row....
exec sql end;
...
end.