Subject Re: [firebird-support] Set term gives Token unknown error
Author Aage Johansen
Stevio wrote:
> Ah ok I was trying to run it in the DSQL window. (I told you I haven't used
> this stuff in quite a while lol!)
> Why does SET TERM ^ ; not work in the DSQL window in IB_SQL, and it also
> does not work in Database Explorer (from the Enter SQL window),
but it works
> from within IB_SQL when you select Execute Script from the Connection tab?

The DSQL window expects just one statement, the script window will
accept a sequence of statements (or just one).

>
> What I am trying to do is to create a new table and create a primary key
> generator stored procedure. Standard stuff I think?

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.

>
> SET TERM ^ ;
> 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.

Maybe you won't need the procedure at all. Some component sets (like
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)


--
Aage J.