Subject | Re: Interbase Transactions |
---|---|
Author | Geno |
Post date | 2000-12-15T00:30:59Z |
Helen:
I have a trigger. The AUTOINC field works fine. Here is the problem:
I have a table - table1. It has a autoinc field - keyfield. On the
form I add a dbedit box linked to keyfield - dbedit1. I have a
dbnavigator linked to table1. I have a button. In a button I have
this code.
table1.append;
table1.post;
There is 1 record in table1 with a keyfield of 1.
When I run the form, dbedit1 displays 1. When the button is pressed
it should, and does add a new record with the next sequential key
number. However, dbedit1 now shows 0. If I check the value of
keyfield it is 0. The dbnavigator allows me to move through 2
records. The first has a keyfield of 1, the 2nd 0.
If I close the form and run it again I now have 2 records with
keyfields of 1 and 2, as it should be.
If I put the code in a loop and add 1000 records, all is fine. All
1000 records are there with sequential keyfield numbers. However,
until the form is closed, they all show up as 0.
The problem, I assume, is the default transaction. I assume that
since the table1.post is not commited until I end the transaction,
which happens when I close the form, the new record is not actually
posted.
This is a problem since after posting the record, I use the keyfield
to add support records in other tables linked master/detail. This
fails because until the main table is closed the keyfield is always 0.
I tried starting another adding IBTransaction1.CommitRetaining after
the post but that does not resolve the problem. I tried starting
another transactions, since I understand I can have more that one,
but I get an error "transaction already active".
Can you assist?
Thanks.
I have a trigger. The AUTOINC field works fine. Here is the problem:
I have a table - table1. It has a autoinc field - keyfield. On the
form I add a dbedit box linked to keyfield - dbedit1. I have a
dbnavigator linked to table1. I have a button. In a button I have
this code.
table1.append;
table1.post;
There is 1 record in table1 with a keyfield of 1.
When I run the form, dbedit1 displays 1. When the button is pressed
it should, and does add a new record with the next sequential key
number. However, dbedit1 now shows 0. If I check the value of
keyfield it is 0. The dbnavigator allows me to move through 2
records. The first has a keyfield of 1, the 2nd 0.
If I close the form and run it again I now have 2 records with
keyfields of 1 and 2, as it should be.
If I put the code in a loop and add 1000 records, all is fine. All
1000 records are there with sequential keyfield numbers. However,
until the form is closed, they all show up as 0.
The problem, I assume, is the default transaction. I assume that
since the table1.post is not commited until I end the transaction,
which happens when I close the form, the new record is not actually
posted.
This is a problem since after posting the record, I use the keyfield
to add support records in other tables linked master/detail. This
fails because until the main table is closed the keyfield is always 0.
I tried starting another adding IBTransaction1.CommitRetaining after
the post but that does not resolve the problem. I tried starting
another transactions, since I understand I can have more that one,
but I get an error "transaction already active".
Can you assist?
Thanks.
--- In ib-support@egroups.com, Helen Borrie <helebor@w...> wrote:
> At 08:38 PM 14-12-00 +0000, you wrote:
> >Hello:
> >Having a bit of a problem with IB6 transactions. Using Delphi 5.
> >Have an application I am converting from D5/Paradox to D5/IB6.
> >Table has AUTOINC field for its key. When user posts new record,
new
> >key is generated with AUTOINC field. I then use this key to add
> >records in other tables that are connected to this table
> >Master/Deatil. This works fine in Paradox. Set up IB6 table and
> >created AUTOINC field with generator and trigger. This works fine,
> >everytime I call table.post, new record with incrementing key is
> >added. However, when new records are added the AUTOINC field is
not
> >visible until I close the table. Therefore, key field is 0 so I
> >can't add records to other tables. Assume this has something to do
> >with transactions. Have tried CommitRetaing when I post but this
> >does not help. If I call table.refresh, this works but resets
table
> >to 1st record. Can someone tell me what I need to do.
>
> You need to add a trigger to the table to fire the generator,
because
> generators are not hooked up to the columns they populate.
>
> Here is an example:
> SET TERM ^ ;
> CREATE TRIGGER BI_NEW_KEY FOR ATABLE
> ACTIVE BEFORE INSERT POSITION 0 AS
> BEGIN
> IF ((NEW.IDFIELD IS NULL) OR (NEW.IDFIELD=0)) THEN
> NEW.IDFIELD = GEN_ID(THEGENERATOR, 1);
> END ^
> SET TERM; ^
>
> Helen
>
>
> >Thanks Geno
> >
> >
> >
> >
> >To unsubscribe from this group, send an email to:
> >ib-support-unsubscribe@egroups.com
> >
>
> All for Open and Open for All
> InterBase Developer Initiative ยท http://www.interbase2000.org
> _______________________________________________________