Define or describe a registered procedure parameter.
RETCODE dbregparam(dbproc,param_name, type, datalen, data) DBPROCESS *dbproc; char *param_name; int type; DBINT datalen; BYTE *data;
A pointer to the DBPROCESS structure that provides the connection for a particular front-end/server process. It contains all the information that DB-Library/C uses to manage communications and data between the front end and the server.
A pointer to the parameter name.
When creating a registered procedure, param_name is required.
When executing a registered procedure, param_name may be NULL. In this case, the registered procedure will expect to receive its parameters in the order in which they were originally defined.
A symbolic value indicating the datatype of the parameter. Legal data types are: SYBINT1, SYBINT2, SYBINT4, SYBREAL, SYBFLT8, SYBCHAR, SYBBINARY, SYBVARCHAR, SYBDATETIME4, SYBDATETIME, SYBMONEY4, and SYBMONEY.
Note that SYBTEXT and SYBIMAGE are not legal datatypes for parameters.
The length of the parameter.
When creating a registered procedure:
datalen can be used to indicate that no default value is being supplied for this parameter. To indicate no default, pass datalen as DBNODEFAULT.
datalen can be used to indicate that the default value for a parameter is NULL. This is different from having no default. To indicate a NULL default, pass datalen as 0.
When executing a registered procedure:
datalen may be 0. In this case, data is ignored and NULL is passed to the registered procedure for this parameter.
A pointer to the parameter.
When creating a registered procedure, data can be used to provide a default value for the parameter. Pass data as pointing to the default value. If no default value is desired, pass datalen as DBNODEFAULT.
When executing a registered procedure, data may be passed as NULL.
SUCCEED or FAIL.
dbregparam defines a registered procedure parameter. Because a notification procedure is simply a special type of registered procedure, dbregparam also defines a notification procedure parameter.
dbregparam is called to define registered procedure parameters when a registered procedure is created and to describe the parameters when a registered procedure is executed.
DB-Library/C applications can create only a special type of registered procedure, known as a notification procedure. A notification procedure differs from a normal Open Server registered procedure in that it contains no executable statements. See the dbnpdefine and dbnpcreate reference pages.
Either dbnpdefine, which initiates the process of creating a notification procedure, or dbreginit, which initiates the process of executing a registered procedure, must be called before an application calls dbregparam.
When creating a registered procedure:
To indicate that no default value is being supplied, pass datalen as DBNODEFAULT. data is ignored in this case.
To supply a default value of NULL, pass datalen as 0. data is ignored in this case.
To supply a default value that is not NULL pass datalen as the length of the value (or -1 if it is a fixed-length type), and data as pointing to the value.
When executing a registered procedure:
To pass NULL as the value of the parameter, pass datalen as 0. In this case, data is ignored.
To pass a value for this parameter, pass datalen as the length of the value (or -1 if it is a fixed-length type), and data as pointing to the value.
To create a notification procedure, a DB-Library/C application must:
Define the procedure using dbnpdefine
Describe the procedure’s parameters, if any, using dbregparam
Create the procedure using dbnpcreate
This is an example of creating a notification procedure:
DBPROCESS *dbproc;
DBINT status;
/*
** Let’s create a notification procedure called
** "message" which has two parameters:
** msg varchar(255)
** userid int
*/
/*
** Define the name of the notification procedure
** "message"
*/
dbnpdefine (dbproc, "message", DBNULLTERM);
/* The notification procedure has two parameters:
** msg varchar(255)
** userid int
** So, define these parameters. Note that both
** of these parameters are defined with a default
** value of NULL. Passing datalen as 0
** accomplishes this.
*/
dbregparam (dbproc, "msg", SYBVARCHAR, 0, NULL);
dbregparam (dbproc, "userid", SYBINT4, 0, NULL);
/* Create the notification procedure: */
status = dbnpcreate (dbproc);
if (status == FAIL)
{
fprintf(stderr, "ERROR: Failed to create \
message!\n");
}
else
{
fprintf(stdout, "Success in creating \
message!\n");
}
To execute a registered procedure, a DB-Library/C application must:
Initiate the call using dbreginit
Pass the procedure’s parameters, if any, using dbregparam
Execute the procedure through dbregexec
This is an example of executing a registered procedure:
DBPROCESS *dbproc;
DBINT newprice = 55;
DBINT status;
/*
** Initiate execution of the registered procedure
** "price_change".
*/
dbreginit (dbproc, "price_change", DBNULLTERM);
/*
** The registered procedure has two parameters:
** name varchar(255)
** newprice int
** So pass these parameters to the registered
** procedure.
*/
dbregparam (dbproc, "name", SYBVARCHAR, 6,
"sybase");
dbregparam (dbproc, "newprice", SYBINT4, -1,
&newprice);
/* Execute the registered procedure: */
status = dbregexec (dbproc, DBNOTIFYALL);
if (status == FAIL)
{
fprintf(stderr, "ERROR: Failed to execute \
price_change!\n");
}
else if (status == DBNOPROC)
{
fprintf(stderr, "ERROR: Price_change does \
not exist!\n");
}
else
{
fprintf(stdout, "Success in executing \
price_change!\n");
}