Multiple statements and parameters

Discussion of open issues, suggestions and bugs regarding PgDAC (PostgreSQL Data Access Components) for Delphi, C++Builder, Lazarus (and FPC)
Post Reply
yozey
Posts: 32
Joined: Sat 17 Jan 2009 14:41

Multiple statements and parameters

Post by yozey » Tue 29 Sep 2009 19:59

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.

Plash
Devart Team
Posts: 2844
Joined: Wed 10 May 2006 07:09

Post by Plash » Wed 30 Sep 2009 07:27

You should use an unique name for each parameter.

yozey
Posts: 32
Joined: Sat 17 Jan 2009 14:41

Post by yozey » Wed 30 Sep 2009 12:19

Plash wrote:You should use an unique name for each parameter.
Ok thank you.

Post Reply