Re: Calling C code from Informix-SQL Forms
Posted in 1993
Topics: Connectivity: ESQL/C, 4GL & Embedded SQL, Migration, Import/Export & Data Conversion
> > I would like to be able to send mail to some appropriate people when certain > tables in our Informix DB are updated or inserted to. > > Now, I've been told I need to create a custom form runner with CPERF and link > in the C routines. How does cperf work? Do the C routines need to be in a > particular format or have particular parameters? > > Brad. > You can find the detail description of linking perform forms and 'C' functions in INFORMIX-ESQL/C Programmers manual. You can also find example programs in $INFORMIXDIR/demo/sql directory. (p_ex?.per and *.c , *.ec files) I can help you with the following example. In control blocks you can use C functions anywhere you can use an expression. ## Form file pertest.per database testdb screen { field1 : [f000 ] field2 : [f001 ] } end tables tsttbl attributes f000 = field1; f001 = field2; instructions delimiters " " after editadd editupdate of field1 let f001 = my_c_func () end ###### C Function pertest.c #include <stdio.h> #include "ctools.h" $include sqlca; valueptr my_c_func (); struct ufunc userfuncs[] = { "my_c_func ", my_c_func , /* "my_c_func" is the name of the user function as called in PERFORM * my_c_func Pointer to the user C function. */ 0,0 /* End of function array */ }; valueptr my_c_func () { /** Your C functions *****/ } In order to return values to perform form you have to use the macro functions given in $INFORMIXDIR/incl/ctools.h. To get value perfrom form to 'C' functions and vice-versa use the supplied library functions pf_getval,pf_putval ... compile the perform form: sformbld pertest.per create custom version of sperform: cperf pertest.c -o pertest To run the form: pertest pertest.frm +--------------------------+---------------------------+ | G.T.Madavan, | e-mail: gtmad@smi.mn.org | | Systems Migration Inc., | Phone : (612) 890-0040 | | Burnsville, MN, U.S.A | Fax : (612) 890-0966 | +--------------------------+---------------------------+