Subject | RE: [firebird-support] Arg.. Autonum generator newbie question... |
---|---|
Author | Si Carter |
Post date | 2005-03-04T13:57:43Z |
The following script works for me (tested in IBOConsole), there are a few
changes from what you posted (look at set term and NEW.ITEMNUM = GEN_ID...)
CREATE TABLE ITEMS (
ITEMNUM INTEGER NOT NULL,
CATEGORYNUM INTEGER,
PRIMARY KEY (ITEMNUM)
);
CREATE GENERATOR ITEMNUM_ID;
COMMIT;
SET TERM ## ;
CREATE TRIGGER ITEM_ID_TRIG FOR ITEMS
BEFORE INSERT POSITION 0 AS
BEGIN
NEW.ITEMNUM = GEN_ID(ITEMNUM_ID, 1);
END ##
SET TERM ; ##
COMMIT;
The error you were receiving was more than likely because the Generator had
already been created (presuming you ran this script more than once)
Hih
Si Carter
http://www.tectsoft.net/
changes from what you posted (look at set term and NEW.ITEMNUM = GEN_ID...)
CREATE TABLE ITEMS (
ITEMNUM INTEGER NOT NULL,
CATEGORYNUM INTEGER,
PRIMARY KEY (ITEMNUM)
);
CREATE GENERATOR ITEMNUM_ID;
COMMIT;
SET TERM ## ;
CREATE TRIGGER ITEM_ID_TRIG FOR ITEMS
BEFORE INSERT POSITION 0 AS
BEGIN
NEW.ITEMNUM = GEN_ID(ITEMNUM_ID, 1);
END ##
SET TERM ; ##
COMMIT;
The error you were receiving was more than likely because the Generator had
already been created (presuming you ran this script more than once)
Hih
Si Carter
http://www.tectsoft.net/
> -----Original Message-----
> From: cowmix3 [mailto:mmarch@...]
> Sent: 04 March 2005 10:51
> To: firebird-support@yahoogroups.com
> Subject: [firebird-support] Arg.. Autonum generator newbie question...
>
>
>
> I have looked at every example and I can't get things to
> work.. Here is what I have for my example:
>
> CREATE TABLE "ITEMS"
> (
> "ITEMNUM" INTEGER NOT NULL,
> "CATEGORYNUM" INTEGER,
> PRIMARY KEY ("ITEMNUM")
> );
>
>
>
>
> CREATE GENERATOR ITEMNUM_ID;
> COMMIT;
> SET TERM;
>
> CREATE TRIGGER ITEM_ID_TRIG FOR ITEMS
>
> BEFORE INSERT POSITION 0
> AS BEGIN
> ITEMS.ITEMNUM = GEN_ID(ITEMNUM_ID, 1);
> END
>
> SET TERM ;
>
> And I get something like this:
>
> ISC ERROR CODE:335544351
>
> ISC ERROR MESSAGE:
> unsuccessful metadata update
> DEFINE GENERATOR failed
> attempt to store duplicate value (visible to active transactions) in
>
> unique index "RDB$INDEX_11"
>
> Arg!
>
> Help!
>
> <march>
>
>
>
>
>
>
> Yahoo! Groups Links
>
>
>
>
>
>
>