在线时间:8:00-16:00
迪恩网络APP
随时随地掌握行业动态
扫描二维码
关注迪恩网络微信公众号
c++builder XE 官方demo最全60多个 http://community.embarcadero.com/blogs?view=entry&id=8761
FireDAC.Comp.Client
用好FDMemTable代替之前的ClientDataSet,以前ClientDataSet内存表转换太繁琐了步骤。 TClientDataSet *cds = new TClientDataSet(this);
c++智能指针 #include <memory> //For STL auto_ptr class std::auto_ptr<TFDMemTable> table (new TFDMemTable(NULL));
一句就可以了 FDMemTable1->CopyDataSet(dm->ADOQueryPub, TFDCopyDataSetOptions() << coStructure << coRestart << coAppend);
多用FDMemTable,不再用ClientDataSet\DataSetProvider1做转换了 FDMemTable2->Data = FDMemTable1->Data; FDMemTable2->CopyDataSet(FDMemTable1, TFDCopyDataSetOptions() << coStructure << coRestart << coAppend);
建立缓存表 FDMemTable1.Close(); FDMemTable1.FieldDefs.Clear(); FDMemTable1.FieldDefs.Add('ID', ftInteger, 0, True); FDMemTable1.FieldDefs.Add('Name', ftString, 20, false); FDMemTable1.CreateDataSet(); FDMemTable1.AppendRecord([101, 'aaa']); FDMemTable1.AppendRecord([102, 'bbb']); FDMemTable1.AppendRecord([103, 'ccc']); 0)FDMemTable1.SourceView遍历各行数据,取任意行数据无需Next移动指针了。TFDDatSView for (int i = 0; i < FDMemTable1->SourceView->Rows->Count; i++) FDMemTable1->SourceView->Rows->ItemsI[i]->GetData("fieldName");//取指定行指定字段名的值 9行7列的值。 FDMemTable1.Data.DataView.Rows.ItemsI[9].ValueI[7]; FDMemTable1.Table.Rows[i].ValueI[oCol.Index] Caption = FDMemTable1->SourceView->Rows->Count;//过滤后1条
iMax := 0; for i := 0 to FDQuery1.SourceView.Rows.Count - 1 do if FDQuery1.SourceView.Rows[i].GetData('id', @iVal) and (iVal > iMax) then iMax := iVal
数据集拷贝,复制数据集,合并数据集 FDMemTable1->Filter = "id=102"; FDMemTable1只有1条记录 1)Data FDMemTable2->Data = FDMemTable1->Data;
FDQuery->Open("select * from tt"); FDMemTable2->Data = FDQuery->Data;
FDMemTable2是全部记录,有3条记录。 FDMemTable1->Delete();后的记录不在Data里。 2)CopyDataSet 带结构拷贝 FDMemTable2->CopyDataSet(FDMemTable1, TFDCopyDataSetOptions() << coStructure << coRestart << coAppend); FDMemTable2->CommitUpdates(); 缓存更新用到changeCount,所以copy完后加上CommitUpdates
不带结构,仅拷贝数据,字段个数可以不一致,字段数以目标数据集FDMemTable2为标准。 FDMemTable2->CopyDataSet(FDMemTable1, TFDCopyDataSetOptions() << coRestart << coAppend); //第二个参数默认是coRestart << coAppend,所以下面就更简单了。 FDMemTable2->CopyDataSet(FDMemTable1); FDMemTable2只有1条记录 3)CopyRecord\CopyField copy the current record field values .Only One Record FDMemTable2->CopyDataSet(FDMemTable1, TFDCopyDataSetOptions() << coStructure); 4)CloneCursor All Record, ignore filter CloneCursor,数据共享,一个修改,另一个也修改了,但是FDMemTable1->Close之后FDMemTable2还正常显示。 FDMemTable2->CloneCursor( FDMemTable1); 2016.3.4 test 不能排序,FDMemTable2->IndexFieldNames = "ID";不起作用,所以尽量不建议用这个方式。 5)AtrachTable All Record,ignore filter,TFDDatSTable FDMemTable2->AttachTable(FDMemTable1->Table, NULL); //or //FDMemTable2->AttachTable(FDMemTable1->Table,FDMemTable1->View); 6)FilteredData FDQuery1.Filter := 'upper(name) like ''D%'''; FDQuery1.Filtered := True; // copy to FDMemTable1 all FDQuery1 visible (where name starts from D) records FDMemTable1.Data := FDQuery1.FilteredData; 11)增强的Locate功能LocateEx、LookupEx函数 lxoCheckOnly If included, then LocateEx does not: Change the current position. Fire BeforeScroll / AfterScroll events. Finish editing mode 第一步:
A DataTable or a DataView must be supplied. Hint: if that is TFDMemTable, use CreateDataSet or CloneCursor to open dataset CloneCurso的数据集均无法用IndexFieldNames排序。用CreateDataSet创建的数据集排序正常! TSQLTimeStampField Caching_Updates_
FDQuery1.CachedUpdates := True;
iSavePoint := FDQuery1.SavePoint;
try
FDQuery1.Append;
...
FDQuery1.Post;
FDQuery1.Append;
...
FDQuery1.Post;
FDQuery1.Append;
...
FDQuery1.Post;
except
FDQuery.SavePoint := iSavePoint;
end;
FDQuery1.CachedUpdates := True;
FDQuery1.Append;
...
FDQuery1.Post;
FDQuery1.Append;
...
FDQuery1.Post;
FDQuery1.Append;
...
FDQuery1.Post;
FDConnection1.StartTransaction;
iErrors := FDQuery1.ApplyUpdates;
if iErrors = 0 then begin
FDQuery1.CommitUpdates;
FDConnection1.Commit;
end
else
FDConnection1.Rollback;
var
oErr: EFDException;
...
if FDQuery1.ApplyUpdates > 0 then begin
FDQuery1.FilterChanges := [rtModified, rtInserted, rtDeleted, rtHasErrors];
try
FDQuery1.First;
while not FDQuery1.Eof do begin
oErr := FDQuery1.RowError;
if oErr <> nil then begin
// process exception object
...
end;
FDQuery1.Next;
end;
finally
FDQuery1.FilterChanges := [rtUnmodified, rtModified, rtInserted];
end;
end;
|
2023-10-27
2022-08-15
2022-08-17
2022-09-23
2022-08-13
请发表评论