mirror of
https://gitlab.com/freepascal.org/fpc/source.git
synced 2025-08-17 16:09:17 +02:00
* Implemented TDataset.AppendRecord and InsertRecord + test (bug 11450)
git-svn-id: trunk@11514 -
This commit is contained in:
parent
3291b023b5
commit
b2bc1a17ff
@ -829,6 +829,37 @@ begin
|
||||
FFieldDefs.Assign(AFieldDefs);
|
||||
end;
|
||||
|
||||
procedure TDataSet.DoInsertAppendRecord(const Values: array of const; DoAppend : boolean);
|
||||
var i : integer;
|
||||
ValuesSize : integer;
|
||||
begin
|
||||
ValuesSize:=Length(Values);
|
||||
if ValuesSize>FieldCount then DatabaseError(STooManyFields,self);
|
||||
if DoAppend then
|
||||
Append
|
||||
else
|
||||
Insert;
|
||||
|
||||
for i := 0 to ValuesSize-1 do with values[i] do
|
||||
case VType of
|
||||
vtInteger : fields[i].AsInteger := VInteger;
|
||||
vtBoolean : fields[i].AsBoolean := VBoolean;
|
||||
vtChar : fields[i].AsString := VChar;
|
||||
vtWideChar : fields[i].AsString := VWideChar;
|
||||
vtString : fields[i].AsString := AnsiString(VString);
|
||||
vtAnsiString: fields[i].AsString := AnsiString(VAnsiString);
|
||||
vtCurrency : fields[i].AsCurrency := VCurrency^;
|
||||
// vtWideString: fields[i].AsWideString := VWideString;
|
||||
vtInt64 : fields[i].AsLargeInt := VInt64^;
|
||||
vtQWord : fields[i].AsLargeInt := VQWord^;
|
||||
vtVariant : fields[i].AsVariant := VVariant^;
|
||||
else
|
||||
DatabaseError(SIncompatibleTVarRec);
|
||||
end; {case}
|
||||
Post;
|
||||
|
||||
end;
|
||||
|
||||
procedure TDataSet.InitFieldDefsFromfields;
|
||||
var i : integer;
|
||||
begin
|
||||
@ -1321,7 +1352,7 @@ end;
|
||||
Procedure TDataset.AppendRecord(const Values: array of const);
|
||||
|
||||
begin
|
||||
//!! To be implemented
|
||||
DoInsertAppendRecord(Values,True);
|
||||
end;
|
||||
|
||||
Function TDataset.BookmarkValid(ABookmark: TBookmark): Boolean;
|
||||
@ -1754,9 +1785,8 @@ end;
|
||||
|
||||
Procedure TDataset.InsertRecord(const Values: array of const);
|
||||
|
||||
|
||||
begin
|
||||
//!! To be implemented
|
||||
DoInsertAppendRecord(Values,False);
|
||||
end;
|
||||
|
||||
Function TDataset.IsEmpty: Boolean;
|
||||
|
@ -44,6 +44,7 @@ Resourcestring
|
||||
STransNotActive = 'Operation cannot be performed on an inactive transaction';
|
||||
STransActive = 'Operation cannot be performed on an active transaction';
|
||||
SFieldNotFound = 'Field not found : "%s"';
|
||||
SIncompatibleTVarRec = 'Faild to assign one of the TVarRec values into a TField';
|
||||
SInactiveDataset = 'Operation cannot be performed on an inactive dataset';
|
||||
SInvalidDisplayValues = '"%s" are not valid boolean displayvalues';
|
||||
SInvalidFieldKind = '%s : invalid field kind : ';
|
||||
@ -94,6 +95,7 @@ Resourcestring
|
||||
SDBCreateDropFailed = 'Creation or dropping of database failed';
|
||||
SMaxIndexes = 'The maximum amount of indexes is reached';
|
||||
SMinIndexes = 'The minimum amount of indexes is 1';
|
||||
STooManyFields = 'More fields specified then really exist';
|
||||
// These are added for Delphi-compatilility, but not used by the fcl:
|
||||
SFieldIndexError = 'Field index out of range';
|
||||
SIndexFieldMissing = 'Cannot access index field ''%s''';
|
||||
|
@ -30,6 +30,7 @@ type
|
||||
procedure TestCancelUpdDelete1;
|
||||
procedure TestCancelUpdDelete2;
|
||||
procedure TestSafeAsXML;
|
||||
procedure TestAppendInsertRecord;
|
||||
procedure TestBookmarks;
|
||||
procedure TestBookmarkValid;
|
||||
|
||||
@ -519,6 +520,28 @@ begin
|
||||
AssertEquals('TestName1',LoadDs.FieldByName('name').AsString);
|
||||
end;
|
||||
|
||||
procedure TTestDBBasics.TestAppendInsertRecord;
|
||||
begin
|
||||
with DBConnector.GetNDataset(true,6) do
|
||||
begin
|
||||
open;
|
||||
// InsertRecord should insert a record, set the values, post the record and
|
||||
// make the new record active.
|
||||
InsertRecord([152,'TestInsRec']);
|
||||
AssertEquals(152,fields[0].AsInteger);
|
||||
AssertEquals('TestInsRec',fields[1].AsString);
|
||||
AssertTrue(state=dsBrowse);
|
||||
|
||||
// AppendRecord should append a record, further the same as InsertRecord
|
||||
AppendRecord([151,'TestInsRec']);
|
||||
AssertEquals(151,fields[0].AsInteger);
|
||||
AssertEquals('TestInsRec',fields[1].AsString);
|
||||
AssertTrue(state=dsBrowse);
|
||||
next;
|
||||
AssertTrue(EOF);
|
||||
end;
|
||||
end;
|
||||
|
||||
procedure TTestDBBasics.TestBookmarks;
|
||||
var BM1,BM2,BM3,BM4,BM5 : TBookmark;
|
||||
begin
|
||||
|
Loading…
Reference in New Issue
Block a user