Subject | Re: Why Firebird AutoIncrement not trigger? |
---|---|
Author | smching2001 |
Post date | 2003-05-10T03:41:44Z |
If using IBQuery, I will not able to insert data through DBGrid.
--- In ib-support@yahoogroups.com, Paul Vinkenoog <paul@v...> wrote:
> Hello,
>
> > I'm using Borland 6 & Firebird 1.0 and created a table with three
> > fields:
> >
> > DEPARTMENTID : INTERGER NOT NULL <== P.KEY
> > DEPARTMENTCODE : VACHAR(8)
> > DEPARTMENTNAME : VACHAR(40)
> >
> > Where the column special of DEPARTMENTID is set to Create
> > AutoIncrement Trigger & Generator as follow:
> >
> > begin
> > if (new.DEPARTMENTID is null)
> > then new.DEPARTMENTID = gen_id(DEPARTMENT_GEN, 1);
> > end
> >
> > The problem is when I insert data using the DBgrid, it always
> > prompted me to enter the Value of DEPARTMENTID.
> > If I don't enter the value for DEPARTMENTID, error occured.
> > Until I enter an unique value then I can continue. Why?
>
> That's because the Borland components don't know about your trigger
> and the generator. But they do know (I suppose) that DEPARTMENTID is
> PK, so it has to be filled.
>
> Although I haven't used the Borland Interbase components in a long
> time, I think two of your options are:
>
> - use an IBQuery instead of an IBTable. Leave DEPARTMENTID out of
the
> query. Your trigger will take care of the PK.
>
> - use IBTAble (or IBQuery) with DEPARTMENTID. Edit the FieldDefs of
> the Table or Query and set faRequired false for field
DEPARTMENTID.
>
> Hope this helps.
>
> Greetings,
> Paul Vinkenoog