Creating queries
About this task
Creating a query involves the creation of at least three separate objects: a QueryDef Object, a QueryFilterNode Object, and a ResultSet Object. More complex queries might also involve the creation of additional QueryFilterNode objects.
Procedure
To create a query, follow these steps:
- Create a QueryDef object and fill it with
the search parameters.
To create this object, use the
BuildQuery
method of the Session object.Note: You use theBuildQuery
method to build a query and not theBuildSQLQuery
method. TheBuildSQLQuery
method generates a ResultSet object directly from an SQL query string. - Use the methods of QueryDef to add search criteria and to specify the fields of each record you want the query to return.
- Create a ResultSet object to hold the returned
data.
To create this object, call the
BuildResultSet
method of the Session object. On creation, the ResultSet object creates a set of internal data structures using the information in the QueryDef object as a template. When the query is run, the ResultSet object fills these data structures with data from the query. - Run the query by calling the ResultSet object's
Execute
method. - Access the data using other methods of this object. (For more information, see "Navigating through the result set".)
Results
Note: If you use the BuildSQLQuery
method to create a query based on SQL syntax, your query string must
contain all of the desired search parameters. The BuildSQLQuery method
returns a ResultSet object directly, instead of returning a QueryDef
object.