MDAC 2.5 SDK - Technical Articles


 

Data Shaping Service for OLE DB

Data shaping provides a way to model complex, hierarchical data relationships—such as one-to-many or many-to-many—to create sophisticated data analysis and reporting applications. Data shaping puts a lot of power in the developer's hands. However, the shape commands themselves can become complex.

In OLE DB, a single rowset can be used to retrieve data for each level in a hierarchical query. The parent rowset contains a "chapter-valued" column that identifies the set of rows within the single child rowset that pertain to that parent. Specifying this chapter value when calling row-retrieval methods on the child rowset effectively limits the rowset to those rows that pertain to the given chapter.

ADO supports binding to hierarchical data by exposing "tear-off" recordsets. Binding to a column in a recordset that represents nested data returns a child recordset for that data. The way this recordset works is identical to how any other recordset in ADO works.

The ability to model data hierarchically is provided through the Data Shaping Service for OLE DB, shipped as part of the MDAC SDK. This service provider can be accessed through ADO or through OLE DB directly, and it works like any other provider. When connecting to the Data Shaping Service, the user specifies the underlying data provider from which the data to shape is obtained. The Data Shaping Service supports a special syntax for relating multiple result sets from the underlying provider to each other, similar to a relational join except that the results are returned as a hierarchical OLE DB rowset or ADO recordset.

Alternatively, the Data Shaping Service can be used to aggregate values and return the results as hierarchical data.

The Data Shaping Service provides the following functions:

The hierarchy syntax aggregates a result, as defined by a command or a name, and constructs a new hierarchy. A command is a cursor definition native to the data provider. Commands can contain parameters, which customize the hierarchy when it is created. A name refers to existing local results already built by the Data Shaping Service; that is, the Data Shaping Service can add columns to a new result. The new columns can be an aggregation function over child rowsets, an expression, or just a new user-defined column.

By default, the value of the child reference column is different for each row because the Data Shaping Service creates a new chapter every time the current row is moved. The provider can optionally return a unique child reference for a given child, and update the membership of the respective child chapter on row changes to contain the child rows for the current parent row.

The Data Shaping Service applies the requery method called on the root rowset of a hierarchy to the entire hierarchy. All other functions such as navigation and synchronization are associated with each component rowset and should be called as needed on each component of a hierarchy.

In ADO, hierarchies are implemented by using a command syntax that defines how to shape the recordsets. Embedded within that syntax are the actual commands to be sent to the data source.

The Data Shaping Service implements three types of hierarchies. See the following topics for a complete description and an example of each hierarchy type: