2. Embedded SQL for C : Advanced Processing : User-Defined Data Handlers for Large Objects : Data Handlers and the SQLDA
 
Share this page                  
Data Handlers and the SQLDA
You may specify a user-defined data handler as an SQLVAR element of the SQLDA, to transmit large objects to/from the database. The eqsqlda.h file included via the include sqlda statement defines an IISQLHDLR type that may be used to specify a data handler and its argument. It is defined:
typedef struct sq_datahdlr
   {
       char *sqlarg; /* optional argument to pass */
       int (*sqlhdlr)(); /* user-defined datahandler */
    } IISQLHDLR;
The file does not declare an IISQLHDLR variable; the program must declare a variable of the specified type and set the values:
IISQLHDLR data_handler;
char *arg;
int Get_Handler();
data_handler.sqlarg = arg;
data_handler.sqlhdlr = Get_Handler;
The sqltype, sqllen and sqldata fields of the SQLVAR element of the SQLDA should then be set as follows:
/*
** assume sqlda is a pointer to a dynamically allocated ** SQLDA
*/
sqlda->sqlvar[i].sqltype = IISQ_HDLR_TYPE;
sqlda->sqlvar[i].sqllen = 0;
sqlda->sqlvar[i].sqldata = (char*)&data_handler;
To indicate nullability for a column set sqltype to negative IISQ_HDLR_TYPE, as shown in the following code fragment:
sqlda->sqlvar[i].sqltype = -IISQ_HDLR_TYPE;