I'm trying to create an app that will mimic what will eventually be a php/mysql web app. Therefore, I'm trying to mostly use SQL commands directly and not use data-aware components/datasets.
I want to execute a simple "SELECT * FROM table WHERE id=xxx" command, and I need to have access to the resulting SQL table (might be one line, might be more) to parse. There seems to be a lot of ways to submit SQL - TMyCommand, TMyConnection, TMyQuery, TMyStoredProc. I was trying to use TMyConnection.ExecSQL(qstr, []), but I can't find the "output" of running the SQL.
1. Is the TMyConnection.ExecSQL the best way to do this?
2. Where/how can I get the raw SQL table output from my SELECT command?
(Using MySQL Embedded)
Thanks.
ExecSQL Question
-
eduardosic
- Posts: 387
- Joined: Fri 18 Nov 2005 00:26
- Location: Brazil
Re: ExecSQL Question
To return resultset you need of TMyQueryrandyc wrote:I'm trying to create an app that will mimic what will eventually be a php/mysql web app. Therefore, I'm trying to mostly use SQL commands directly and not use data-aware components/datasets.
I want to execute a simple "SELECT * FROM table WHERE id=xxx" command, and I need to have access to the resulting SQL table (might be one line, might be more) to parse. There seems to be a lot of ways to submit SQL - TMyCommand, TMyConnection, TMyQuery, TMyStoredProc. I was trying to use TMyConnection.ExecSQL(qstr, []), but I can't find the "output" of running the SQL.
1. Is the TMyConnection.ExecSQL the best way to do this?
2. Where/how can I get the raw SQL table output from my SELECT command?
(Using MySQL Embedded)
Thanks.
try this:
Code: Select all
MyQuery.Connection := MyConnection;
with MyQuery do begin
Close;
SQL.Text := 'SELECT * FROM table WHERE id = :ID';
ParamByName( 'ID' ).AsInteger := 100;
Execute;
SomeVariable := FieldByName( 'FieldName' ).AsString;
Close;
end;