Programming Guide |
Edits the ORDER BY clause in a SELECT statement for automatic SQL generation
#include <tmusubs.h>int dm_gen_change_select_order_by(char *arg, char *widget_name, int sort_ind, int flag);
arg
- Reserved for future use.
widget_name
- The name of the widget whose
column_name
property is referenced in theORDER BY
clause. If the name of the database column is entered, it is ignored.sort_ind
- Specifies whether the sort is ascending (
DM_GEN_ASC_SORTED
) or descending (DM_GEN_DESC_SORTED
). If set to an invalid value, an error is generated.flag
- Specifies the type of change to make with one of the following constants:
DM_GEN_APPEND
- Adds the specified information to the end of the
ORDER BY
clause. This produces the following statement:DBMS DECLARE
cursor
FOR SELECT
select_list
FROM
tables
ORDER BY
existing_order_by_list
,
column_position
sort_ind
DM_GEN_PREPEND
- Adds the specified information to the beginning of the
ORDER BY
clause. This produces the following statement:DBMS DECLARE
cursor
FOR SELECT
select_list
FROM
tables
ORDER BY
column_position
sort_ind
,
existing_order_by_list
DM_GEN_REPLACE_ALL
- The specified information replaces the previous
ORDER BY
clause. This produces the following statement:DBMS DECLARE
cursor
FOR SELECT
select_list
FROM
tables
ORDER BY
column_position
sort_ind
If
flag
is set to this value andwidget_name
is set to an empty string, theORDER BY
clause is removed. For example:x = dm_gen_change_select_order_by
("", "", "", DM_GEN_REPLACE_ALL)
dm_gen_change_select_order_by
lets you edit theORDER BY
clause built with the SQL generator. The 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. Note that this function must be called once for each change you wish to make.By default, the SQL generator builds the
ORDER BY
clause from values of the table view's Sort Widgets (sort_widgets
) property. For more information on how the SQL generator builds statements, 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, calldm_gen_change_select_order_by
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.
# Appends the order by list for titles table.
# The Function property is set to titles_orderby.
proc titles_orderby (event)
vars retval(5)
if (event == TM_SEL_BUILD_PERFORM)
{
retval = dm_gen_change_select_order_by \
("", "film_minutes", DM_GEN_ASC_SORTED, DM_GEN_APPEND)if (retval != 0)
return TM_FAILURE
}
return TM_PROCEED