In my application I have an update function that also runs scripts with an own uniConnection and uniScript component in autocommit mode. This used to work well over years, also with lots of DDL statements: procedures, triggers new tables altering existing tables and normal sql statements modifying data.
Yesterday I tested a script that creates four tables, generators, triggers and three constraints (in this order). Suddenly all statements following this block did not execute with the error message 'object abc in use' even if the statement did not access it.
I discovered that the constraints were the root cause, when I commented them out in the script, all following statements executed without errors.
I now changed this what made the whole thing work:
- I split the script into two having the first only contain the ddl statements
- I changed the order and created the constraints directly after defining the tables
- I disconnect and reconnect to the database after every script
As I can now work around that problem, I can live with it but I would like to understand, especially since pasting the scripts both into one and executing it in IBExpert does not produce an error on the same database. Any explanation would be great!
EDIT 1-aug-2016: I tested with older versions of my software, it runs well with the versions I compiled with Delphi 10 Seattle and the Unidac version that was current then. There were no change to the update code since then! This strange behaviour must have been introduced with D10.1 releases. As the update mechanism is in the software I have to omit the constraints to make it work with versions that have the bug. I am going to move the update code to a dll that will be downloaded upfront.
Here is the script (if someone wants to test it against a 1.5.6 database with D10.1 and Unidac). The last statement will not execute!
Code: Select all
create table study(id bigint not null, bez varchar(100) not null, codi varchar(10), crmuser varchar(20), crmpw varchar(66), crmvalidthru date, aktiv char(1), primary key(id));
create table studoc(id bigint not null, studyid bigint not null, bez varchar(50), primary key(id));
create table stutyp(id bigint not null, lbltxt varchar(100) not null, lfd integer, primary key(id));
create table studat(id bigint not null, studyid bigint not null, stutypid bigint not null, avalue varchar(1024), primary key(id));
grant all on study to anwend;
grant all on studoc to anwend;
grant all on studat to anwend;
grant all on stutyp to anwend;
create generator gen_studyid;
create generator gen_studocid;
create generator gen_stutypid;
create generator gen_studatid;
alter table studat add constraint fkstudat1 foreign key (stutypid) references stutyp(id);
alter table studat add constraint fkstudat2 foreign key (studyid) references study(id);
alter table studoc add constraint fkstudoc1 foreign key (studyid) references study(id);
SET TERM ^ ;
CREATE OR ALTER TRIGGER STUDY_BI0 FOR STUDY
ACTIVE BEFORE INSERT POSITION 0
AS
begin
if (new.id is null) then begin
new.id = gen_id(gen_STUDYID,1);
end
end
^
CREATE OR ALTER TRIGGER STUDOC_BI0 FOR STUDOC
ACTIVE BEFORE INSERT POSITION 0
AS
begin
if (new.id is null) then begin
new.id = gen_id(gen_STUDOCID,1);
end
end
^
CREATE OR ALTER TRIGGER STUTYP_BI0 FOR STUTYP
ACTIVE BEFORE INSERT POSITION 0
AS
begin
if (new.id is null) then begin
new.id = gen_id(gen_STUTYPID,1);
end
end
^
CREATE OR ALTER TRIGGER STUDAT_BI0 FOR STUDAT
ACTIVE BEFORE INSERT POSITION 0
AS
begin
if (new.id is null) then begin
new.id = gen_id(gen_STUDATID,1);
end
end
^
SET TERM ; ^
UPDATE INI SET AVAL='497' WHERE AKEY='SCHEMAVER';