fdLocalSql可以对fdMemTable内存表进行SQL查询(可以对多个fdMemTable内存表进行联表查询哦),fdLocalSql使用SQLITE引擎,而FIREDAC驱动SQLITE,连SQLITE驱动DLL都不需要附带的。
所有设置用FormCreate里用代码
procedure TForm6.FormCreate(Sender: TObject); begin FDConnection1.Open('DriverID=SQLite'); FDLocalSQL1.Connection:= FDConnection1; FDLocalSQL1.Active:=true; FDMemTable1.FieldDefs.Add('aID', ftInteger, 0, True); FDMemTable1.FieldDefs.Add('aName', ftString, 20, false); FDMemTable1.CreateDataSet(); FDMemTable1.AppendRecord([101, 'aaa']); FDMemTable1.AppendRecord([102, 'bbb']); FDMemTable1.AppendRecord([102, 'bbb']); FDMemTable1.AppendRecord([102, 'bbb']); FDMemTable1.AppendRecord([103, 'ccc']); FDMemTable1.LocalSQL:= FDLocalSQL1; FDMemTable1.Active:=true; FDQuery1.Connection:= FDConnection1; FDQuery1.SQL.Text:='select * from FDMemTable1 where aid>101 ' ; FDQuery1.Active:=true; DataSource1.DataSet:= FDQuery1; DbGrid1.DataSource:= DataSource1; end;
2]可以设置多个内存表,FDMemTable1,FDMemTable2
//================================ FDMemTable1 ===================================== FDMemTable1.FieldDefs.Add('aID', ftInteger, 0, True); FDMemTable1.FieldDefs.Add('aName', ftString, 20, false); FDMemTable1.CreateDataSet(); FDMemTable1.AppendRecord([101, 'aaa']); FDMemTable1.AppendRecord([102, 'bbb']); FDMemTable1.AppendRecord([102, 'bbb']); FDMemTable1.AppendRecord([102, 'bbb']); FDMemTable1.AppendRecord([103, 'ccc']); FDMemTable1.LocalSQL:= FDLocalSQL1; FDMemTable1.Active:=true; //--------------------------- FDMemTable2 -------------------------------------- FDMemTable2.FieldDefs.Add('aID', ftInteger, 0, True); FDMemTable2.FieldDefs.Add('aName', ftString, 20, false); FDMemTable2.CreateDataSet(); FDMemTable2.AppendRecord([201, 'aaa']); FDMemTable2.AppendRecord([102, 'bbb']); FDMemTable2.AppendRecord([202, 'bbb']); FDMemTable2.AppendRecord([102, 'bbb']); FDMemTable2.AppendRecord([103, 'ccc']); FDMemTable2.LocalSQL:= FDLocalSQL1; FDMemTable2.Active:=true; //================================================================================== FDQuery1.Connection:= FDConnection1; FDQuery1.SQL.Text:='select * from FDMemTable1, FDMemTable2 where FDMemTable1.aID=FDMemTable2.aID ' ; //这里写SQL语句 FDQuery1.Active:=true;