Subject | Creating Unique Index with trigger |
---|---|
Author | Gerhardus Geldenhuis |
Post date | 2001-09-25T10:12:11Z |
Hi
I have written a trigger that generates a unique index I just want to know
if there
is a better way to do it and how do i fool my program in ignoring the
primary key attributes without using ibo.
I have set the field QISKEY required property to false but I still get a
exeception when
adding a record.
Would it be better to add a new record via stored procedure. Either way the
dataset will
need to be refreshed after adding a record.
here is my trigger code
DECLARE VARIABLE Number Integer;
declare variable ss varchar(7);
BEGIN
if (New.QISTYPE=1) then
begin
Number=gen_id(GEN_QIS_Q, 1);
ss=cast(number as char);
new.QISKEY='Q'||ss;
end
if (New.QISTYPE=2) then
begin
Number=gen_id(GEN_QIS_I, 1);
ss=cast(number as char);
new.QISKEY='I'||ss;
end
if (New.QISTYPE=3) then
begin
Number=gen_id(GEN_QIS_S, 1);
ss=cast(number as char);
new.QISKEY='S'||ss;
end
END
here is the table code
CREATE TABLE QIS2
(
QISKEY VARCHAR(8) NOT NULL,
QISTYPE SMALLINT NOT NULL,
CREATETIMESTAMP TIMESTAMP DEFAULT CURRENT_TIMESTAMP,
PAYED DOM_BOOLEAN COLLATE NONE
);
I have written a trigger that generates a unique index I just want to know
if there
is a better way to do it and how do i fool my program in ignoring the
primary key attributes without using ibo.
I have set the field QISKEY required property to false but I still get a
exeception when
adding a record.
Would it be better to add a new record via stored procedure. Either way the
dataset will
need to be refreshed after adding a record.
here is my trigger code
DECLARE VARIABLE Number Integer;
declare variable ss varchar(7);
BEGIN
if (New.QISTYPE=1) then
begin
Number=gen_id(GEN_QIS_Q, 1);
ss=cast(number as char);
new.QISKEY='Q'||ss;
end
if (New.QISTYPE=2) then
begin
Number=gen_id(GEN_QIS_I, 1);
ss=cast(number as char);
new.QISKEY='I'||ss;
end
if (New.QISTYPE=3) then
begin
Number=gen_id(GEN_QIS_S, 1);
ss=cast(number as char);
new.QISKEY='S'||ss;
end
END
here is the table code
CREATE TABLE QIS2
(
QISKEY VARCHAR(8) NOT NULL,
QISTYPE SMALLINT NOT NULL,
CREATETIMESTAMP TIMESTAMP DEFAULT CURRENT_TIMESTAMP,
PAYED DOM_BOOLEAN COLLATE NONE
);