Subject Re: [IBO] Autoincrement field with TIBODATABASE Object
Author Helen Borrie (TeamIBO)
At 03:11 PM 25-01-02 +0000, you wrote:
>I setup an autoincrement field using the IBWorkbench Wizard for a
>program that accesses the data using Interbase Objects TIBODatabase
>object- the one that is InfoPower compatible.
>In delphi I set the required-flag of the concerning field to false.
> When I run the program and hit insert, and then add data to the
>fields, except the ID field, and then use save, I get the following
>error " exception class edatabase error with message 'field'
>PatientID must have value"
>
>What am I doing wrong?
>>
>> My IBworkbench has the following code in the trigger section
>> begin
>> /* first - check for NULL for this column */
>> if (new.PATINFO_ID is null)
>> then begin
>> /* if NULL, provide a new ID for this generator */
>> new.PATINFO_ID = gen_id(PATINFO_GEN, 1);
>> end
>> end
>>
>> And the following code in the generator
>>
>> CREATE GENERATOR PATINFO_GEN;
>> SET GENERATOR PATINFO_GEN TO 0;
>>

You can fool delphi but you can't fool the database! Either use the klutzy solution of using a special InsertSQL DEM statement that doesn't include the generator column (we don't call them autoincrement in FB/IB, because they are not autoincrement type!).

The IBO way to do it is to set the GeneratorLinks property, like this:

PATINFO_ID=PATINFO_GEN

Nothing could be simpler.

Take the NotRequired attribute off the TField. Its not required. :)


regards,
Helen Borrie (TeamIBO Support)

** Please don't email your support questions privately **
Ask on the list and everyone benefits
Don't forget the IB Objects online FAQ - link from any page at www.ibobjects.com