Page 1 of 1

Multiple statements and parameters

Posted: Tue 29 Sep 2009 19:59
by yozey
Just a quick question on what is the best way to achieve the following:
I wish to populate a query with a few sql statements (with parameters) before actually executing them. Is there a way to have each statement with parameters compiled when I add them or do I have to assign unique parameters for each statement?

For example

Code: Select all

Query.SQL.Add('INSERT INTO table VALUES(:id, :name);');
Query.Params[0].AsInteger := 1;
Query.Params[1].AsString := 'First';
// compile here
Query.SQL.Add('INSERT INTO table VALUES(:id, :name);');
Query.Params[0].AsInteger := 2;
Query.Params[1].AsString := 'Second';
// compile here
Query.Execute;
And that will execute those statements compiled with their parameters.

Thanks.

Posted: Wed 30 Sep 2009 07:27
by Plash
You should use an unique name for each parameter.

Posted: Wed 30 Sep 2009 12:19
by yozey
Plash wrote:You should use an unique name for each parameter.
Ok thank you.