mirror of
https://gitlab.com/freepascal.org/fpc/source.git
synced 2025-08-16 18:19: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;
|
FieldDefs.BeginUpdate;
|
||||||
try
|
try
|
||||||
for i := 0 to Fields.Count-1 do with fields[i] do
|
for i := 0 to Fields.Count-1 do with fields[i] do
|
||||||
begin
|
if not (FieldKind in [fkCalculated,fkLookup]) then // Do not add fielddefs for calculated/lookup fields.
|
||||||
with TFieldDef.Create(FieldDefs,FieldName,DataType,Size,Required,i+1) do
|
|
||||||
begin
|
begin
|
||||||
if Required then Attributes := attributes + [faRequired];
|
with TFieldDef.Create(FieldDefs,FieldName,DataType,Size,Required,FieldDefs.Count+1) do
|
||||||
if ReadOnly then Attributes := attributes + [faReadOnly];
|
begin
|
||||||
if DataType = ftBCD then precision := (fields[i] as TBCDField).Precision
|
if Required then Attributes := attributes + [faRequired];
|
||||||
else if DataType = ftFMTBcd then precision := (fields[i] as TFMTBCDField).Precision;
|
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;
|
||||||
end;
|
|
||||||
finally
|
finally
|
||||||
FieldDefs.EndUpdate;
|
FieldDefs.EndUpdate;
|
||||||
end;
|
end;
|
||||||
|
@ -33,6 +33,7 @@ type
|
|||||||
procedure CreateDatasetFromFielddefs;
|
procedure CreateDatasetFromFielddefs;
|
||||||
procedure CreateDatasetFromFields;
|
procedure CreateDatasetFromFields;
|
||||||
procedure TestOpeningNonExistingDataset;
|
procedure TestOpeningNonExistingDataset;
|
||||||
|
procedure TestCreationDatasetWithCalcFields;
|
||||||
end;
|
end;
|
||||||
|
|
||||||
implementation
|
implementation
|
||||||
@ -129,6 +130,52 @@ begin
|
|||||||
ds.Free;
|
ds.Free;
|
||||||
end;
|
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
|
initialization
|
||||||
{$ifdef fpc}
|
{$ifdef fpc}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user