TQuery's efficiency

I use TQuery  as follows codes:

For i:=1 to 370 Do
        For j:=1 to 55 Do
    Begin

with Query_RGB do
     begin
     close;
     ParamByname('Colour_Name').asString:=Color_Name[1,i,j];
     prepare;
     open;
     while not Query_RGB.EOF do
         begin

             Color_RGB[1,i,j]:=Query_RGB.Fields[0].asInteger;
             Query_RGB.Next;

         end;
     end;


This Code cause a low efficiency,which cannot bear. How to improve it?

Thanks a lot
ws1999Asked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

rwilson032697Commented:
I'm not surprised! Thats a lot of TQuery opens!

It looks like you are going to visit every row in the table (or at least enough of them not to matter). So, use a plain TTable and iterate through it like this:

Table.First;
while not Table.eof do
  begin
    ConvertColourNameToIndex(Table.FieldByName['ColourName'].AsString, i, j);
    Color_RGB[1,i,j]:=Table.Fields[0].asInteger;
    Table.Next;
  end;

I hope this is clear. What is does is simply iterate through the records, and work out the i,j colour indexes from the colour name in each record, then doing the assignment to the color_rgb array.

Cheers,

Raymond.
0
geobulCommented:
Hi,
What does the Query_RGB.SQL contain?
And what tables do you read from?
Maybe you can decrease loops making SQL statement to give more records at once.

Regards, Geo
0
kotikCommented:
Hi!
Btw, you don't need to call Prepare every time you change params.
Prepare is used only if you change the SQL text. This will increase a little the efficiency:

Qry.Close;
Qry.SQL := YOUR_SQL_TEXT;
Qry.Prepare;
for i := 1 to 100 do
  for j := 1 to 100 do begin
    Qry.ParamByName(YourParam) := Value;
    Qry.Open;
    // Use Qry result
  end;
0
TAZICommented:
Hi . . .

What exactly are you trying to do here.  Please explain ? ?

Regards
Tazi
0
rwilson032697Commented:
<Lock>
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Delphi

From novice to tech pro — start learning today.