To help identify the problem, you could replace your main block with...
LBeneficiaryVisits := TVisites.Create;
//
try
try
//
with qryRead do
begin
//
//SQL.Clear;
//SQL.Add('select * from ' + strStoredProcName + '(' + QuotedStr(strStartDate) + ',' + QuotedStr(strEndDate) + ')');
// Open the dataset
//Open;
//
For i := 0 to 10000 do // Or whatever you think the record count is...
//while not EOF do
begin
//
with LBeneficiaryVisits.Add do
begin
Prenom := 'Hello World'';
Sexe := 'Hello World';
// Skip null date fields
//if not Fields.Fields[2].IsNull then
DateNaissance := Now;
SigneDistinctif := 'Hello World';
Pays := 'Hello World';
Mediateur := 'Hello World';
SituationFamiliale := 'Hello World';
Dependants := Random(1000);
EnfantsScolarises := Random(1000);
EnfantsNonScolarises := Random(1000);
EntreeEnFrance := Random(1000);
VilleCodePostale := 'Hello World';
SituationAdministrative := 'Hello World';
AutorisationTravailOuiNon := 'Hello World';
Logement := 'Hello World';
LienAvecBondy := Random(1000);
CouvertureMedicale := 'Hello World';
NomMedecinTraitant := 'Hello World';
Pathologie := 'Hello World';
PathologieSousTraitementOuiNon := 'Hello World';
SuiviPar := 'Hello World';
SuiviSociale := 'Hello World';
// Skip null date fields
//if not Fields.Fields[22].IsNull then
PremiereVisite := Now;
MotifPremiereVisite := 'Hello World';
OrientePar := 'Hello World';
Partenaire := 'Hello World';
Ressources := 'Hello World';
Charges := 'Hello World';
TotaleEntretiens := 'Hello World';
NombreRepas := Random(1000);
PresentSansMange := Random(1000);
TotaleFrequentation := Random(1000);
//
end;
//Next;
end;
// close the dataset
//Close;
end;
// copy the collection to a memory stream in preparation for sending to clients
SaveCollectionToStream(LBeneficiaryVisits, LStream);
except
// close the open dataset
// an open dataset may be the reason why errors hang the server & force a server restart
//if qryRead.Active then
// qryRead.Close;
end;
finally
// Release the objects created earlier
FreeAndNil(LBeneficiaryVisits);
end;
Sorry if I'm stating the obvious, but:
If it still takes 5 minutes, nothing to do with the cursor; it'll be populating the collection, or streaming it.
- next step, comment out the streaming. If it still takes 5 minutes, it's the collection population.
If it's now fast, it's the streaming...
If this whole code block is fast, then indeed it is the database cursor somehow. Can't see how myself, but we live in a wierd old world :-)
Good luck...
UPDATE: Investigated a little further. Crumbs, this was a shock... Don't know if it's your problem, but you're actually doing a whole lot of looping you don't know about...
In DB.pas...
function TFields.FieldByNumber(FieldNo : Integer) : TField;
Var i : Longint;
begin
Result:=Nil;
For I:=0 to FFieldList.Count-1 do
If FieldNo=TField(FFieldList[I]).FieldNo then
begin
Result:=TField(FFieldList[i]);
Exit;
end;
end;
To eliminate this
Var
FieldDateNaissance : TField;
then before you start your while loop...
FieldDateNaissance := Fields.Fields[2];
then within your while loop do the following instead...
DateNaissance := FieldDateNaissance.AsDateTime;
That'll actually get rid of a fair amount of overhead. 5 minutes worth? Doesn't feel right, but you never know... And I still recommend my first approach to eliminate the collections...