Page 1 of 1

ExecSQL Question

Posted: Mon 11 May 2009 21:53
by randyc
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.

Re: ExecSQL Question

Posted: Tue 12 May 2009 20:23
by eduardosic
randyc 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.
To return resultset you need of TMyQuery

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;