KeyGen

Discussion of open issues, suggestions and bugs regarding IBDAC (InterBase Data Access Components) for Delphi, C++Builder, Lazarus (and FPC)
Post Reply
rcmz
Posts: 15
Joined: Wed 12 Mar 2008 05:58

KeyGen

Post by rcmz » Wed 12 Mar 2008 06:02

I need some samples on using KeyGen with TIBCQuery built in runtime

Where can I get this Info.

TIA
rcmz

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

Post by Plash » Fri 14 Mar 2008 15:33

Please see the following example:

Code: Select all

  IBCQuery1.SQL.Text := 'select * from emp';
  IBCQuery1.KeyFields := 'empno';
  IBCQuery1.KeyGenerator := 'emp_id';
  IBCQuery1.Open;
 
  IBCQuery1.Insert;
  IBCQuery1.FieldByName('ENAME').AsString := 'AAA';
  IBCQuery1.Post;

rcmz
Posts: 15
Joined: Wed 12 Mar 2008 05:58

Post by rcmz » Fri 14 Mar 2008 15:53

Thanx for your response

But if I use

ibcquery.sql.text := 'INSERT CLIENTS (NAME)'+
'VALUES ('AAA')';
ibcquery.execute;

the id gets a null value but the record gets inserted.

the problem is with the id

TIA
Ramiro[/code]

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

Post by Plash » Fri 14 Mar 2008 16:18

KeyGenerator property can be used only when you open a SELECT statement, and insert records to this dataset.

If you execute INSERT statement, you should use the generator in this statement:

Code: Select all

INSERT INTO CLIENTS (ID, NAME)
VALUES (NEXT VALUE FOR my_gen, 'AAA')

Post Reply