Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Cascade deletion in self-referencing table could raise "no current record for fetch operation" error [CORE5322] #5598

Closed
firebird-issue-importer opened this issue Aug 1, 2016 · 8 comments

Comments

@firebird-issue-importer
Copy link

firebird-issue-importer commented Aug 1, 2016

Submitted by: Koltcov Viktor (koltcov)

Votes: 1

Can't delete record with cascade foreign key, but it worked in firebird 2.5.2

when try to delete
DELETE FROM TABLE_A WHERE (ID = 1)

get error
The cursor identified in the UPDATE or DELETE statement is not positioned on a row.
no current record for fetch operation.
At trigger 'CHECK_1'.

test DDL:

/******************************************************************************/
/*** Generated by IBExpert 2016.6.22.1 01.08.2016 9:58:18 ***/
/******************************************************************************/

SET SQL DIALECT 3;

SET NAMES WIN1251;

CREATE DATABASE 'TEST.FDB '
USER 'SYSDBA' PASSWORD 'masterkey'
PAGE_SIZE 16384
DEFAULT CHARACTER SET WIN1251 COLLATION WIN1251;

/******************************************************************************/
/*** Tables ***/
/******************************************************************************/

CREATE TABLE "TABLE_A" (
"ID" INTEGER NOT NULL,
"SOME_DATA" INTEGER
);

CREATE TABLE "TABLE_B" (
"ID" INTEGER NOT NULL,
"TABLE_A_ID" INTEGER,
"SOME_DATA" INTEGER,
"PARENT_ID" INTEGER
);

INSERT INTO "TABLE_A" ("ID", "SOME_DATA") VALUES (1, 10);

COMMIT WORK;

INSERT INTO "TABLE_B" ("ID", "TABLE_A_ID", "SOME_DATA", "PARENT_ID") VALUES (1, 1, 555, NULL);
INSERT INTO "TABLE_B" ("ID", "TABLE_A_ID", "SOME_DATA", "PARENT_ID") VALUES (2, 1, 222, 1);

COMMIT WORK;

/******************************************************************************/
/*** Primary keys ***/
/******************************************************************************/

ALTER TABLE "TABLE_A" ADD CONSTRAINT "PK_TABLE_A" PRIMARY KEY ("ID");
ALTER TABLE "TABLE_B" ADD CONSTRAINT "PK_TABLE_B" PRIMARY KEY ("ID");

/******************************************************************************/
/*** Foreign keys ***/
/******************************************************************************/

ALTER TABLE "TABLE_B" ADD CONSTRAINT "FK_TABLE_B_1" FOREIGN KEY ("TABLE_A_ID") REFERENCES "TABLE_A" ("ID") ON DELETE CASCADE;
ALTER TABLE "TABLE_B" ADD CONSTRAINT "FK_TABLE_B_2" FOREIGN KEY ("PARENT_ID") REFERENCES "TABLE_B" ("ID") ON DELETE CASCADE;

Commits: d5ec668 6a3d9d0

@firebird-issue-importer
Copy link
Author

firebird-issue-importer commented Aug 1, 2016

Modified by: Koltcov Viktor (koltcov)

description: Can't delete record with cascade foreign key, but it worked in firebird 2.5.2

when try to delete
DELETE FROM TABLE_A WHERE (ID = 1)

get error
The cursor identified in the UPDATE or DELETE statement is not positioned on a row.
no current record for fetch operation.
At trigger 'CHECK_1'.

test DDL:

/******************************************************************************/
/*** Generated by IBExpert 2016.6.22.1 01.08.2016 9:58:18 ***/
/******************************************************************************/

SET SQL DIALECT 3;

SET NAMES WIN1251;

CREATE DATABASE 'TEST.FDB '
USER 'SYSDBA' PASSWORD 'masterkey'
PAGE_SIZE 16384
DEFAULT CHARACTER SET WIN1251 COLLATION WIN1251;

/******************************************************************************/
/*** Tables ***/
/******************************************************************************/

CREATE TABLE "TABLE_A" (
"ID" INTEGER NOT NULL,
"SOME_DATA" INTEGER
);

CREATE TABLE "TABLE_B" (
"ID" INTEGER NOT NULL,
"TABLE_A_ID" INTEGER,
"SOME_DATA" SMALLINT,
"PARENT_ID" SMALLINT
);

INSERT INTO "TABLE_A" ("ID", "SOME_DATA") VALUES (1, 10);

COMMIT WORK;

INSERT INTO "TABLE_B" ("ID", "TABLE_A_ID", "SOME_DATA", "PARENT_ID") VALUES (1, 1, 555, NULL);
INSERT INTO "TABLE_B" ("ID", "TABLE_A_ID", "SOME_DATA", "PARENT_ID") VALUES (2, 1, 222, 1);

COMMIT WORK;

/******************************************************************************/
/*** Primary keys ***/
/******************************************************************************/

ALTER TABLE "TABLE_A" ADD CONSTRAINT "PK_TABLE_A" PRIMARY KEY ("ID");
ALTER TABLE "TABLE_B" ADD CONSTRAINT "PK_TABLE_B" PRIMARY KEY ("ID");

/******************************************************************************/
/*** Foreign keys ***/
/******************************************************************************/

ALTER TABLE "TABLE_B" ADD CONSTRAINT "FK_TABLE_B_1" FOREIGN KEY ("TABLE_A_ID") REFERENCES "TABLE_A" ("ID") ON DELETE CASCADE;
ALTER TABLE "TABLE_B" ADD CONSTRAINT "FK_TABLE_B_2" FOREIGN KEY ("PARENT_ID") REFERENCES "TABLE_B" ("ID") ON DELETE CASCADE;

=>

Can't delete record with cascade foreign key, but it worked in firebird 2.5.2

when try to delete
DELETE FROM TABLE_A WHERE (ID = 1)

get error
The cursor identified in the UPDATE or DELETE statement is not positioned on a row.
no current record for fetch operation.
At trigger 'CHECK_1'.

test DDL:

/******************************************************************************/
/*** Generated by IBExpert 2016.6.22.1 01.08.2016 9:58:18 ***/
/******************************************************************************/

SET SQL DIALECT 3;

SET NAMES WIN1251;

CREATE DATABASE 'TEST.FDB '
USER 'SYSDBA' PASSWORD 'masterkey'
PAGE_SIZE 16384
DEFAULT CHARACTER SET WIN1251 COLLATION WIN1251;

/******************************************************************************/
/*** Tables ***/
/******************************************************************************/

CREATE TABLE "TABLE_A" (
"ID" INTEGER NOT NULL,
"SOME_DATA" INTEGER
);

CREATE TABLE "TABLE_B" (
"ID" INTEGER NOT NULL,
"TABLE_A_ID" INTEGER,
"SOME_DATA" INTEGER,
"PARENT_ID" INTEGER
);

INSERT INTO "TABLE_A" ("ID", "SOME_DATA") VALUES (1, 10);

COMMIT WORK;

INSERT INTO "TABLE_B" ("ID", "TABLE_A_ID", "SOME_DATA", "PARENT_ID") VALUES (1, 1, 555, NULL);
INSERT INTO "TABLE_B" ("ID", "TABLE_A_ID", "SOME_DATA", "PARENT_ID") VALUES (2, 1, 222, 1);

COMMIT WORK;

/******************************************************************************/
/*** Primary keys ***/
/******************************************************************************/

ALTER TABLE "TABLE_A" ADD CONSTRAINT "PK_TABLE_A" PRIMARY KEY ("ID");
ALTER TABLE "TABLE_B" ADD CONSTRAINT "PK_TABLE_B" PRIMARY KEY ("ID");

/******************************************************************************/
/*** Foreign keys ***/
/******************************************************************************/

ALTER TABLE "TABLE_B" ADD CONSTRAINT "FK_TABLE_B_1" FOREIGN KEY ("TABLE_A_ID") REFERENCES "TABLE_A" ("ID") ON DELETE CASCADE;
ALTER TABLE "TABLE_B" ADD CONSTRAINT "FK_TABLE_B_2" FOREIGN KEY ("PARENT_ID") REFERENCES "TABLE_B" ("ID") ON DELETE CASCADE;

@firebird-issue-importer
Copy link
Author

firebird-issue-importer commented Aug 1, 2016

Commented by: @dyemanov

Could be related to CORE5305.

@firebird-issue-importer
Copy link
Author

firebird-issue-importer commented Aug 2, 2016

Commented by: @hvlad

It is about self-referenced FK, i believe

@firebird-issue-importer
Copy link
Author

firebird-issue-importer commented Sep 7, 2016

Modified by: @hvlad

assignee: Vlad Khorsun [ hvlad ]

@firebird-issue-importer
Copy link
Author

firebird-issue-importer commented Sep 7, 2016

Modified by: @hvlad

Fix Version: 3.0.1 [ 10730 ]

Fix Version: 4.0 Alpha 1 [ 10731 ]

summary: do not work cascade deleting => Cascade deletion in self-referencing table could raise "no current record for fetch operation" error

@firebird-issue-importer
Copy link
Author

firebird-issue-importer commented Sep 8, 2016

Modified by: @hvlad

status: Open [ 1 ] => Resolved [ 5 ]

resolution: Fixed [ 1 ]

@firebird-issue-importer
Copy link
Author

firebird-issue-importer commented Sep 9, 2016

Modified by: @pavel-zotov

status: Resolved [ 5 ] => Resolved [ 5 ]

QA Status: No test => Done successfully

@firebird-issue-importer
Copy link
Author

firebird-issue-importer commented Sep 9, 2016

Modified by: @pavel-zotov

status: Resolved [ 5 ] => Closed [ 6 ]

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants