Sign in Join

Live chat for Free Pascal, Lazarus, Delphi and every Pascal programmer.

Mailing lists / fpc-pascal / 2011-09

How to detect supported data types in dataset?

3 messages · 2 people · –

Reply by email Subscribe to this list Your subscription

Read-only archive. Use j and k to move between messages.

Reinier Olislagers

Hi list,

Possible newbie question so feel free to educate me ;) (Away for some days, so may not read response until back)

A patch by Ludo Brands on bufdataset (mantis 19930) got me thinking:

const
  ftSupported = [ftString,ftGuid,... and so on];
procedure TCustomBufDataset.CreateDataset;
var i:integer;
 begin
...
// check if all types are supported
  For i:=0 to FieldDefs.Count-1 do
    if not (Fielddefs.items[i].DataType in ftSupported) then
DatabaseErrorFmt(SUnsupportedFieldType,[Fieldtypenames[Fielddefs.items[i].DataType]]);
   CreateFields;
 end;

Suppose I want to write a dataset data copier or importer/exporter, how do I detect supported datatypes in a dataset?

For example, in my dbfexport test code, I make a bufdataset with all possible fields, then strip each field away when strange errors/AVs occur when assigning values to them.
For other datasets (with similar checks as proposed in Ludo's patch), the runtime library is nice enough to warn me on field creation that it doesn't work.

Am I missing something obvious or does it make sense to expose something like a SupportedFieldTypes property for datasets?
How does Delphi do this?

Besides that, I think it's an excellent idea to check for invalid datatypes when creating fields, rather than failing later on when assigning values to them.
(Of course, if that is implemented in a lot of datasets, checking exceptions when creating fields would be a rough way of checking if a datatype is supported ;)

I understand that 3rd party inherited datasets may not abide by this, but it's worth a shot to offer the functionality..

Thanks,
Reinier

Unknown author
to Reinier Olislagers
Reinier Olislagers wrote 35 lines
Hi list, Possible newbie question so feel free to educate me ;) (Away for some days, so may not read response until back) A patch by Ludo Brands on bufdataset (mantis 19930) got me thinking: const ftSupported = [ftString,ftGuid,... and so on]; procedure TCustomBufDataset.CreateDataset; var i:integer; begin ... // check if all types are supported For i:=0 to FieldDefs.Count-1 do if not (Fielddefs.items[i].DataType in ftSupported) then DatabaseErrorFmt(SUnsupportedFieldType,[Fieldtypenames[Fielddefs.items[i].DataType]]); CreateFields; end; Suppose I want to write a dataset data copier or importer/exporter, how do I detect supported datatypes in a dataset? For example, in my dbfexport test code, I make a bufdataset with all possible fields, then strip each field away when strange errors/AVs occur when assigning values to them. For other datasets (with similar checks as proposed in Ludo's patch), the runtime library is nice enough to warn me on field creation that it doesn't work. Am I missing something obvious or does it make sense to expose something like a SupportedFieldTypes property for datasets? How does Delphi do this?

It does not.

Besides that, I think it's an excellent idea to check for invalid datatypes when creating fields, rather than failing later on when assigning values to them.

It is up to the implementation of the datasets to give a decent error when an unsupported data type is being created.

Michael.

Reinier Olislagers
to Unknown author
Show quoted text 12 lines
On Thu, 8 Sep 2011, Reinier Olislagers wrote: > Am I missing something obvious or does it make sense to expose something > like a SupportedFieldTypes property for datasets? > How does Delphi do this? It does not. > Besides that, I think it's an excellent idea to check for invalid > datatypes when creating fields, rather than failing later on when > assigning values to them. It is up to the implementation of the datasets to give a decent error when an unsupported data type is being created.

Ok, thanks, I'll raise bug reports for the relevant datasets when I hit that problem again...

Reinier