Page 1 of 1

in-list parameter as array (etc)

Posted: Thu 09 Jan 2020 06:08
by mWaltari
I've been thinking that something like this would make code way easier.

SELECT *
FROM TABLEA
WHERE
ID IN (:INPARAMETER)

could use it like

LQueryTableA.ParamByName('INPARAMETER').InParameter([1, 2, 3, 4, 5]);

(not .AsInArray etc because can't overload because values can come from different data types)

It should have few overloads depending where data is coming From. TStrings, TArray<T>, TList<T> at least.

Should take care of quotes and so. This would make code side way simpler and no need for own code to handle all this. Not sure which databases support this natively somehow, if not, could just modify SQL I think.

-Tee-

Re: in-list parameter as array (etc)

Posted: Fri 10 Jan 2020 08:49
by ViktorV
To solve your task, you can use Macros. For example:
var
InConditione: string;
...
IBCQuery.SQL.Text := 'select * from tablea where ID in (&InCondition)';
InCondition := '1, 2, 3';
IBCQuery.MacroByName('InCondition').AsString := InCondition;
IBCQuery.Open;
You can learn more about Macros at: http://www.devart.com/ibdac/docs/work_macros.htm