using parameter by where clause in ()

Discussion of open issues, suggestions and bugs regarding MyDAC (Data Access Components for MySQL) for Delphi, C++Builder, Lazarus (and FPC)
Post Reply
jkuiper
Posts: 138
Joined: Fri 04 Aug 2006 14:17

using parameter by where clause in ()

Post by jkuiper » Thu 03 Nov 2011 09:42

I want to use a parameter to findsome records.

Normally the query look likes this : 'select * from table where id in (1,2,3)', it wil gives the asked records.

In Delphi I use a parameter:

Code: Select all

Myquery1.SQL.Text := from table where id in (:id);
MyQuery1.Params[0].Value := eparams.text;
This results in: 'select * from table where id in ('1,2,3')'

Is there a way to get the proper value (1,2,3) when I use Params?

AndreyZ

Post by AndreyZ » Thu 03 Nov 2011 10:41

Hello,

To avoid this problem, you should use macros instead of parameters. Here is an example:

Code: Select all

Myquery1.SQL.Text := 'select * from table where id in (&id)';
MyQuery1.Macros[0].Value := eparams.text;
MyQuery1.Open;
For more information about macros, please read the 'Working with Macros' topic of the MyDAC documentation.

Post Reply