Delphi / ADO : how to get result of Execute()?
Solution 1
@mawg, the SHOW DATABASES
command returns an dataset with one column called 'Database', so you can use the TADOQuery
component to read the data.
try this code.
var
AdoQuery : TADOQuery;
begin
AdoQuery:=TADOQuery.Create(nil);
try
AdoQuery.Connection:=AdoConnection;
AdoQuery.SQL.Add('SHOW DATABASES');
AdoQuery.Open;
while not AdoQuery.eof do
begin
Writeln(AdoQuery.FieldByname('DataBase').AsString);
AdoQuery.Next;
end;
finally
AdoQuery.Free;
end;
end;
Solution 2
What you need is to reach the returned _Recordset
.
If you don't mind using the Delphi components, you should use TADODataSet
or TADOQuery
to execute a SQL command which can return any results (or the more low-evel TADOCommand
s' Execute
methods).
If you wanty something realy simple, w/o all the VCL balast, you mignt want to try the TADOWrap
class from ExplainThat (MIT licenced).
Solution 3
You must use an TADOQuery connected to TADODataBase. At property SQL you must include the SQl statament to retrive databases in SGDB. In SQL Server you can do this:
SELECT * FROM sysdatabases
In MySQL must exist something similar to retrieve the names.
You can connect this TADOQuery to a TDataSource and a DBGrid to see visual result or use code to explore the result of the query (some similar to this):
ADOQuery1.Open;
while not ADOQuery1.eof do begin
Name := ADOQuery1.FieldByName('DBName').AsString;
ADOQuery1.Next;
end;
Regards
Mawg says reinstate Monica
Donate a cup of food for free: Click to Give @ The Hunger Site SOreadytohelp
Updated on June 07, 2022Comments
-
Mawg says reinstate Monica almost 2 years
I have declared
AdoConnection : TADOConnection;
and successfully connected to the default "mysql" database (so, no need to pass that code).Now, taking baby steps to learn, I would like to
AdoConnection.Execute('SHOW DATABASES', cmdText);
which seems to work ok, in the sense that it doesn't throw an exception, but I am such a n00b that I don't know how I can examine the result of the command :-/Halp!