Page 1 of 1

Repeated parameters in MSQuery

Posted: Mon 03 Nov 2014 21:00
by danilo.abranches
Hi,

I am having the following problem to set some parameters in a MSQuery. When own parameters that are repeated in the query and dynamically create (CreateParam or ParseSQL), the second value is NULL when seen in Profiler.

Example:

Code: Select all

MSQueryPl1.ParamCheck := False;
MSQueryPl1.SQL.Text := 'select * from table where field = :field and '''' <> :field';
MSQueryPl1.Params.ParseSQL(MSQueryPl1.SQL.Text, True);
MSQueryPl1.ParamByName('field', 'value', ftString);
The query is generated with the last parameter NULL. If i make a loop and set the two parameters, it works.

This way it works:

Code: Select all

MSQueryPl1.ParamCheck := True;
MSQueryPl1.SQL.Text := 'select * from table where field = :field and '''' <> :field';
MSQueryPl1.ParamByName('field', 'value', ftString);
Does anyone know why this happens?

Re: Repeated parameters in MSQuery

Posted: Tue 04 Nov 2014 09:18
by paweld

Re: Repeated parameters in MSQuery

Posted: Tue 04 Nov 2014 10:12
by AlexP
If you are using Lazarus, then when using similar parameter names you should set a value for each parameter entry. This is due to implementation when working with parameters in Lazarus. In Delphi, the value is set for both parameters.

Re: Repeated parameters in MSQuery

Posted: Tue 04 Nov 2014 12:39
by danilo.abranches
Thank you.

Re: Repeated parameters in MSQuery

Posted: Wed 05 Nov 2014 05:55
by AlexP
If you have any further questions, feel free to contact us.