ExecSQL Question

Discussion of open issues, suggestions and bugs regarding MyDAC (Data Access Components for MySQL) for Delphi, C++Builder, Lazarus (and FPC)
Post Reply
randyc
Posts: 2
Joined: Mon 27 Apr 2009 19:49

ExecSQL Question

Post by randyc » Mon 11 May 2009 21:53

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.

eduardosic
Posts: 387
Joined: Fri 18 Nov 2005 00:26
Location: Brazil

Re: ExecSQL Question

Post by eduardosic » Tue 12 May 2009 20:23

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;

Post Reply