Udostępnij za pośrednictwem


Using Accessors

Accessors are created by calling IAccessor::CreateAccessor, reference-counted by calling IAccessor::AddRefAccessor, and released by calling IAccessor::ReleaseAccessor. They can be created or released at any time. An accessor can be a row accessor (used for accessing rowset data), a parameter accessor (used for accessing parameter data), or both.

Row accessors

Row accessors can be created on command and rowset objects, but they can be used only on rowset objects. These accessors describe the bindings to columns in the rowset and, if created on a command object, are inherited by any rowsets created by that command object. Row accessors created on a rowset after a row is fetched from that rowset can still be used against that row.

Consumers can create and use more than one accessor at a time on any row. Therefore, the consumer can get or set multiple copies of the same data. For example, suppose a rowset contains employee data including a picture of the employee. The consumer might create two accessors: one for all of the columns except the picture column and another for the picture column. The consumer might then pass the handle of the first accessor to IRowset::GetData to get all of the data except the picture. When the user requests the picture, the consumer would then pass the handle to the second accessor to IRowset::GetData to get the picture.

When ICommand::Execute creates a rowset, the rowset inherits all row accessors that have been created on that command. To the consumer, it appears as if each accessor has been copied from the command to the rowset: The bindings, flags (except DBACCESSOR_PARAMETERDATA), and handle of each accessor are the same on both the rowset and the command. After the rowset is opened, it gets its own independent copy of the accessors. Calling IAccessor methods on the command object has no effect on the accessors available on any existing rowsets, and calling IAccessor methods on the rowset has no effect on the accessors available on any existing commands.

For example, suppose the text command that creates a rowset contains parameters. The consumer might create multiple rowsets by repeatedly executing this text command with different parameters. Because the rowsets are created from the same text command, all can use the same row accessors. To create a row accessor on a command, the consumer must know the column ordinals.

Parameter accessors

Parameter accessors can be created and used only on command objects. They are used for accessing parameter data that describes bindings to parameters in the command text.

Combined row/parameter accessors

Combined row/parameter accessors can be created on command objects by setting both the DBACCESSOR_ROWDATA and the DBACCESSOR_PARAMETERDATA flags. Combined row/parameter accessors can also be inherited and used on a rowset. When used on a rowset, the DBACCESSOR_PARAMETERDATA flag is irrelevant. Therefore, it is provider-specific whether or not this flag is set.

This topic is a part of: