Query classes and cursors (ArcObjects .NET 10.6 SDK)
ArcObjects Help for .NET developers > Developing with ArcGIS > Learning ArcObjects > Managing data > Working with feature data > Other data sources > Query classes and cursors overview > Query classes and cursors (ArcObjects .NET 10.6 SDK)

Query classes and cursors


Summary
This topic discusses query classes and query cursors.

In this topic


About query classes and cursors

Query classes and query cursors are mechanisms for querying spatial and non-spatial data from relational databases or geodatabases using Structured Query Language (SQL). This functionality is exposed through ArcMap as query layers. Both query classes and query cursors are created from SQL workspaces using the ISqlWorkspace interface.

SQL workspaces

To obtain a reference to a SQL workspace, you must first connect to a database or enterprise geodatabase using the WorkspaceFactory.Open method, then cast from IWorkspace to ISQLWorkpsace. SQL workspaces cannot be used like many other workspaces to open datasets because they do not implement the IFeatureWorkspace interface. Instead, the ISqlWorkspace interface should only be used to open query classes and to create query cursors.
The following types of database management systems (DBMSs) can be accessed as SQL workspaces:
  • SQL Server
  • Oracle
  • PostgreSQL
  • DB2
  • Informix
  • Netezza 

Query classes

A query class allows the results of a SQL query to be accessed as a read-only table or feature class. The following steps are used to create a query class:
  1. Create a query description.
  2. Modify the query description (may not be required, depending on the query).
  3. Pass the query description to the workspace to get a query class.
One requirement of a query class is that it must have a unique ID column. This can be a non-null integer column, or you can define a virtual column with values mapped from one or more existing columns. Mapping columns is one example of when modifying the intermediate query description is required.
Once a query class has been created, it can be consumed by other components in many of the same ways as a geodatabase table or feature class. For example, a query class with a spatial column can be combined with a feature layer to view the query class in ArcMap.
For more information about using query classes, see Working with query classes.

Query cursors

A query cursor returns read-only rows that are not bound to a table (similar to rows returned from a QueryDef cursor). In general, query cursors can be used like non-recycling search cursors. Some restrictions placed on the input of a query class do not apply to query cursors. For example, the following is true for query cursors:
  • Rows are not required to have a natural or mapped unique ID
  • Spatial columns containing multiple geometry types can be used
There are no intermediate steps to creating a query cursor. ISqlWorkspace.OpenQueryCursor, which takes a SQL statement as an argument, is used to create a query cursor.
For more information about query cursors, see Working with query cursors.


See Also:

Working with query classes
Working with query cursors