From 4087fd6888cda337e3a4c3aeb1a7e6972ec7155d Mon Sep 17 00:00:00 2001 From: joost Date: Sat, 9 Aug 2008 10:37:03 +0000 Subject: [PATCH] * Implemented TBufDataset.CreateDataset * TBufDataset can now be used as a memory-dataset like TMemDataset git-svn-id: trunk@11539 - --- packages/fcl-db/src/base/bufdataset.pas | 27 +++++++++++++++++++++--- packages/fcl-db/tests/testdbbasics.pas | 28 +++++++++++++++++++++++++ 2 files changed, 52 insertions(+), 3 deletions(-) diff --git a/packages/fcl-db/src/base/bufdataset.pas b/packages/fcl-db/src/base/bufdataset.pas index 1845eee4ca..f02f1915d3 100644 --- a/packages/fcl-db/src/base/bufdataset.pas +++ b/packages/fcl-db/src/base/bufdataset.pas @@ -371,8 +371,8 @@ type procedure SetFilterText(const Value: String); override; {virtual;} procedure SetFiltered(Value: Boolean); override; {virtual;} {abstracts, must be overidden by descendents} - function Fetch : boolean; virtual; abstract; - function LoadField(FieldDef : TFieldDef;buffer : pointer; out CreateBlob : boolean) : boolean; virtual; abstract; + function Fetch : boolean; virtual; + function LoadField(FieldDef : TFieldDef;buffer : pointer; out CreateBlob : boolean) : boolean; virtual; procedure LoadBlobIntoBuffer(FieldDef: TFieldDef;ABlobBuf: PBufBlobField); virtual; abstract; public @@ -394,6 +394,7 @@ type const ACaseInsFields: string = ''); virtual; procedure SaveToFile(const FileName: string = ''; Format: TDataPacketFormat = dfBinary); procedure LoadFromFile(const AFileName: string = ''); + procedure CreateDataset; property ChangeCount : Integer read GetChangeCount; property MaxIndexesCount : Integer read FMaxIndexesCount write SetMaxIndexesCount; @@ -752,7 +753,7 @@ end; Function TBufDataset.GetCanModify: Boolean; begin - Result:= False; + Result:= True; end; function TBufDataset.intAllocRecordBuffer: PChar; @@ -2323,6 +2324,12 @@ begin FileName := StoreFileName; end; +procedure TBufDataset.CreateDataset; +begin + CheckInactive; + CreateFields; +end; + procedure TBufDataset.IntLoadFromFile(const FileName: string); function GetNodeAttribute(const aNode : TDOMNode; AttName : String) : string; @@ -2458,6 +2465,20 @@ begin Refresh; end; +function TBufDataset.Fetch: boolean; +begin + // Empty procedure to make it possible to use TBufDataset as a memory dataset + Result := False; +end; + +function TBufDataset.LoadField(FieldDef: TFieldDef; buffer: pointer; out + CreateBlob: boolean): boolean; +begin + // Empty procedure to make it possible to use TBufDataset as a memory dataset + CreateBlob := False; + Result := False; +end; + procedure TBufDataset.ParseFilter(const AFilter: string); begin // parser created? diff --git a/packages/fcl-db/tests/testdbbasics.pas b/packages/fcl-db/tests/testdbbasics.pas index b10b8969e2..e295462616 100644 --- a/packages/fcl-db/tests/testdbbasics.pas +++ b/packages/fcl-db/tests/testdbbasics.pas @@ -29,6 +29,7 @@ type procedure TearDown; override; published procedure TestFileNameProperty; + procedure TestClientDatasetAsMemDataset; procedure TestCancelUpdDelete1; procedure TestCancelUpdDelete2; procedure TestSafeAsXML; @@ -534,6 +535,33 @@ begin FTestXMLDatasetDefinition(Ds); end; +procedure TTestDBBasics.TestClientDatasetAsMemDataset; +var ds : TBufDataset; + i : integer; +begin + ds := TBufDataset.Create(nil); + DS.FieldDefs.Add('ID',ftInteger); + DS.FieldDefs.Add('NAME',ftString,50); + DS.CreateDataset; + DS.Open; + for i := 1 to 10 do + begin + ds.Append; + ds.FieldByName('ID').AsInteger := i; + ds.FieldByName('NAME').AsString := 'TestName' + inttostr(i); + DS.Post; + end; + ds.first; + for i := 1 to 10 do + begin + AssertEquals(i,ds.fieldbyname('ID').asinteger); + AssertEquals('TestName' + inttostr(i),ds.fieldbyname('NAME').AsString); + ds.next; + end; + AssertTrue(ds.EOF); + DS.Close; +end; + procedure TTestDBBasics.TestAppendInsertRecord; begin with DBConnector.GetNDataset(true,6) do