Subject Re: [IBO] TIBOTable and TIBOQuery problem
Author Helen Borrie
Hello Hans,

At 06:14 PM 29/01/2005 -0700, you wrote:

>Hello Jason,
>
>TIBOTable and TIBOQuery problem.
>
> AppendRecord doesn't honor or insert according to specified GeneratorLinks
>
> Table 'IHist' has only one primary key
>
>with frmCompanyDatabase.IHist do
> begin
> SessionName := 'mySession';
> DatabaseName := 'myDatabase';
> TableName := 'IHist';
> GeneratorLinks.Clear;
> GeneratorLinks.Add('IHistID=IHist_IHistID');
>
> open;
> append;
> post;
> append;
> post;
> append;
> post;
>
>/* Three records get appended correctly with auto generator link values
>for field 'IHistID' */
>
> AppendRecord([nil, 1, 1, LastMonthYear, LastMonth, 1,
> EncodeDate(LastMonthYear, LastMonth, 1), 500, Null, 'Physical Count',
> Null, 1, Null]);
>
>/* However the AppendRecord raises exception
>
> violation of PRIMARY or UNIQUE KEY constraint "INTEG_88" on table
> "IHIST" */
>
> end;

GeneratorLinks get triggered by a call to Insert(). IBO translates a call
to Append() into Insert().

AppendRecord is a TDataset method that is appropriate to databases that
insert records by physically appending them to a file (like Paradox,
Access, MySQL, dBase, etc.). Firebird and InterBase never append records,
since they have no implicit physical order in storage.

You can call AppendRecord() but, f you must, then pass the actual value for
the generated key, not "nil". That is, use the GEN_ID() function of the
TIB_Connection, via the dataset's IB_Connection property, as follows:

AppendRecord([IB_Connection.Gen_ID(IHist_IHistID,1), 1, 1, LastMonthYear,
LastMonth, 1, EncodeDate(LastMonthYear, LastMonth, 1), 500, Null, 'Physical
Count', Null, 1, Null]);

Helen