mirror of
https://gitlab.com/freepascal.org/fpc/source.git
synced 2025-04-22 06:49:27 +02:00
* Raise an exception when a TBufDataset is opened while there is no dataset created
git-svn-id: trunk@21268 -
This commit is contained in:
parent
cbb8b23c71
commit
f011d02833
@ -1116,9 +1116,9 @@ end;
|
||||
procedure TCustomBufDataset.InternalOpen;
|
||||
|
||||
var IndexNr : integer;
|
||||
i : integer;
|
||||
|
||||
begin
|
||||
InitDefaultIndexes;
|
||||
if not Assigned(FDatasetReader) and (FileName<>'') then
|
||||
begin
|
||||
FFileStream := TFileStream.Create(FileName,fmOpenRead);
|
||||
@ -1126,6 +1126,21 @@ begin
|
||||
FReadFromFile := True;
|
||||
end;
|
||||
if assigned(FDatasetReader) then IntLoadFielddefsFromFile;
|
||||
|
||||
// This is to check if the dataset is actually created (By calling CreateDataset,
|
||||
// reading from a stream in some other way implemented by a descendent)
|
||||
// If there are less fields then FieldDefs we know for sure that the dataset
|
||||
// is not (correctly) created.
|
||||
if Fields.Count<FieldDefs.Count then
|
||||
DatabaseError(SErrNoDataset);
|
||||
// If there is a field with FieldNo=0 then the fields are not found to the
|
||||
// FieldDefs which is a sign that there is no dataset created. (Calculated and
|
||||
// lookupfields have FielNo=-1)
|
||||
for i := 0 to Fields.Count-1 do
|
||||
if fields[i].FieldNo=0 then
|
||||
DatabaseError(SErrNoDataset);
|
||||
|
||||
InitDefaultIndexes;
|
||||
CalcRecordSize;
|
||||
|
||||
FBRecordcount := 0;
|
||||
|
@ -111,6 +111,7 @@ Resourcestring
|
||||
SRollBackRetaining = 'Rollback and retaining transaction';
|
||||
SErrNoFieldsDefined = 'Can not create a dataset when there are no fielddefinitions or fields defined';
|
||||
SErrApplyUpdBeforeRefresh= 'Must apply updates before refreshing data';
|
||||
SErrNoDataset = 'Missing underlying dataset, can not open';
|
||||
|
||||
Implementation
|
||||
|
||||
|
@ -32,6 +32,7 @@ type
|
||||
published
|
||||
procedure CreateDatasetFromFielddefs;
|
||||
procedure CreateDatasetFromFields;
|
||||
procedure TestOpeningNonExistingDataset;
|
||||
end;
|
||||
|
||||
implementation
|
||||
@ -109,6 +110,25 @@ begin
|
||||
TestDataset(ds);
|
||||
end;
|
||||
|
||||
procedure TTestSpecificTBufDataset.TestOpeningNonExistingDataset;
|
||||
var ds : TBufDataset;
|
||||
f: TField;
|
||||
begin
|
||||
ds := TBufDataset.Create(nil);
|
||||
F := TIntegerField.Create(ds);
|
||||
F.FieldName:='ID';
|
||||
F.DataSet:=ds;
|
||||
|
||||
CheckException(ds.Open,EDatabaseError);
|
||||
ds.Free;
|
||||
|
||||
ds := TBufDataset.Create(nil);
|
||||
DS.FieldDefs.Add('ID',ftInteger);
|
||||
|
||||
CheckException(ds.Open,EDatabaseError);
|
||||
ds.Free;
|
||||
end;
|
||||
|
||||
initialization
|
||||
{$ifdef fpc}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user