mirror of
https://gitlab.com/freepascal.org/fpc/source.git
synced 2025-08-16 04:49:19 +02:00
* add bufdataset to test framework, Mantis #20081, patch by bigchimp
git-svn-id: trunk@19495 -
This commit is contained in:
parent
293f09e41d
commit
43e9ffca3b
1
.gitattributes
vendored
1
.gitattributes
vendored
@ -1982,6 +1982,7 @@ packages/fcl-db/tests/Makefile.fpc -text
|
|||||||
packages/fcl-db/tests/README.txt svneol=native#text/plain
|
packages/fcl-db/tests/README.txt svneol=native#text/plain
|
||||||
packages/fcl-db/tests/XMLXSDExportTest.lpi svneol=native#text/plain
|
packages/fcl-db/tests/XMLXSDExportTest.lpi svneol=native#text/plain
|
||||||
packages/fcl-db/tests/XMLXSDExportTest.lpr svneol=native#text/plain
|
packages/fcl-db/tests/XMLXSDExportTest.lpr svneol=native#text/plain
|
||||||
|
packages/fcl-db/tests/bufdatasettoolsunit.pas svneol=native#text/plain
|
||||||
packages/fcl-db/tests/database.ini.txt svneol=native#text/plain
|
packages/fcl-db/tests/database.ini.txt svneol=native#text/plain
|
||||||
packages/fcl-db/tests/dbfexporttest.lpi svneol=native#text/plain
|
packages/fcl-db/tests/dbfexporttest.lpi svneol=native#text/plain
|
||||||
packages/fcl-db/tests/dbfexporttest.lpr svneol=native#text/plain
|
packages/fcl-db/tests/dbfexporttest.lpr svneol=native#text/plain
|
||||||
|
118
packages/fcl-db/tests/bufdatasettoolsunit.pas
Normal file
118
packages/fcl-db/tests/bufdatasettoolsunit.pas
Normal file
@ -0,0 +1,118 @@
|
|||||||
|
unit BufDatasetToolsUnit;
|
||||||
|
|
||||||
|
{$mode objfpc}{$H+}
|
||||||
|
|
||||||
|
interface
|
||||||
|
|
||||||
|
uses
|
||||||
|
Classes, SysUtils, toolsunit,
|
||||||
|
db,
|
||||||
|
BufDataset;
|
||||||
|
|
||||||
|
type
|
||||||
|
{ TbufdatasetConnector }
|
||||||
|
TbufdatasetDBConnector = class(TDBConnector)
|
||||||
|
protected
|
||||||
|
procedure CreateNDatasets; override;
|
||||||
|
procedure CreateFieldDataset; override;
|
||||||
|
procedure DropNDatasets; override;
|
||||||
|
procedure DropFieldDataset; override;
|
||||||
|
Function InternalGetNDataset(n : integer) : TDataset; override;
|
||||||
|
Function InternalGetFieldDataset : TDataSet; override;
|
||||||
|
end;
|
||||||
|
|
||||||
|
implementation
|
||||||
|
|
||||||
|
{ TbufdatasetDBConnector }
|
||||||
|
|
||||||
|
procedure TbufdatasetDBConnector.CreateNDatasets;
|
||||||
|
begin
|
||||||
|
// All datasets only exist in memory, so nothing has to be done
|
||||||
|
end;
|
||||||
|
|
||||||
|
procedure TbufdatasetDBConnector.CreateFieldDataset;
|
||||||
|
begin
|
||||||
|
// All datasets only exist in memory, so nothing has to be done
|
||||||
|
end;
|
||||||
|
|
||||||
|
procedure TbufdatasetDBConnector.DropNDatasets;
|
||||||
|
begin
|
||||||
|
// All datasets only exist in memory, so nothing has to be done
|
||||||
|
end;
|
||||||
|
|
||||||
|
procedure TbufdatasetDBConnector.DropFieldDataset;
|
||||||
|
begin
|
||||||
|
// All datasets only exist in memory, so nothing has to be done
|
||||||
|
end;
|
||||||
|
|
||||||
|
function TbufdatasetDBConnector.InternalGetNDataset(n: integer): TDataset;
|
||||||
|
var BufDataset : TBufDataset;
|
||||||
|
i : integer;
|
||||||
|
|
||||||
|
begin
|
||||||
|
BufDataset := TBufDataset.Create(nil);
|
||||||
|
BufDataset.FieldDefs.Add('ID',ftInteger);
|
||||||
|
BufDataset.FieldDefs.Add('NAME',ftString,50);
|
||||||
|
BufDataset.CreateDataset;
|
||||||
|
BufDataset.Open;
|
||||||
|
for i := 1 to n do
|
||||||
|
begin
|
||||||
|
BufDataset.Append;
|
||||||
|
BufDataset.FieldByName('ID').AsInteger := i;
|
||||||
|
BufDataset.FieldByName('NAME').AsString := 'TestName' + inttostr(i);
|
||||||
|
BufDataset.Post;
|
||||||
|
end;
|
||||||
|
BufDataset.Close;
|
||||||
|
Result := BufDataset;
|
||||||
|
end;
|
||||||
|
|
||||||
|
function TbufdatasetDBConnector.InternalGetFieldDataset : TDataSet;
|
||||||
|
|
||||||
|
|
||||||
|
var BufDataset : TBufDataset;
|
||||||
|
i : integer;
|
||||||
|
|
||||||
|
begin
|
||||||
|
BufDataset := TBufDataset.Create(nil);
|
||||||
|
with BufDataset do
|
||||||
|
begin
|
||||||
|
//todo: this is based on memds.
|
||||||
|
//check and add bufdataset supported fields
|
||||||
|
FieldDefs.Add('ID',ftInteger);
|
||||||
|
FieldDefs.Add('FSTRING',ftString,10);
|
||||||
|
FieldDefs.Add('FSMALLINT',ftSmallint);
|
||||||
|
FieldDefs.Add('FINTEGER',ftInteger);
|
||||||
|
// FieldDefs.Add('FWORD',ftWord);
|
||||||
|
FieldDefs.Add('FBOOLEAN',ftBoolean);
|
||||||
|
FieldDefs.Add('FFLOAT',ftFloat);
|
||||||
|
// FieldDefs.Add('FCURRENCY',ftCurrency);
|
||||||
|
// FieldDefs.Add('FBCD',ftBCD);
|
||||||
|
FieldDefs.Add('FDATE',ftDate);
|
||||||
|
FieldDefs.Add('FTIME',ftTime);
|
||||||
|
FieldDefs.Add('FDATETIME',ftDateTime);
|
||||||
|
FieldDefs.Add('FLARGEINT',ftLargeint);
|
||||||
|
CreateDataset;
|
||||||
|
Open;
|
||||||
|
for i := 0 to testValuesCount-1 do
|
||||||
|
begin
|
||||||
|
Append;
|
||||||
|
FieldByName('ID').AsInteger := i;
|
||||||
|
FieldByName('FSTRING').AsString := testStringValues[i];
|
||||||
|
FieldByName('FSMALLINT').AsInteger := testSmallIntValues[i];
|
||||||
|
FieldByName('FINTEGER').AsInteger := testIntValues[i];
|
||||||
|
FieldByName('FBOOLEAN').AsBoolean := testBooleanValues[i];
|
||||||
|
FieldByName('FFLOAT').AsFloat := testFloatValues[i];
|
||||||
|
ShortDateFormat := 'yyyy-mm-dd';
|
||||||
|
FieldByName('FDATE').AsDateTime := StrToDate(testDateValues[i]);
|
||||||
|
FieldByName('FLARGEINT').AsLargeInt := testLargeIntValues[i];
|
||||||
|
Post;
|
||||||
|
end;
|
||||||
|
Close;
|
||||||
|
end;
|
||||||
|
Result := BufDataset;
|
||||||
|
end;
|
||||||
|
|
||||||
|
initialization
|
||||||
|
RegisterClass(TbufdatasetDBConnector);
|
||||||
|
end.
|
||||||
|
|
@ -10,7 +10,6 @@ type=interbase
|
|||||||
|
|
||||||
; PostgreSQL database:
|
; PostgreSQL database:
|
||||||
[postgresql]
|
[postgresql]
|
||||||
|
|
||||||
; The connector specifies the DB-component that has to be used. The 'sql'
|
; The connector specifies the DB-component that has to be used. The 'sql'
|
||||||
; connector tests the SQLDB components
|
; connector tests the SQLDB components
|
||||||
connector=sql
|
connector=sql
|
||||||
@ -105,3 +104,7 @@ name=/tmp
|
|||||||
; MemDS in memory dataset:
|
; MemDS in memory dataset:
|
||||||
[memds]
|
[memds]
|
||||||
connector=memds
|
connector=memds
|
||||||
|
|
||||||
|
; BufDataset in memory dataset:
|
||||||
|
[bufdataset]
|
||||||
|
connector=bufdataset
|
||||||
|
@ -14,6 +14,7 @@ uses
|
|||||||
// List of supported database-connectors
|
// List of supported database-connectors
|
||||||
sqldbtoolsunit,
|
sqldbtoolsunit,
|
||||||
dbftoolsunit,
|
dbftoolsunit,
|
||||||
|
bufdatasettoolsunit,
|
||||||
memdstoolsunit,
|
memdstoolsunit,
|
||||||
SdfDSToolsUnit,
|
SdfDSToolsUnit,
|
||||||
// Units wich contains the tests
|
// Units wich contains the tests
|
||||||
|
@ -330,7 +330,7 @@ begin
|
|||||||
DBConnectorClass := GetClass('T'+dbconnectorname+'DBConnector');
|
DBConnectorClass := GetClass('T'+dbconnectorname+'DBConnector');
|
||||||
if assigned(DBConnectorClass) then
|
if assigned(DBConnectorClass) then
|
||||||
DBConnector := TDBConnectorClass(DBConnectorClass).create
|
DBConnector := TDBConnectorClass(DBConnectorClass).create
|
||||||
else Raise Exception.Create('Unknown db-connector specified');
|
else Raise Exception.Create('Unknown db-connector specified: ' + 'T'+dbconnectorname+'DBConnector');
|
||||||
inc(DBConnectorRefCount);
|
inc(DBConnectorRefCount);
|
||||||
end;
|
end;
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user