mirror of
https://gitlab.com/freepascal.org/fpc/source.git
synced 2025-04-24 11:29:16 +02:00
* Createdataset should not create fielddefs for calculated or lookup fields
git-svn-id: trunk@21640 -
This commit is contained in:
parent
ee47ad22ff
commit
cc3ac1dd95
@ -910,15 +910,16 @@ begin
|
||||
FieldDefs.BeginUpdate;
|
||||
try
|
||||
for i := 0 to Fields.Count-1 do with fields[i] do
|
||||
begin
|
||||
with TFieldDef.Create(FieldDefs,FieldName,DataType,Size,Required,i+1) do
|
||||
if not (FieldKind in [fkCalculated,fkLookup]) then // Do not add fielddefs for calculated/lookup fields.
|
||||
begin
|
||||
if Required then Attributes := attributes + [faRequired];
|
||||
if ReadOnly then Attributes := attributes + [faReadOnly];
|
||||
if DataType = ftBCD then precision := (fields[i] as TBCDField).Precision
|
||||
else if DataType = ftFMTBcd then precision := (fields[i] as TFMTBCDField).Precision;
|
||||
with TFieldDef.Create(FieldDefs,FieldName,DataType,Size,Required,FieldDefs.Count+1) do
|
||||
begin
|
||||
if Required then Attributes := attributes + [faRequired];
|
||||
if ReadOnly then Attributes := attributes + [faReadOnly];
|
||||
if DataType = ftBCD then precision := (fields[i] as TBCDField).Precision
|
||||
else if DataType = ftFMTBcd then precision := (fields[i] as TFMTBCDField).Precision;
|
||||
end;
|
||||
end;
|
||||
end;
|
||||
finally
|
||||
FieldDefs.EndUpdate;
|
||||
end;
|
||||
|
@ -33,6 +33,7 @@ type
|
||||
procedure CreateDatasetFromFielddefs;
|
||||
procedure CreateDatasetFromFields;
|
||||
procedure TestOpeningNonExistingDataset;
|
||||
procedure TestCreationDatasetWithCalcFields;
|
||||
end;
|
||||
|
||||
implementation
|
||||
@ -129,6 +130,52 @@ begin
|
||||
ds.Free;
|
||||
end;
|
||||
|
||||
procedure TTestSpecificTBufDataset.TestCreationDatasetWithCalcFields;
|
||||
var ds : TBufDataset;
|
||||
f: TField;
|
||||
i: integer;
|
||||
begin
|
||||
ds := TBufDataset.Create(nil);
|
||||
try
|
||||
F := TIntegerField.Create(ds);
|
||||
F.FieldName:='ID';
|
||||
F.DataSet:=ds;
|
||||
F := TStringField.Create(ds);
|
||||
F.FieldName:='NAME';
|
||||
F.DataSet:=ds;
|
||||
F.Size:=50;
|
||||
|
||||
F := TStringField.Create(ds);
|
||||
F.FieldKind:=fkCalculated;
|
||||
F.FieldName:='NAME_CALC';
|
||||
F.DataSet:=ds;
|
||||
F.Size:=50;
|
||||
|
||||
F := TStringField.Create(ds);
|
||||
F.FieldKind:=fkLookup;
|
||||
F.FieldName:='NAME_LKP';
|
||||
F.LookupDataSet:=DBConnector.GetNDataset(5);
|
||||
F.KeyFields:='ID';
|
||||
F.LookupKeyFields:='ID';
|
||||
F.LookupResultField:='NAME';
|
||||
F.DataSet:=ds;
|
||||
F.Size:=50;
|
||||
|
||||
DS.CreateDataset;
|
||||
|
||||
TestDataset(ds);
|
||||
|
||||
for i := 0 to ds.FieldDefs.Count-1 do
|
||||
begin
|
||||
CheckNotEquals(ds.FieldDefs[i].Name,'NAME_CALC');
|
||||
CheckNotEquals(ds.FieldDefs[i].Name,'NAME_LKP');
|
||||
end;
|
||||
DS.Close;
|
||||
finally
|
||||
ds.Free;
|
||||
end;
|
||||
end;
|
||||
|
||||
initialization
|
||||
{$ifdef fpc}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user