violation of PRIMARY or UNIQUE KEY constraint "UNQ1" on table "Table1"

Discussion of open issues, suggestions and bugs regarding IBDAC (InterBase Data Access Components) for Delphi, C++Builder, Lazarus (and FPC)
Post Reply
inageib
Posts: 184
Joined: Wed 26 Aug 2009 14:11

violation of PRIMARY or UNIQUE KEY constraint "UNQ1" on table "Table1"

Post by inageib » Wed 08 Jan 2014 22:23

Hello,
I get this error when I try to insert new record although I can do the same without errors inside my admin tool.
violation of PRIMARY or UNIQUE KEY constraint "UNQ1" on table "Table1"
here is the SQL

Code: Select all

CREATE TABLE Table1 (
    MN_ID               INTEGER NOT NULL,
    POS                SMALLINT NOT NULL

);

ALTER TABLE Table1 ADD CONSTRAINT UNQ1 UNIQUE (MN_ID, POS);

/* Trigger */
CREATE OR ALTER TRIGGER Table1_BI0 FOR Table1
ACTIVE BEFORE INSERT POSITION 0
AS
begin
  select max(POS)+1 from table1 where Table1.MN_id = new.mn_id into new.pos;
end

I enter the "MN_ID" value but for "POS" I leave the trigger "Table1_BI0" to do that. The Insert is working inside my admin tool but in my app I get the above error, please advise

Thanks

inageib
Posts: 184
Joined: Wed 26 Aug 2009 14:11

Re: violation of PRIMARY or UNIQUE KEY constraint "UNQ1" on table "Table1"

Post by inageib » Fri 10 Jan 2014 16:43

any response ?

ZEuS
Devart Team
Posts: 240
Joined: Thu 05 Apr 2012 07:32

Re: violation of PRIMARY or UNIQUE KEY constraint "UNQ1" on table "Table1"

Post by ZEuS » Sat 11 Jan 2014 07:36

Unfortunately, we can not reproduce the "violation of PRIMARY or UNIQUE KEY constraint" error you have reported.
Please create a small sample that demonstrates the problem, and send it to eugeniyz*devart*com.

inageib
Posts: 184
Joined: Wed 26 Aug 2009 14:11

Re: violation of PRIMARY or UNIQUE KEY constraint "UNQ1" on table "Table1"

Post by inageib » Sat 11 Jan 2014 16:27

This is very strange, I tried again and it work without error. What can cause that behavior !!?

ZEuS
Devart Team
Posts: 240
Joined: Thu 05 Apr 2012 07:32

Re: violation of PRIMARY or UNIQUE KEY constraint "UNQ1" on table "Table1"

Post by ZEuS » Tue 14 Jan 2014 09:23

We can not give a definite answer to such a general question. The problem may be caused by different reasons, and is specific to the code. If you can reproduce the problem and provide us with a test project - we will try to help.

Post Reply