Logo

OLEDB Direct Components Suite

An accessor is a data structure created by the consumer that describes how row or parameter data from the data store is to be laid out in the consumer's data buffer. For each column in a row (or parameter in a set of parameters), the accessor contains a binding. A binding is a data structure that holds information about a column or parameter value, such as its ordinal value, data type, and destination in the consumer's buffer.

From point of view of VCL an accessor represents a fields collection while a binding represents a field. This let work with only few columns of rowset, or use one accessor to fetch data and another to send them to data store. This also let use BLOB-on-demand.

OLEDB Direct Components Suite let create dynamic accessors. The next example shows this:

uses OLEDBComponents;

var
    ac: TOLEDBAccessor;
    Col, Row: Integer;
begin
    ac := OLEDBRowset1.CreateDynamicAccessor;
    OLEDBRowset1.MoveFirst;
    StringGrid1.ColCount := ac.Bindings.Count;
    //RecordCount is available only if rfScroll is in Flags,
    //i.e. IRowsetScroll interface is supported
    if rfScroll in OLEDBRowset1.Flags then
        StringGrid1.RowCount := OLEDBRowset1.RecordCount+1
      else
        StringGrid1.RowCount := 2;

    //Fill column headers
    for Col:=0 to ac.Bindings.Count-1 do
        StringGrid1.Cells[Col, 0] := OLEDBRowset1.ColumnInfo[Col].Name;

    //Fill string grid
    Row := 1;
    while not OLEDBRowset1.EOF do begin
        for Col:=0 to ac.Bindings.Count-1 do
            try
                //Not all data types can be converted into string
                StringGrid1.Cells[Col, Row] := ac.Bindings[Col].AsString;
              except
                StringGrid1.Cells[Col, Row] := '';
              end;
        Inc(Row);
        if StringGrid1.RowCount < Row + 1 then
            StringGrid1.RowCount := Row+1;
        OLEDBRowset1.MoveNext;
      end;

    //Do not delete accessors directly, call Accessors.Remove to do this
    OLEDBRowset1.Accessors.Remove(ac);
end;