Handler
This example assumes that the book table was created with the statement:
exec sql create table book (chapter_num integer,
chapter_name char(50), chapter_text long varchar)
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 retrieve the chapter_text column a segment at a time.
C main program
C ***************
program handler
exec sql include sqlca
C Do not declare the datahandlers nor the datahandler
C argument to the ESQL pre-processor.
external Put_Handler
integer Put_Handler
external Put_Handler
integer Get_Handler
structure /hdlr_arg/
character*1000 argstr
integer argint
end structure
record /hdlr_arg/hdlarg
C Null indicator for datahandler must be declared
C to ESQL
exec sql begin declare section
integer*2 indvar
integer*4 chapter_num
exec sql end declare section
C INSERT a long varchar value chapter_text into the table book
C using the datahandler Put_Handler.
C The argument passed to the datahandler is the address of
C the record hdlarg.
. . .
exec sql insert into book (chapter_num, chapter_name,
chapter_text)
1 values (5, 'One Dark and Stormy Night',
2 Datahandler(Put_Handler(hdlarg)))
. . .
C Select the column chapter_num and the long varchar column
C chapter_text from the table book.
C The Datahandler (Get_Handler) will be invoked for each non-null
C value of column chapter_text retrieved. For null values the
C indicator variable will be set to "-1" and the datahandler will
C not be called.
...
exec sql select chapter_num, chapter_text into
1 :chapter_num,
2 datahandler(Get_Handler(hdlarg)):indvar from book
exec sql begin
process row ...
exec sql end
. . .
end