TMyQuery, read whole record at once?
Posted: Mon 13 Jan 2020 16:49
I am fetching data from a mySQL database using TMyQuery. Usually I process one field at a time inside a while not eof loop using fieldbyname().
As some processing is complex I'd like instead to fetch the whole record at once and pass that to a procedure to do the processing of each field away from the loop.
If this is possible to do, please can someone show me the syntax to fetch one whole record, pass it as a parameter and then extract each field?
The structure of the code I usually use is
and the pseudo code of what I want to do is
As some processing is complex I'd like instead to fetch the whole record at once and pass that to a procedure to do the processing of each field away from the loop.
If this is possible to do, please can someone show me the syntax to fetch one whole record, pass it as a parameter and then extract each field?
The structure of the code I usually use is
Code: Select all
Procedure ProcessTable;
begin
Query1.SQL.Clear;
Query1.SQL.Add(SQL);
Query1.Open;
Query1.first ;
while not Query1.Eof do
begin
var1 := Query1.FieldByName('field1').AsString;
var2 := Query1.FieldByName('field2').AsInteger;
//etc.
Query1.Next;
end;
Query1.close;
end;
Code: Select all
procedure ProcessRecord( TheRecord : <some type>);
begin
..
//extract the fields from TheRecord and process them - how?
var1 := TheRecord .FieldByName('field1').AsString; - how?
var2 := TheRecord .FieldByName('field2').AsInteger; - how?
..
end;
Procedure ProcessTable;
var
record : <some type>;
begin
Query1.SQL.Clear;
Query1.SQL.Add(SQL);
Query1.Open;
Query1.first ;
while not Query1.Eof do
begin
record:= Query1.<Get the whole record at once>; //how?
ProcessRecord(record);
Query1.Next;
end;
Query1.close
end;