我有一个TFDMemTable,里面装满了数千张唱片。是否有一种方法来限制结果记录的前50?
我试着用:
FDMemTable.FetchOptions.RecsSkip := 0;
FDMemTable.FetchOptions.RecsMax := 50;
FDMemTable.Open;但它没有起作用,数据保持不变。
发布于 2018-09-01 17:30:55
我希望@Victoria能够向您展示一种更好、更一般的方法,但至少有两种方法可以做到这一点:
要实现其中的第一个,将以下组件添加到表单/数据模中:
FDLocalSQL1: TFDLocalSQL;
FDConnection1: TFDConnection;
FDQuery1: TFDQuery;
FDPhysSQLiteDriverLink1: TFDPhysSQLiteDriverLink;然后执行如下代码:
procedure TForm3.CopyData1;
begin
FDConnection1.DriverName := 'SQLite';
FDConnection1.Connected := True;
FDLocalSQL1.Connection := FDConnection1;
FDLocalSQL1.DataSets.Add(FDMemTable1); // this is the source dataset
FDLocalSQL1.Active := True;
FDQuery1.SQL.Text := 'select * from FDMemTable1 order by ID limit 5'; // ID being an Integer field of the FDMemTable
FDQuery1.Active := True;
FDMemTable1.Close;
FDMemTable1.Data := FDQuery1.Data; // Re-opens FDMemTable 1, which now contains only the first X records
end;FD的LocalSQL使用Sqlite来完成它的工作。Sqlite中的函数等效为"Select .“它的限制条款。
当然,在您的任务中使用LocalSQL的一个优点是,由于LocalSQL支持order,所以您可以确定保留了哪些(顶部)X记录。
批处理迁移方法所需的代码要少一些,但需要使用筛选器表达式来识别第一个X记录。使用ID字段的示例可能是
procedure TForm3.CopyData2;
begin
FDMemTable1.Filter := 'ID <=50';
FDMemTable1.Filtered := True;
FDBatchMove1.Execute; // move data from FDMemTable1 to FDMemTable2;
FDMemTable1.Close;
FDMemTable1.Data := FDMemTable2.Data; // Re-opens FDMemTable 1, which now contains only the first X records
end;顺便,你说
我有一个TFDMemTable,里面装满了数千张唱片。我
我认为,您尝试过的方法的问题可能是,当您在FDMemTable中拥有记录时,尝试以尝试的方式限制它们的数量为时已晚。*)
https://stackoverflow.com/questions/52129389
复制相似问题