![]() | Programming Guide | ![]() |
Edits the FROM clause in a SELECT statement for automatic SQL generation
#include <tmusubs.h>int dm_gen_change_select_from(char *arg, char *table, char *corr_name, int flag);
arg- Reserved for future use.
table- The name of the database table. For some database engines, you may need to include the owner name in the format:
owner.table_namecorr_name- The correlation name for the database table.
flag- Specifies the type of change to make with one of the following constants:
DM_GEN_APPEND- Adds the name of the database table and its associated correlation name to the end of the
FROMclause. This produces the following statement:DBMS DECLAREcursorFOR SELECTselect_listFROM
existing_from_clause,
table corr_nameDM_GEN_PREPEND- Adds the name of the database table and its associated correlation name to the beginning of the
FROMclause. This produces the following statement:DBMS DECLAREcursorFOR SELECTselect_listFROM
table corr_name,
existing_from_clauseDM_GEN_REPLACE_ALL- The name of the database table and its associated correlation name replace the previous
FROMclause. This produces the following statement:DBMS DECLAREcursorFOR SELECTselect_listFROM
table corr_name
dm_gen_change_select_fromallows you to edit the tables listed in theFROMclause of aSELECTstatement built with the SQL generator. The data structure for theSELECTstatement, which is built by a call to dm_gen_sql_info (generally in theTM_SEL_GENevent), must already exist before this function is called. Note that this function must be called once for each table name you wish to change.By default, the SQL generator builds the table list based on the
tableproperty of each table view in the server view. 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 which processes the
TM_SEL_BUILD_PERFORMevent. If you are modifying the select processing for a server view, call thedm_gen_change_select_fromfunction 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.
# JPL Procedure:
# Fetch data from titles which is an unlinked table view.
# Function property is set to titles_join.
proc titles_join (event)
vars retval(5)
if (event == TM_SEL_BUILD_PERFORM)
{
retval = dm_gen_change_select_list("", "name", "name", \
DM_GEN_APPEND)
retval = dm_gen_change_select_from \
("", "titles", "titles", DM_GEN_APPEND)
retval = dm_gen_change_select_where ("", \
"rentals.title_id = titles.title_id", DM_GEN_APPEND)
if (retval != 0)
return TM_FAILURE
}
return TM_PROCEED