Advice for using VirtualQuery

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 :

1. Question
----------
So for more process speed, in some case, instead of doing this:
  1. OpenDBQueryFilterUniDir(qryValeurMes,UniCnct_CTRL_,TxtSQLTest_,'','ORDER BY NO_ID ASC'');
We do this (without sorting the "base" query, and sorting the VirtualQuery) :
  1. VirtualqryValeurMes:=TVirtualQuery.Create(Nil);
  2. OpenDBQueryFilterUniDir(qryValeurMes,UniCnct_CTRL_,TxtSQLTest_,'','');
  3. AddToVirtualQuery(vqryATraiter_,[InfoVQueryChild(QueryDtSetSource_,NomVirtQry_,True)],False);
  4. OpenDBVQueryFilter(VirtualqryValeurMes,'SELECT * FROM VIRTU_TBL_ORDER','',ORDER BY NO_ID ASC',False,[])
  5. vqryATraiter_.First;
Procedure AddToVirtualQuery :
  1. Procedure AddToVirtualQuery(vqryATraiter_ : TVirtualQuery; dseAAjouter_ : Array Of TInfoVQueryChild; ClearStructure_ : Boolean);
  2. Var
  3. IDataSet : Integer;
  4.  
  5. Begin
  6.  If ClearStructure_ = True Then CloseDBVQuery(vqryATraiter_,True);
  7. For IDataSet:=Low(dseAAjouter_) To High(dseAAjouter_) Do
  8. If dseAAjouter_[IDataSet].Ajouter = True Then
  9. With vqryATraiter_.SourceDataSets.Add Do
  10. Begin
  11. DataSet:=dseAAjouter_[IDataSet].DataSetComponent;
  12. SchemaName:='';
  13. TableName:=dseAAjouter_[IDataSet].DataSetName;
  14. End;
  15. End;
Function InfoVQueryChild :
  1. Function InfoVQueryChild(DataSetComponent_ : TDataSet; DataSetName_ : String; Ajouter_ : Boolean) : TInfoVQueryChild;
  2. Begin
  3. Result.DataSetComponent:=DataSetComponent_;
  4. Result.DataSetName:=DataSetName_;
  5. Result.Ajouter:=Ajouter_;
  6. End;

Function OpenDBVQueryFilter :

  1. procedure OpenDBVQueryFilterInfoCast(vqryATraiter_ : TVirtualQuery;  CodeSQL_,Fltr_,TriF_ : String; RequestLive_ : Boolean; FieldsAsString_,FieldsAsInt_ : Array Of String);
  2. Var
  3.  IField : Integer;

  4. Begin
  5. CloseDBVQuery(vqryATraiter_,False);
  6.  vqryATraiter_.UniDirectional:=False;
  7. vqryATraiter_.Options.StrictUpdate:=False;
  8. vqryATraiter_.Options.LongStrings:=False;
  9. vqryATraiter_.Filtered:=False;
  10. vqryATraiter_.Filter:='';
  11. vqryATraiter_.FilterSQL:='';
  12. vqryATraiter_.SQL.Add(CodeSQL_);
  13. vqryATraiter_.FetchRows:=NbrFetchRows;
  14. vqryATraiter_.MasterSource:=Nil;
  15. vqryATraiter_.DetailFields:='';
  16. vqryATraiter_.MasterFields:='';
  17. vqryATraiter_.ReadOnly:=Not RequestLive_;
  18. vqryATraiter_.RefreshOptions:=[];
  19. vqryATraiter_.DataTypeMap.Clear;
  20. If Length(FieldsAsString_) > 0 Then
  21. For IField:=Low(FieldsAsString_) To High(FieldsAsString_) Do
  22. vqryATraiter_.DataTypeMap.AddFieldNameRule(FieldsAsString_[IField],ftString);
  23.  
  24. If Length(FieldsAsInt_) > 0 Then
  25. For IField:=Low(FieldsAsInt_) To High(FieldsAsInt_) Do
  26. vqryATraiter_.DataTypeMap.AddFieldNameRule(FieldsAsInt_[IField],ftInteger);
  27. If Fltr_ <> '' Then
  28. Begin
  29. vqryATraiter_.SQL.Add('WHERE');
  30. vqryATraiter_.SQL.Add('('+Fltr_+')');
  31. End;
  32. If TriF_ <> '' Then vqryATraiter_.SQL.Add(TriF_);
  33. vqryATraiter_.Prepare;
  34. vqryATraiter_.Open;
  35. 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.