![]() | 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_nameproperty is referenced in theORDER BYclause. 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 BYclause. This produces the following statement:DBMS DECLAREcursorFOR SELECTselect_listFROMtablesORDER BYexisting_order_by_list,
column_positionsort_indDM_GEN_PREPEND- Adds the specified information to the beginning of the
ORDER BYclause. This produces the following statement:DBMS DECLAREcursorFOR SELECTselect_listFROMtablesORDER BYcolumn_positionsort_ind,
existing_order_by_listDM_GEN_REPLACE_ALL- The specified information replaces the previous
ORDER BYclause. This produces the following statement:DBMS DECLAREcursorFOR SELECTselect_listFROMtablesORDER BYcolumn_positionsort_indIf
flagis set to this value andwidget_nameis set to an empty string, theORDER BYclause is removed. For example:x = dm_gen_change_select_order_by
("", "", "", DM_GEN_REPLACE_ALL)
dm_gen_change_select_order_bylets you edit theORDER BYclause built with the SQL generator. The 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 change you wish to make.By default, the SQL generator builds the
ORDER BYclause 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_PERFORMevent. If you are modifying the select processing for a server view, calldm_gen_change_select_order_byfrom 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