Programming Guide |
Edits the WHERE clause in a SELECT statement used in automatic SQL generation
#include <tmusubs.h>int dm_gen_change_select_where(char *arg, char *where_expr, int flag);
arg
- Reserved for future use.
where_expr
- Text of the expression to include in the
WHERE
clause. If the expression includes a parameter and the function is called within a JPL procedure, the parameter name must be declared with four colons because of colon expansion (::::parm1
).flag
- Specifies the type of change to make with one of these constants:
DM_GEN_APPEND
- When
flag
is set to this value,where_expr
is added to end of theWHERE
clause. This produces the following statement:DBMS DECLARE
cursor
FOR SELECT
select_list
FROM
table_list
WHERE
link_expression
AND
existing_where_expr
AND
where_expr
DM_GEN_PREPEND
- Adds
where_expr
to the beginning of the expressions derived from theuse_in_where
property. This produces the following statement:DBMS DECLARE
cursor
FOR SELECT
select_list
FROM
table_list
WHERE
link_expression
AND
where_expr
AND
existing_where_expr
DM_GEN_REPLACE_ALL
- Removes all the expressions based on the
use_in_where
property beingPV_YES
andwhere_expr
replaces the previous data. This produces the following statement:DBMS DECLARE
cursor
FOR SELECT
select_list
FROM
table_list
WHERE
link_expression
AND
where_expr
You also need to call
dm_gen_change_execute_using
to remove theexisting_where_expr
from theUSING
clause of theEXECUTE
statement.
dm_gen_change_select_where
lets you edit theWHERE
clause of aSELECT
statement. The structure for theSELECT
statement, which is generally built by a call to dm_gen_sql_info in theTM_SEL_GEN
event, must already exist beforedm_gen_change_select_where
is called.By default, the data for the
WHERE
clause comes from:
- Widgets whose
use_in_where
property is set toPV_YES
.
dm_gen_change_select_where
adds to or replaces the data based on theuse_in_where
property. For more information on how the SQL generator uses this property, refer to Chapter 33, "Using Automated SQL Generation," in Application Development Guide.In particular, this function can be used to add a
BETWEEN
clause or a subquery to aSELECT
statement.This function can be implemented as part of a transaction manager event function which processes the
TM_SEL_BUILD_PERFORM
event. If you are modifying the select processing for a server view, calldm_gen_change_select_where
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 the next section. For more information on writing transaction event functions, refer to Chapter 32, "Writing Transaction Event Functions," in Application Development Guide.
# JPL Procedure:
# Append IN clause to WHERE clause.
# Function property is set to titles_in.
proc titles_in (event)
vars retval(5)
if (event == TM_SEL_BUILD_PERFORM)
{
vars 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)
{
for i=1 while i <= occ
{
if (qbe_titleid[i] != "")
{
in_buffer = in_buffer ## comma ## \
':+qbe_titleid[i]'
comma = ","
}
}in_buffer = "title_id in (" ##in_buffer ")"
retval = dm_gen_change_select_where \
("", in_buffer, DM_GEN_APPEND)
if (retval != 0)
return TM_FAILURE
}
}
return TM_PROCEED# JPL Procedure:
# Append search condition using onscreen value.
# Function property is set to titles_where.
proc titles_where (event)
vars retval(5)
if (event == TM_SEL_BUILD_PERFORM)
{
retval = dm_gen_change_select_where\
("", "film_minutes > ::::parm1", DM_GEN_APPEND)
retval = dm_gen_change_execute_using("", "parm1", \
"film_minutes", 1, DM_GEN_ABSOLUTE_OCCUR, \
DM_GEN_APPEND)
if (retval != 0)
return TM_FAILURE
}
return TM_PROCEED
dm_gen_sql_info, dm_gen_change_execute_using