Advice for using VirtualQuery
Hello,
We are developing software under Embarcadero Sydney with TUniQuery component on Firebird or SQL Server DataBase. We have noticed that using a VirtualQuery is much faster (especially when sorting).
From there I have two questions :
So for more process speed, in some case, instead of doing this:
- OpenDBQueryFilterUniDir(qryValeurMes,UniCnct_CTRL_,TxtSQLTest_,'','ORDER BY NO_ID ASC'');
We do this (without sorting the "base" query, and sorting the VirtualQuery) :
- VirtualqryValeurMes:=TVirtualQuery.Create(Nil);
- OpenDBQueryFilterUniDir(qryValeurMes,UniCnct_CTRL_,TxtSQLTest_,'','');
- AddToVirtualQuery(vqryATraiter_,[InfoVQueryChild(QueryDtSetSource_,NomVirtQry_,True)],False);
- OpenDBVQueryFilter(VirtualqryValeurMes,'SELECT * FROM VIRTU_TBL_ORDER','',ORDER BY NO_ID ASC',False,[])
- vqryATraiter_.First;
Procedure AddToVirtualQuery :
- Procedure AddToVirtualQuery(vqryATraiter_ : TVirtualQuery; dseAAjouter_ : Array Of TInfoVQueryChild; ClearStructure_ : Boolean);
- Var
- IDataSet : Integer;
-
- Begin
- If ClearStructure_ = True Then CloseDBVQuery(vqryATraiter_,True);
- For IDataSet:=Low(dseAAjouter_) To High(dseAAjouter_) Do
- If dseAAjouter_[IDataSet].Ajouter = True Then
- With vqryATraiter_.SourceDataSets.Add Do
- Begin
- DataSet:=dseAAjouter_[IDataSet].DataSetComponent;
- SchemaName:='';
- TableName:=dseAAjouter_[IDataSet].DataSetName;
- End;
- End;
Function InfoVQueryChild :
- Function InfoVQueryChild(DataSetComponent_ : TDataSet; DataSetName_ : String; Ajouter_ : Boolean) : TInfoVQueryChild;
- Begin
- Result.DataSetComponent:=DataSetComponent_;
- Result.DataSetName:=DataSetName_;
- Result.Ajouter:=Ajouter_;
- End;
Function OpenDBVQueryFilter :
- procedure OpenDBVQueryFilterInfoCast(vqryATraiter_ : TVirtualQuery; CodeSQL_,Fltr_,TriF_ : String; RequestLive_ : Boolean; FieldsAsString_,FieldsAsInt_ : Array Of String);
- Var
- IField : Integer;
- Begin
- CloseDBVQuery(vqryATraiter_,False);
- vqryATraiter_.UniDirectional:=False;
- vqryATraiter_.Options.StrictUpdate:=False;
- vqryATraiter_.Options.LongStrings:=False;
- vqryATraiter_.Filtered:=False;
- vqryATraiter_.Filter:='';
- vqryATraiter_.FilterSQL:='';
- vqryATraiter_.SQL.Add(CodeSQL_);
- vqryATraiter_.FetchRows:=NbrFetchRows;
- vqryATraiter_.MasterSource:=Nil;
- vqryATraiter_.DetailFields:='';
- vqryATraiter_.MasterFields:='';
- vqryATraiter_.ReadOnly:=Not RequestLive_;
- vqryATraiter_.RefreshOptions:=[];
- vqryATraiter_.DataTypeMap.Clear;
- If Length(FieldsAsString_) > 0 Then
- For IField:=Low(FieldsAsString_) To High(FieldsAsString_) Do
- vqryATraiter_.DataTypeMap.AddFieldNameRule(FieldsAsString_[IField],ftString);
-
- If Length(FieldsAsInt_) > 0 Then
- For IField:=Low(FieldsAsInt_) To High(FieldsAsInt_) Do
- vqryATraiter_.DataTypeMap.AddFieldNameRule(FieldsAsInt_[IField],ftInteger);
- If Fltr_ <> '' Then
- Begin
- vqryATraiter_.SQL.Add('WHERE');
- vqryATraiter_.SQL.Add('('+Fltr_+')');
- End;
- If TriF_ <> '' Then vqryATraiter_.SQL.Add(TriF_);
- vqryATraiter_.Prepare;
- vqryATraiter_.Open;
- End;
Is it right to do that ? Do you have any advice to do that better ?
2. Question
----------
An other problem : We have a version problem too. With the version 9.4.0 of Unidac this process works well.
We have tried with the version 10.3.1 and we have a problem when we try to open a sorting VirtualQuery, it comes with an error :
In french : "Enregistrement non trouvé". When we remove the sorting from the VirtualQuery, it's working.