mathinvalidnik
mathinvalidnik

Reputation: 1600

Executing script on Firebird error Token unknown - line 1, column 5 TERM. Error Code: -104

I am trying to write a script that creates a table, adds some constraints and then make a column auto-increment. As far as I read it happens with generator and before insert trigger.

Here is my code:

CREATE TABLE BLANKS
(
 ID INT NOT NULL PRIMARY KEY,
 BLANK_ID INT NOT NULL,
 DATABASE_ID SMALLINT NOT NULL,
 BLANK_VERSION DECIMAL,

 CONSTRAINT ROW_UNIQUENESS UNIQUE(BLANK_ID, DATABASE_ID, BLANK_VERSION)
)


    /* Autoincrement for field (ID) */
    CREATE GENERATOR GEN_BLANKS_ID;

    SET TERM ^ ;

    CREATE TRIGGER BLANKS_BI FOR BLANKS
    ACTIVE BEFORE INSERT POSITION 0
    AS
    BEGIN
      IF (NEW.ID IS NULL) THEN
      NEW.ID = GEN_ID(GEN_BLANKS_ID,1);
    END^

    SET TERM ; ^

But it just doesn't work. It creates the table and the generator but when it reaches SET TERM ^ ; the script fails with error:

SQL Error:  Dynamic SQL Error SQL error code = -104 Token unknown - line 1, column 5 TERM. Error Code: -104. can't format message 13:896 -- message file C:\Program Files (x86)\SQL Maestro Group\firebird.msg not found The SQL: SET TERM ^ ;
; 

Do you have any suggestions?

Upvotes: 2

Views: 5163

Answers (1)

Stijn Bousard
Stijn Bousard

Reputation: 401

Add a semicolon after the create table statement and remove the set term ^ syntax if your SQL client doesn't like it:

CREATE TABLE BLANKS
(
 ID INT NOT NULL PRIMARY KEY,
 BLANK_ID INT NOT NULL,
 DATABASE_ID SMALLINT NOT NULL,
 BLANK_VERSION DECIMAL,

 CONSTRAINT ROW_UNIQUENESS UNIQUE(BLANK_ID, DATABASE_ID, BLANK_VERSION)
);


    /* Autoincrement for field (ID) */
    CREATE GENERATOR GEN_BLANKS_ID;

    CREATE TRIGGER BLANKS_BI FOR BLANKS
    ACTIVE BEFORE INSERT POSITION 0
    AS
    BEGIN
      IF (NEW.ID IS NULL) THEN
      NEW.ID = GEN_ID(GEN_BLANKS_ID,1);
    END

Upvotes: 3

Related Questions