I’m probably being hopelessly optimistic here but is there any simple way of omitting certain fields when opening a data table?
When I say “simple”, I mean without resorting to using dynamic select which is fraught with issues because I then have to use FieldByName as the indexes are all different.
My scenario is I have a table which contains a binary field and, in many cases, I want to open the table and retrieve a load of records but omit the binary data.
The basic problem with using Dynamic Select to retrieve only a subset of fields is that I then can’t use the strongly-typed classes as all the indexes will be wrong and instead have to use FieldByName. That isn’t a problem per se, it’s more a question of remembering that. Down the line, if someone forgets that Dynamic Select is being employed and just uses the typed fields, it won’t work.
I guess what I really wanted was some way of maintaining the “full” set of fields/columns but somehow just not retrieving the binary fields and just having NULLs in those columns. I’ll have a play around.
if I put the binary fields at the end, then ideally I’d like to use dynamic select to specify all other fields.
Firstly, will the fields be in the order I add them to DynamicSelectFieldNames (so I’d need to add them in the correct order).
Secondly, is there some generic way I could load all non-binary fields into the dynamic select in the correct order? Obviously I could use the schema but that’s not accessible client-side.
You can easily load server-side schema with RDA.ReadSchema:
RemoteDataAdapter.ReadSchema; // it will load whole schema from server-side at 1st request
RemoteDataAdapter.FillSchema([table]); // fill table fields using cached schema
clear unneeded fields:
for var i: Integer := 0 to table.Fields.Count - 1 do begin
if table.Fields[i].DataType in [datBlob] then begin
//delete binary fields up to end of table
while table.Fields.Count > i do
table.Fields.Delete(i);
Break;
end;
end;
Out of interest, whenever I’ve updated a table’s fields in the schema, I’ve always updated any corresponding TDAMemDataTable components via Retrieve DataTable Schema, so the fields and order are always the same.
Is this actually required or not? If the order of fields in the schema differed from the table component, would it try putting values in the wrong fields?
you use the strongly-typed classes so better to update table component.
by other side, you can just clear Fields like table.Fields.Clear. in this case schema will be loaded automatically.
another workaround: you can have table_full (with binary data) & table_reduced (without binary data) in Schema… as a result, you will have 2 strongly-typed classes. it can be more easy and clean solution