This is my sql set of statements:
char *sql = "BEGIN TRANSACTION;
CREATE TABLE Friends(id varchar UNIQUE);
CREATE TABLE Enemies(id2 varchar ,id3 INTEGER,CONSTRAINT id_econst
FOREIGN KEY(id2) REFERENCES Friends(id) ON DELETE CASCADE);
INSERT INTO Friends VALUES('11');
INSERT INTO Friends VALUES('2');
INSERT INTO Enemies VALUES('11',3);
INSERT INTO Enemies VALUES('3',5);
END TRANSACTION;
PRAGMA foreign_keys = ON;
DELETE FROM Friends WHERE id = '11';";
Performs cascade delete on the Enemies table, whereas :
char *sql = "BEGIN TRANSACTION;
CREATE TABLE Friends(id varchar UNIQUE);
CREATE TABLE Enemies(id2 varchar ,id3 INTEGER,CONSTRAINT id_econst
FOREIGN KEY(id2) REFERENCES Friends(id) ON DELETE CASCADE);
INSERT INTO Friends VALUES('11');
INSERT INTO Friends VALUES('2');
INSERT INTO Enemies VALUES('11',3);
INSERT INTO Enemies VALUES('3',5);
PRAGMA foreign_keys = ON;
DELETE FROM Friends WHERE id = '11';
END TRANSACTION;";
does normal delete.
Why is it so ?
Aucun commentaire:
Enregistrer un commentaire