Using macro or param

Discussion of open issues, suggestions and bugs regarding MyDAC (Data Access Components for MySQL) for Delphi, C++Builder, Lazarus (and FPC)
Post Reply
cybsistemas
Posts: 118
Joined: Mon 12 Sep 2005 17:31
Location: Argentina

Using macro or param

Post by cybsistemas » Fri 23 Apr 2010 10:33

CREATE TABLE Customers (
Id smallint(5) unsigned NOT NULL AUTO_INCREMENT,
Name char(40) DEFAULT NULL,
Comision float(12,2) DEFAULT NULL,
PRIMARY KEY (Id)
) ENGINE=MyISAM AUTO_INCREMENT=91 DEFAULT CHARSET=latin1


MyQuery1.SQL.Text := 'select * from Customers where id in (:num);';
MyQuery1.ParamByName('num').AsString := '125,188,225,216';
MyQuery1.Execute;

Error in result



MyQuery1.SQL.Text := 'select * from Customers where id in (&num);';
MyQuery1.MacroByName('num').AsString := '125,188,225,216';
MyQuery1.Execute;

Error in result

As is it done?

swierzbicki
Posts: 451
Joined: Wed 19 Jan 2005 09:59

Post by swierzbicki » Fri 23 Apr 2010 14:09

That is designed as is. You can't pass a string as "list". When you are using .AsString, you are just sending a String. Delphi will replace it :

MyQuery1.SQL.Text := 'select * from Customers where id in (:num);';
MyQuery1.ParamByName('num').AsString := '125,188,225,216';

will be executed like this :
select * from Customers where id in ('125,188,225,216')
instead of
select * from Customers where id in (125,188,225,216)

Try to use macros:

MyQuery1.SQL.Text := 'select * from Customers where id in (&num);';
MyQuery1.MacroByName('num').Vaule := '125,188,225,216';

cybsistemas
Posts: 118
Joined: Mon 12 Sep 2005 17:31
Location: Argentina

Post by cybsistemas » Fri 23 Apr 2010 19:06

Thanks

Post Reply