Programming Guide |
Adds or replaces a bind value in a DBMS EXECUTE statement for SQL generation
#include <tmusubs.h>int dm_gen_change_execute_using(char *arg, char *bind_parm, char *bind_val, int occ, int relative, int flag);
arg
- Reserved for future use.
bind_parm
- Specifies the bind parameter.; if a null pointer or empty string, the clause is not built.
bind_val
- Specifies the bind value; if a null pointer or an empty string, the clause is not built.
occ
- Specifies the occurrence number.
relative
- Specifies how to use the occurrence number with one of the following values:
DM_GEN_ABSOLUTE_OCCUR
DM_GEN_RELATIVE_TO_PARENT
DM_GEN_RELATIVE TO CHILDflag
- Specifies the type of change to make with one of the following constants:
DM_GEN_APPEND
- When
flag
is set to this value,bind_val
is added to end of theUSING
clause. This produces the following statement:DBMS WITH CURSOR cursor EXECUTE USING
existing_parentTV_binds,
existing_childTV_binds,
bind_parm = bind_val[
occ]
DM_GEN_PREPEND
- When
flag
is set to this value,bind_val
is added to the beginning of theUSING
clause. This produces the following statement:DBMS WITH CURSOR
cursor
EXECUTE USING
bind_parm = bind_val
[
occ
],
existing_parentTV_binds
,
existing_childTV_binds
DM_GEN_REPLACE_ALL
- When
flag
is set to this value,bind_val
replaces the previousUSING
clause. This produces the following statement:DBMS WITH CURSOR
cursor
EXECUTE USING
bind_parm = bind_val
[
occ
]
- If
flag
is set to this value and the other arguments are empty strings, theUSING
clause is removed.
dm_gen_change_execute_using
lets you edit theUSING
clause of aDBMS EXECUTE
statement. The data structure for theSELECT
statement, which is built by a call to dm_gen_sql_info (generally in theTM_SEL_GEN
event), must already exist before this function is called. Note that this function must be called once for each bind value you wish to change.Often, a call to
dm_gen_change_execute_using
follows a call to the function dm_gen_change_select_where. If new parameters are added to theWHERE
clause's search conditions, those parameters must also be added to theEXECUTE USING
statement.This function can be implemented as part of a transaction manager event function that processes the
TM_SEL_BUILD_PERFORM
event. If you are modifying the select processing for a server view, call thedm_gen_change_execute_using
function from an event function attached to the first parent table view in the server view.To view a sample event function written in JPL, refer to the example in this section. For more information on writing transaction event functions, refer to Chapter 32, "Writing Transaction Event Functions," in Application Development Guide.
The settings for
relative
andoccurrence
determine the value forocc
, the occurrence number used in the statement.If
relative
is set toDM_GEN_RELATIVE_TO_PARENT
orDM_GEN_RELATIVE_TO_CHILD
, the current occurrence in the parent or child table view is used as the basis for the occurrence number. Then, the setting foroccurrence
is checked. Ifoccurrence
is 0, the current occurrence in that table view is used in the statement. Ifoccurrence
is greater than 0, the occurrence is calculated by adding the specified occurrence to the current occurrence.If you only need to substitute an occurrence number in the statement processing, set
relative
toDM_GEN_ABSOLUTE_OCCUR
and setoccurrence
to be greater than 0.
# JPL Procedure:
# Generate IN clause using binding parameters.
# Function property is set to titles_exec.
proc titles_exec (event)
if (event == TM_SEL_BUILD_PERFORM)
{
vars retval(5), occ(3), i(3), in_buffer(255), comma(1)
occ = @widget("qbe_titleid")->num_occurrences
# If the array "qbe_titleid" contains data,
# build a SQL "in" clause.
if (occ > 0)# First loop through qbe_titleid and build an IN clause
# in the form "title_id" in (::p1, ::p2, ::p3).
{
for i=1 while i <= occ
{
if (qbe_titleid[i] != "")
{
%.0 i = i
in_buffer = in_buffer ## comma ## "\:\:p" ## i \
comma = ","
}
}
in_buffer = "title_id in (" ## in_buffer ## ")"
retval = dm_gen_change_select_where \
("", in_buffer, DM_GEN_APPEND)# Now loop through qbe_titleid and change the EXECUTE
# USING statement. This could be done in the previous loop.
# It is separated for clarity.
for i=1 while i <= occ
{
if (qbe_titleid[i] != "")
{
%.0 i = i
retval=dm_gen_change_execute_using \
('', "p:i", "qbe_titleid", i, \
DM_GEN_ABSOLUTE_OCCUR, DM_GEN_APPEND)
}
}
if (retval != 0)
return TM_FAILURE
}
}
return TM_PROCEED
The following example uses the current occurrence in the parent table view to specify the occurrence number. The parent table view in this sequential link is a list of customers. When you enter one of the
rental_status
codes for a customer in theqbe_status
field, the rentals for that customer which match that status populate the child table view.# JPL Procedure:
# Generate WHERE and EXECUTE USING clause using occurrence
# in parent table view. The Function property for rentals
# table view is set to rentals_hook.proc rentals_hook(event)
{
vars whexp(100) retval(5)
if (event==TM_SEL_BUILD_PERFORM)
{
# Build the following: correlation.rental_status = ::qbe1
whexp=dm_gen_get_tv_alias(sm_tm_pinquire(TM_TV_NAME)) \
## ".rental_status" \
## "=" \
## "::::qbe1"
# Add it to the WHERE clause.
retval = dm_gen_change_select_where("", whexp,\
DM_GEN_APPEND)
# Append to the EXECUTE USING clause in the form:
# qbe1 = qbe_stat[<occ>]
# where occ is the same occurrence number as the current
# occurrence in parent table view.
retval = dm_gen_change_execute_using\
("", "qbe1", "qbe_stat", \
0, DM_GEN_RELATIVE_TO_PARENT, DM_GEN_APPEND)
}
return TM_PROCEED
}