Programming Guide



dm_gen_change_select_from

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_name

corr_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 FROM clause. This produces the following statement:
DBMS DECLARE cursor FOR SELECT select_list FROM
existing_from_clause,
table corr_name

DM_GEN_PREPEND
Adds the name of the database table and its associated correlation name to the beginning of the FROM clause. This produces the following statement:
DBMS DECLARE cursor FOR SELECT select_list FROM
table corr_name,
existing_from_clause

DM_GEN_REPLACE_ALL
The name of the database table and its associated correlation name replace the previous FROM clause. This produces the following statement:

DBMS DECLARE cursor FOR SELECT select_list FROM
table corr_name

Returns

Description

dm_gen_change_select_from allows you to edit the tables listed in the FROM clause of a SELECT statement built with the SQL generator. The data structure for the SELECT statement, which is built by a call to dm_gen_sql_info (generally in the TM_SEL_GEN event), 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 table property 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_PERFORM event. If you are modifying the select processing for a server view, call the dm_gen_change_select_from 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.

Example

# 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

See Also

dm_gen_sql_info