ComponentOne Query 8.0
Custom comparison operators

Developers can define custom comparison operators in addition to the standard ones: "equal", "greater than", and so on. Custom comparisons can be added both at design time, using a template file, and at run time, setting the TemplateAttributes array property.

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

A custom comparison definition contains the following attributes:


Comparison identifier, must be greater than maximum standard comparison id (use the c1qFirstUserComparisonID constant, or just start from 100).


Text appearing in the comparison menu.


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


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


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


The string used in the resulting SQL statement. It can be specified in a template, parameterized form, with special tags: <C1Q_FIELD1>, <C1Q_FIELD2> and some others (see below) that will be substituted with field names and constant values in SQL generation. If there are no special tags in the template string, it is used in generated SQL as is.

Tags in Template attribute:

<C1Q_FIELD1>, <C1Q_FIELD2>: left and right parts of the comparison. In a simple condition, <C1Q_FIELD1> is always a field and <C1Q_FIELD2> is a constant value. In an advanced condition, they both can be either a field or a constant value.

<C1Q_FIELD1_LEFTQUOTE>, <C1Q_FIELD1_RIGHTQUOTE>, <C1Q_FIELD2_LEFTQUOTE>, <C1Q_FIELD2_RIGHTQUOTE>: quotation marks used with a constant value. These tags are substituted with a quotation mark appropriate for the constant's data type. For a string constant, they are usually single quotes. For a field or a numeric constant, they are substituted with empty strings.

<C1Q_LIKE_PERCENT>: wildcard matching any string in LIKE (standard SQL character: %).

<C1Q_LIKE_UNDERSCORE>: wildcard matching a single character in LIKE (standard SQL character: _).

To add a custom comparison 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

Where <id> is the integer id of the comparison (see the Id attribute above).

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

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

See also: Specifying Function and Comparison Attributes for a Particular Query Item and Type checking in condition items.

For an example of how to add custom comparisons, see samples: CustomComarisons, CustomComparisons2.



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

Product Support Forum  |  Documentation Feedback