Subject | Re: [firebird-support] Set term gives Token unknown error |
---|---|
Author | Stevio |
Post date | 2008-04-29T16:55:01Z |
> From: "Aage Johansen" <aagjohan@...>Not sure why I have a select in here, as I am not using the information
> Sure, but you're doing too much. Reduce to:
>
> > /* Create Table */
> > CREATE TABLE LETABLE (
> > LETABLE_ID INTEGER NOT NULL,
> > ...more fields...
> > PRIMARY KEY (LETABLE_ID)
> > );
> >
> > /* Primary key generator */
> > CREATE GENERATOR GEN_NEW_LETABLE_ID;
> I would usually do a commit here.
>
> Drop this select. It's out of place here (and probably elsewhere as well)
> -- SELECT GEN_ID(GEN_NEW_LETABLE_ID, (SELECT MAX (LETABLE_ID) FROM
> LETABLE))
> -- FROM RDB$DATABASE;
> If you need it, run it from the cursor window.
selected. The code was copied and adjusted from old SQL code I'd used. Maybe
this was included so I could just check things were working.
> > SET TERM ^ ;What does suspend do and why do I need it?
> > CREATE TRIGGER SET_NEW_LETABLE_ID FOR LETABLE
> > ACTIVE BEFORE INSERT POSITION 0
> > AS
> > BEGIN
> > IF (NEW.LETABLE_ID IS NULL) THEN NEW.LETABLE_ID =
> > GEN_ID(GEN_NEW_LETABLE_ID, 1);
> > END ^
> >
> > CREATE PROCEDURE PROC_NEW_LETABLE_ID
> > RETURNS (THE_NEW_LETABLE_ID INTEGER)
> > AS
> > BEGIN
> > THE_NEW_LETABLE_ID = GEN_ID(GEN_NEW_LETABLE_ID, 1);
> You will need a SUSPEND here!
> > END ^
> > SET TERM ; ^
> Do another commit.
What is the actual line of SQL code that should be added? Is it:
SUSPEND;
or
SUSPEND ^
> Maybe you won't need the procedure at all. Some component sets (likeI would use this generator within the GeneratorField of a TIBDataSet with
> IBO) have a function you can call.
> E.g. assume your connection component is cnDB:
> THEVALUE:=cnDB.Gen_ID('GEN_NEW_LETABLE_ID',1);
> (IIRC - untested)
the property value:
GEN_NEW_LETABLE_ID -> LETABLE_ID By 1
Thanks,
Stephen