BuildFilterOperator

Description

Creates the top-level QueryFilterNode Object for the query.

This QueryDef method is the starting-point for building a query expression. You must call this method to obtain the first filter in the query expression. From this filter, you can construct additional filters to specify the criteria you want. The query expression is constructed as a tree of Boolean operators. The tree is not necessarily binary; you can add more than two conditions to a filter node.

Syntax

VBScript


querydef.BuildFilterOperator bool_operator

Perl

$querydef->BuildFilterOperator(bool_operator);
Identifier
Description
querydef
A QueryDef object.
bool_operator
A Long whose value is one of the BoolOp constants.
Return value
The newly created QueryFilterNode object.

Example

VBScript

submit_date < 01/03/2001 AND
(submitter = jjones OR submitter = clopez OR submitter = kwong)

In this expression, the top-level Boolean operator is the AND operator. To start constructing this query expression, you use this method to create the filter that has the top-level operator:

set myQueryDef = sessionObj.BuildQuery("Defect")
myQueryDef.BuildField("id")
myQueryDef.BuildField("headline")
set filterNode1 = myQueryDef.BuildFilterOperator(AD_BOOL_OP_AND)

You use this method just once to construct the root of the tree. To continue adding filters, you call the methods of the returned QueryFilterNode objects. For example, to complete the previous expression, you would write the following code:

filterNode1.BuildFilter "submit_date", AD_COMP_OP_LT, "2001-01-03"

set filterNode2 = filterNode1.BuildFilterOperator(AD_BOOL_OP_OR)
filterNode2.BuildFilter "submitter", AD_COMP_OP_EQ, "jjones"
filterNode2.BuildFilter "submitter", AD_COMP_OP_EQ, "clopez"
filterNode2.BuildFilter "submitter", AD_COMP_OP_EQ, "kwong"

More-complicated expressions are created by recursively attaching more nodes as needed. For more information, see the QueryFilterNode Object.

If a node contains only one condition, the value of the bool_operator parameter is irrelevant. For example, if the entire query expression is 'submitter = jjones', you could construct the query expression as follows:

' You could use either AD_BOOL_OP_AND or AD_BOOL_OP_OR for this
' expression since there is only one condition.
set filterNode = myQueryDef.BuildFilterOperator(AD_BOOL_OP_AND)
filterNode.BuildFilter 'submitter', AD_COMP_OP_EQ, "jjones"
Note: You can create a QueryDef object that has no filtering (in other words, no query expression). In this case, all of the records of the given record type in the database are retrieved. If there is a large number of records (several thousand or more), you should use filters to reduce the number of records returned. Returning large numbers of records adversely affects performance and can lead to excessive memory consumption on server machines.

Perl


@owner = ("jsmith");
@state = ("closed");

$queryDef = $CQsession->BuildQuery("defect");
@dbfields = ("ID","State","Headline");

foreach $field (@dbfields) {
      $queryDef->BuildField($field);
      }

$operator = $queryDef->BuildFilterOperator($CQPerlExt::CQ_BOOL_OP_AND);
$operator->BuildFilter("Owner", $CQPerlExt::CQ_COMP_OP_EQ,\@owner);
$operator->BuildFilter("State", $CQPerlExt::CQ_COMP_OP_NOT_IN, \@state);