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 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
SQL workspaces are created using the SqlWorkspaceFactory class. SQL workspaces cannot be used in the same way as many other workspaces to open datasets, because they do not implement the IFeatureWorkspace interface. Instead, the ISqlWorkspace interface can be used to retrieve a list of tables from the connected database management system (DBMS), to open query classes, and to create query cursors.
The following types of DBMSs can be accessed as SQL workspaces:
- SQL Server
- Oracle
- PostgreSQL
- DB2
- Informix
For more information about using SQL workspaces, see Working with SQL workspaces.
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:
- Create a query description
- Modify the query description (may not be required, depending on the query)
- 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, including limitations on what types of queries can be used as a query class, 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 in the same way as 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 a 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 SQL workspacesWorking with query classes
Working with query cursors