Adding Parameters to a DPB
Go Up to Connecting to Databases
Sometimes it is useful to add parameters to an existing DPB at run time. For example, when an application runs, it might determine a user’s name and password and supply those values dynamically. The isc_expand_dpb()
function can be used to pass the following additional parameters to a populated DPB at run time:
Parameter | Purpose |
---|---|
|
String user name, up to 255 characters |
|
String password, up to 255 characters |
|
String specifying a language-specific message file |
|
String specifying the character set to be used |
|
String role name, up to 255 characters |
- Important: If you expect to add any of these parameters at run time, then create a larger than necessary DPB before calling
isc_expand_dpb()
, so that this function does not need to reallocate DPB storage space at run time.isc_expand_dbp
() can reallocate space, but that space is not automatically freed when the database is detached.
isc_expand_dpb()
requires the following parameters:
Parameter | Type | Description |
---|---|---|
|
|
Pointer to a DPB |
|
|
Pointer to the end of the currently used portion of the DPB |
|
|
Pointers to item type and items to add to the DPB |
The third parameter in the table, “…”, indicates a variable number of replaceable parameters. Each parameter is a character pointer with a unique name. The final parameter must be a NULL or a hexadecimal zero.
- Important:
isc_expand_dpb()
allocates a new block for the DPB. To avoid memory leaks,call isc_free()
to release that space.
The following code demonstrates how isc_expand_dpb()
is called to add a user name and password to the DPB after they are elicited from a user at run time:
char dpb_buffer[256], *dpb, *p; char uname[256], upass[256]; short dpb_length; /* Construct a database parameter buffer. */ dpb = dpb_buffer; *dpb++ = isc_dpb_version1; *dpb++ = isc_dpb_num_buffers; *dpb++ = 1; *dpb++ = 90; dpb_length = dpb - dpb_buffer; dpb = dpb_buffer; /* Now ask user for name and password. */ prompt_user("Enter your user name: "); gets(uname); prompt_user("\nEnter your password: "); gets(upass); /* Will string overflow buffer? */ if ((sizeof (dpb_buffer) - dpb_length) <= strlen (uname) + strlen (upass) + sizeof (isc_dpb_user_name) + sizeof (isc_dpb_password)) { /* Call expand_dpb) */ isc_expand_dpb(&dpb, &dpb_length, isc_dpb_user_name, uname, isc_dpb_password, upass, NULL); } else /* No, add parameters locally */ .....