Query 'Open' or 'Execute'

Discussion of open issues, suggestions and bugs regarding UniDAC (Universal Data Access Components) for Delphi, C++Builder, Lazarus (and FPC)
Post Reply
kyunghu
Posts: 4
Joined: Thu 22 Aug 2019 02:16

Query 'Open' or 'Execute'

Post by kyunghu » Mon 09 Nov 2020 08:45

If you do not know whether or not the value returned when running the stored procedure..

try
UniQuery1.Close;
UniQuery1.SQL.Clear;
UniQuery1.SQL.Text := 'EXEC TEST';
UniQuery1.OPEN
except
UniQuery1.Execute;
end;

Is there any other way?

kyunghu
Posts: 4
Joined: Thu 22 Aug 2019 02:16

Re: Query 'Open' or 'Execute'

Post by kyunghu » Tue 10 Nov 2020 01:06

var
i : integer;
begin
UniQuery1.Close;
UniQuery1.SQL.Clear;
UniQuery1.SQL.Text := 'select * from c_usermaster';
UniQuery1.Execute;
for i := 0 to UniQuery1.RecordCount -1 do begin
Memo1.Lines.Add(UniQuery1.Fields[0].AsString);
UniQuery1.Next;
end;

Using 'Execute' in the 'select' query does not cause any problems.
Is it okay to use it like this?

MaximG
Devart Team
Posts: 1822
Joined: Mon 06 Jul 2015 11:34

Re: Query 'Open' or 'Execute'

Post by MaximG » Fri 13 Nov 2020 12:34

What database are you accessing with our components? The Open method works only for queries that return a recordset. Otherwise, a "Query does not return rows" exception will be thrown.

Execute is a universal method which analyzes the SQL statement. Depending on the statement, our components will open a recordset with the output of the query (for eaxmple, for SELECT statements) or directly execute the statement and read the out parameters (for example for statements containing EXEC).

Post Reply