tags:

views:

291

answers:

4

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!

A: 

You need TAdoQuery to execute statements, that return results.

FractalizeR
and you don't care to give a code example, despite my proclaiming myself a n00b? Nvm, I have worked it out by now
Mawg
I am sorry, but actually there are plenty already. You just need to use google or docs. Being a noob is ok. But being lazy noob is a disaster...
FractalizeR
+1  A: 

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

Neftalí
+1  A: 

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 TADOCommands' 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).

Viktor Svub
+4  A: 

@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;
RRUZ
Thank you very much. That worked like a charm.
Mawg
hmm, now I have another question. Tho output is gotten from AdoQuery.FieldByname but it looks like I have to match the field name to the command. Can I wild-card it? (I would like a generic function to execute a command and get the result into a TStringList)
Mawg