Programming Guide |
Edits the select list for automatic SQL generation
#include <tmusubs.h>int dm_gen_change_select_list(char *arg, char *sel_expr, char *prolfx_alias, int flag);
arg
- Reserved for future use.
sel_expr
- The select expression. If the expression is invalid, the engine returns an error.
prolfx_alias
- Name of the Panther variable to use in the
DBMS ALIAS
statement. This variable should not be a local JPL variable. If this variable does not exist or is blank, theSELECT
statement fetches the expression's values, but they are ignored. This is not considered an error.flag
- Specifies the type of change to make with one of the following constants:
DM_GEN_APPEND
- Adds
sel_expr
to the end of the select list.prolfx_alias
is added after the existing aliases. This produces the following statements:DBMS DECLARE
cursor
FOR SELECT
existing_select_list
,
sel_expr
FROM ...
DBMS WITH CURSORcursor
ALIAS
existing_aliases
,
prolfx_alias
DM_GEN_PREPEND
- Adds
sel_expr
to the beginning of the select list, andprolfx_alias
is added before the existing aliases. This produces the following statements:DBMS DECLARE
cursor
FOR SELECT
sel_expr
,
existing_select_list
FROM ...
DBMS WITH CURSORcursor
ALIAS
prolfx_alias
,
existing_aliases
DM_GEN_REPLACE_ALL
sel_expr
replaces the previous select list, andprolfx_alias
replaces the existing aliases. This produces the following statements:DBMS DECLARE
cursor
FOR SELECT
sel_expr
FROM ...
DBMS WITH CURSORcursor
ALIAS
prolfx_alias
dm_gen_change_select_list
allows you to edit the select list built using the SQL generator. 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. You must call this function once for each change you wish to make.By default, the SQL generator builds the select list from the widgets whose
use_in_select
property is set toPV_YES
. For more information on the SQL generator, refer to Chapter 33, "Using Automated SQL Generation," in Application Development Guide.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, calldm_gen_change_select_list
from an event function attached to the first parent table view in the server view.For more information on transaction event functions, refer to Chapter 32, "Writing Transaction Event Functions," in Application Development Guide.
# JPL Procedure:
# Adds pic1, a binary column, to the select list for the
# current server view and sets bin_col1 as the target.
# The Function property is set to binary_hook.
proc binary_hook (event)
{
vars retval(5) colexp(64)
if (event==TM_SEL_BUILD_PERFORM)
{
colexp=dm_gen_get_tv_alias\
(sm_tm_pinquire(TM_TV_NAME) ## ".pic1")
retval=dm_gen_change_select_list\
("", colexp, "bin_col1", DM_GEN_APPEND)
# The number of occurrences for bin_col1 is set to match the
# number of occurrences of another column in the table.if (retval == 0)
{
retval=sm_n_max_occur("name")
dbms binary bin_col1[:retval](1024)
}
}
return TM_PROCEED}