Browse Source

--- Merging r21268 into '.':
C packages/fcl-db/tests/testspecifictbufdataset.pas
U packages/fcl-db/src/base/bufdataset.pas
U packages/fcl-db/src/base/dbconst.pas
--- Merging r21376 into '.':
C packages/fcl-db/tests/testdbbasics.pas
--- Merging r21591 into '.':
G packages/fcl-db/src/base/bufdataset.pas
--- Merging r21642 into '.':
G packages/fcl-db/src/base/dbconst.pas
Summary of conflicts:
Text conflicts: 2

# revisions: 21268,21376,21591,21642
deleted corrected entry 2621268 Invalid stream operation
r21268 | joost | 2012-05-09 17:56:55 +0200 (Wed, 09 May 2012) | 1 line
Changed paths:
M /trunk/packages/fcl-db/src/base/bufdataset.pas
M /trunk/packages/fcl-db/src/base/dbconst.pas
M /trunk/packages/fcl-db/tests/testspecifictbufdataset.pas

* Raise an exception when a TBufDataset is opened while there is no dataset created
deleted corrected entry 2621268 Invalid stream operation
r21376 | joost | 2012-05-24 11:16:38 +0200 (Thu, 24 May 2012) | 2 lines
Changed paths:
M /trunk/packages/fcl-db/tests/testdbbasics.pas

* Reinstated the thest that was removed in r21365. Better not replace tests with
new ones, but add new tests
deleted corrected entry 2621268 Invalid stream operation
r21591 | marco | 2012-06-13 11:14:55 +0200 (Wed, 13 Jun 2012) | 3 lines
Changed paths:
M /trunk/packages/fcl-db/src/base/bufdataset.pas

* temporarily disabled the Fields.Count<FieldDefs.Count check.
mantis #22030
deleted corrected entry 2621268 Invalid stream operation
r21642 | joost | 2012-06-18 12:41:35 +0200 (Mon, 18 Jun 2012) | 1 line
Changed paths:
M /trunk/packages/fcl-db/src/base/dbconst.pas

* Forgot to commit file in r21641

git-svn-id: branches/fixes_2_6@22703 -

marco 13 years ago
parent
commit
4fd02147e1

+ 22 - 1
packages/fcl-db/src/base/bufdataset.pas

@@ -1117,9 +1117,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);
@@ -1127,6 +1127,27 @@ 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.
+  
+  // commented for now. If there are constant expressions in the select
+  // statement they are ftunknown, and not created.
+  // See mantis #22030
+  
+  //  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 FieldNo=-1)
+  for i := 0 to Fields.Count-1 do
+    if fields[i].FieldNo=0 then
+      DatabaseError(SErrNoDataset);
+
+  InitDefaultIndexes;
   CalcRecordSize;
 
   FBRecordcount := 0;

+ 1 - 0
packages/fcl-db/src/base/dbconst.pas

@@ -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 (compatible) underlying dataset, can not open';
 
 Implementation
 

+ 11 - 0
packages/fcl-db/tests/testdbbasics.pas

@@ -161,6 +161,7 @@ type
     procedure TestRequired;
     procedure TestOldValue;
     procedure TestModified;
+    procedure TestOldValue1;
   end;
 
 
@@ -618,6 +619,16 @@ begin
 end;
 
 procedure TTestCursorDBBasics.TestOldValue;
+var v : variant;
+    bufds: TDataset;
+begin
+  bufds := DBConnector.GetNDataset(0) as TDataset;
+  bufds.Open;
+  bufds.InsertRecord([0,'name']);
+  v := VarToStr(bufds.fields[1].OldValue);
+end;
+
+procedure TTestCursorDBBasics.TestOldValue1;
 begin
   with DBConnector.GetNDataset(1) as TDataset do
   begin;

+ 20 - 0
packages/fcl-db/tests/testspecifictbufdataset.pas

@@ -33,6 +33,7 @@ type
     procedure CreateDatasetFromFielddefs;
     procedure CreateDatasetFromFields;
     procedure TestCreationDatasetWithCalcFields;
+    procedure TestOpeningNonExistingDataset;
   end;
 
 implementation
@@ -156,6 +157,25 @@ begin
   end;
 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}