다음을 통해 공유


Views

By creating a view object, providers that do not support full command syntax can still expose simple operations such as sorting or filtering a rowset. Views can be applied when opening a rowset, or they can be applied to an existing rowset to return either a new chapter on that rowset or a completely new rowset with the additional functionality. OLE DB view objects are not equivalent to SQL-92 views and cannot be used to combine multiple results.

Views are similar to commands, with the following restrictions:

  • The source of the view is a single rowset, fixed at the time the view is created.

  • Views support only simple operations such as filtering and sorting. They do not support complex semantics such as subqueries, joins, or dynamic parameters.

View operations are expressed through method calls as opposed to textual statements.

   CoType TView {
      [mandatory]   interface IColumnsInfo;
      [optional]    interface IAccessor;
      [optional]    interface ISupportErrorInfo;
      [optional]    interface IViewChapter;
      [optional]    interface IViewFilter;
      [optional]    interface IViewRowset;
      [optional]    interface IViewSort;
   };

Views are created either by applying a view when opening a rowset or by applying a view to an existing rowset. A view object may be returned in place of a rowset when executing any rowset-returning method.

  • Toapply a view when opening a rowset, the following steps occur:

    1. The consumer requests one of the following properties from the View property group (either directly or by requesting the associated IID) when opening the rowset:

DBPROP_IViewChapter

DBPROP_IViewFilter

DBPROP_IViewRowset

DBPROP_IViewSort

When one or more of these properties are set, the consumer must request an interface supported by a view object or the provider will return E_NOINTERFACE. Requesting any other interface when opening the rowset, and not explicitly requesting an interface from the View property group, returns the rowset object, regardless of other properties specified on the rowset.

  1. The consumer applies operations such as filtering and sorting to the view object through interfaces such as IViewFilter and IViewSort.

  2. The consumer calls IViewRowset::OpenViewRowset on the view object to return the actual rowset with the view applied.

  • To apply a view to an existing rowset, the following steps occur:

    1. The consumer calls IRowsetView::CreateView on the rowset.

    2. The consumer applies operations such as filtering and sorting to the view object through interfaces such as IViewFilter and IViewSort.

    3. The consumer calls IViewChapter::OpenViewChapter on the view to return a new chapter on the original rowset that reflects the view operations.

      - or -

      The consumer calls IViewRowset::OpenViewRowset on the view to return a new rowset with the view operations applied.

Providers that expose IViewFilter on the view object must also expose IAccessor and IColumnsInfo on the view object. Consumers should use only accessors created on the view object to get or set filters.

Note

To work with ADO 2.1 or later, for views created from existing rowsets (by calling IRowsetView::CreateView), the view object must allow the use of accessors created on the rowset from which the view was created.