![]() | 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
WHEREclause. 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
flagis set to this value,where_expris added to end of theWHEREclause. This produces the following statement:DBMS DECLAREcursorFOR SELECTselect_listFROMtable_listWHERElink_expressionANDexisting_where_exprANDwhere_exprDM_GEN_PREPEND- Adds
where_exprto the beginning of the expressions derived from theuse_in_whereproperty. This produces the following statement:DBMS DECLAREcursorFOR SELECTselect_listFROMtable_listWHERElink_expressionANDwhere_exprANDexisting_where_exprDM_GEN_REPLACE_ALL- Removes all the expressions based on the
use_in_whereproperty beingPV_YESandwhere_exprreplaces the previous data. This produces the following statement:DBMS DECLAREcursorFOR SELECTselect_listFROMtable_listWHERElink_expressionANDwhere_exprYou also need to call
dm_gen_change_execute_usingto remove theexisting_where_exprfrom theUSINGclause of theEXECUTEstatement.
dm_gen_change_select_wherelets you edit theWHEREclause of aSELECTstatement. The structure for theSELECTstatement, which is generally built by a call to dm_gen_sql_info in theTM_SEL_GENevent, must already exist beforedm_gen_change_select_whereis called.By default, the data for the
WHEREclause comes from:
- Widgets whose
use_in_whereproperty is set toPV_YES.
dm_gen_change_select_whereadds to or replaces the data based on theuse_in_whereproperty. 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
BETWEENclause or a subquery to aSELECTstatement.This function can be implemented as part of a transaction manager event function which processes the
TM_SEL_BUILD_PERFORMevent. If you are modifying the select processing for a server view, calldm_gen_change_select_wherefrom 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
![]()
![]()
![]()
![]()