Command Objects

In OLE DB, Data Definition Language (DDL) and Data Manipulation Language (DML) statements are referred to as text commands. A command object contains a text command and encapsulates the query processing services available in today's DBMSs. Commands expose various interfaces representing different areas of functionality of a query processor, including query formulation, preparation, and execution. This figure illustrates a typical OLE DB query processor.

Typical OLE DB query processor

The main purpose of a command object is to execute a text command. Executing a command such as an SQL SELECT statement creates a rowset. Executing a command such as an SQL UPDATE or CREATE TABLE statement does not create a rowset.

Text commands are expressed in a provider-specific language—usually ANSI SQL92.

To use a command, an OLE DB consumer performs the following actions:

  1. Obtains an interface on the command.

  2. Builds a text string representing the command text.

  3. Passes the text string to the command.

  4. Requests properties to be supported by the resulting rowset, if any, including the interfaces it will expose.

  5. Executes the command. (If the command text specified the creation of a rowset, the command returns the rowset to the consumer.)

Because providers can both consume and produce rowsets, it is possible to compose query processors to process distributed, heterogeneous, or parallel queries. It is also possible to compose specialized query processors, such as SQL query processors, text-search query processors, and geographical or image query processors.

Rowset Properties

During command formulation, OLE DB consumers can request certain properties to be satisfied by the rowsets resulting from a command. Common properties include the set of interfaces to be supported by the resulting rowset. Any rowset returned from a command exposes the mandatory interfaces IRowset, IAccessor, IColumnsInfo, and IRowsetInfo, described earlier.

The basic IRowset interface supported by all rowsets enables consumers to, at minimum, navigate forward in the rowset. By requesting the rowset property to scroll backward, a consumer can navigate the rowset in both directions.

To support bidirectional rowsets efficiently, there are additional requirements when creating rowset objects. A forward-only rowset can be fed directly from the query execution plan output. A bidirectional rowset might require materializing the result. In addition to the default interfaces, a consumer may request interfaces to enable direct positioning within a rowset with bookmarks (IRowsetLocate), scrollability (IRowsetScroll), immediate updatability of rows (IRowsetChange), and deferred updatability of rows (IRowsetUpdate). It is also possible to request additional properties that specialize the behavior of certain interfaces — for example, to make some columns of the rowset updatable and the rest read-only.