ComponentOne Query 8.0
Custom Functions

The Function element of a result field query item can contain custom functions, in addition to standard ones: SUM, COUNT, AVERAGE, MIN, MAX. The five standard functions are all aggregation functions. Custom functions can be both aggregated and non-aggregated. For example, you can add an aggregated VAR function (statistical variance) and a non-aggregated YEAR function (the year part of a date field).

Custom functions can be added both at design time, using a template file, and at run time, setting the TemplateAttributes array property.

To add a custom function to the templates (see Customizing the UI with Templates), add a record to the <C1QProperty:Functions> template attribute. All standard functions are defined in the default template file, so you can use their definitions as guidance in defining your own functions.

A custom function definition contains the following attributes:

Id

Function identifier, must be greater than maximum standard function id (greater than 5).

Caption

Text appearing in the function menu.

Text

Text appearing in the Function element of a query item when this function is selected.

Types

Comma-delimited list of data types allowed to be used with this function; the function will be available only for fields having one of these types. Specifying Types="..." makes it available for all data types.

Aggregation

True/False. If True, this is an aggregation function (like SUM, COUNT, and so on), so it is evaluated on a group level, using the GROUP BY clause. Otherwise, it's a regular function, evaluated as an expression in the SELECT clause, unaffected by GROUP BY.

Enabled

True/False. This attribute can be set at run time to control the enabled state of the function's menu item. If it is False, the menu item is disabled.

Template

The string used in the resulting SQL statement. It can be specified in a template, parameterized form, with a special tag <C1Q_FIELD1> that will be substituted with the field name in SQL generation. For example, a template for the YEAR function can be Template="Year(<C1Q_FIELD1>)". If there is no special tag in the template string, it is used in generated SQL as is.

To add a custom function at run time, set the TemplateAttributes property. It is an indexed property, the index must be a specially formatted string as follows:

Example Title
Copy Code
C1QueryFrame.TemplateAttributes("Functions:")

where <id> is the integer id of the function (see the Id attribute above).

To define or change a function definition at run time, set the TemplateAttributes property, with an appropriate index, to a function definition string consisting of the attributes defined above.

You can use the TemplateAttributes property to modify attributes of standard functions as well, not just to define custom functions.

See also: Specifying Function and Comparison Attributes for a Particular Query Item.

For an example of how to add custom functions, see the CustomFunctions sample.

 

 


Copyright (c) GrapeCity, inc. All rights reserved.

Product Support Forum  |  Documentation Feedback