QueryDef Object
A QueryDef object defines the parameters for a query, which is used to retrieve specific records from a database.
A QueryDef object contains a query expression and
a list of display fields. The query expression defines the search
parameters for the query and can contain a complex set of conditional
statements. To run the query, you must create a ResultSet Object and call
its Execute
method.
(You can use the Session object BuildResultSet
method
to create the ResultSet object.) The ResultSet object uses the list
of display fields in the QueryDef object to summarize the search results.
To create a QueryDef object,
- Call the Session object's
BuildQuery
method. The BuildQuery methods returns an QueryDef object with display fields and filters undefined. - Add the filters and fields for your query to the QueryDef object.
To create a query that will return all records of
a given type, create a QueryDef object, but do not add filters to
it. Instead, add the fields to be returned using the QueryDef object's BuildField
method.
You can add filters and nodes to a QueryDef object
to create more complex queries. The nodes of a QueryDef object consist
of one or more QueryFilterNode
Objects, each containing one or more filters. Nodes group
together each of their filters under a single boolean operator. You
use the QueryDef object's BuildFilterOperator
method
to create the root node in this tree. After that, you use the methods
of QueryFilterNode to define the remaining nodes and filters. The
filters themselves can use other comparison operators to test the
relationship of a field to the specified data.
For example, in the following statement:
Select * from <some defect> where (....) AND1 ((...) OR2 ( (...) AND3( (...) OR4 (...))))
the root operator is AND (AND1). Its next level sub-node operator is an OR (OR2). The complete hierarchy is:
AND1 (AND1 is the root operator)
\
OR2 (OR2 is suboperator of AND1)
\
AND3 (AND3 is suboperator of OR2)
\
OR4 (OR4 is suboperator of AND3)
BuildSQLQuery
method.
However, this technique does not create a QueryDef object.For an example of how to use QueryDef object, see Running a query that has dynamic filters.