From ebdf57d175ab2005dbc48fd6e94d74de135f47c7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bj=C3=B6rn=20Lindqvist?= Date: Thu, 25 Aug 2016 13:52:44 +0200 Subject: [PATCH] db.sqlite: fix the delete constraint for the restrict case --- basis/db/sqlite/sqlite-tests.factor | 3 ++- basis/db/sqlite/sqlite.factor | 2 +- 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/basis/db/sqlite/sqlite-tests.factor b/basis/db/sqlite/sqlite-tests.factor index 89a92621ddb..c44c6219147 100644 --- a/basis/db/sqlite/sqlite-tests.factor +++ b/basis/db/sqlite/sqlite-tests.factor @@ -15,7 +15,7 @@ ${ "SELECT RAISE(ROLLBACK, " "'delete on table \"NODE\" violates " "foreign key constraint \"fkd_TREE_NODE_NODE_ID_id\"') " - "WHERE (SELECT ID FROM NODE WHERE ID = OLD.ID) IS NOT NULL; END;" + "WHERE (SELECT NODE FROM TREE WHERE NODE = OLD.ID) IS NOT NULL; END;" } concat } [ { @@ -203,6 +203,7 @@ watch "WATCH" { watch boa insert-tuple watch new select-tuple user>> f user boa select-tuple + user new "mark" >>username delete-tuples ] with-db ] unit-test diff --git a/basis/db/sqlite/sqlite.factor b/basis/db/sqlite/sqlite.factor index 6ffe285522b..62b4bde1052 100644 --- a/basis/db/sqlite/sqlite.factor +++ b/basis/db/sqlite/sqlite.factor @@ -243,7 +243,7 @@ M: sqlite-db-connection persistent-table ( -- assoc ) BEFORE DELETE ON ${foreign-table-name} FOR EACH ROW BEGIN SELECT RAISE(ROLLBACK, 'delete on table \"${foreign-table-name}\" violates foreign key constraint \"fkd_${table-name}_${table-id}_${foreign-table-name}_${foreign-table-id}_id\"') - WHERE (SELECT ${foreign-table-id} FROM ${foreign-table-name} WHERE ${foreign-table-id} = OLD.${foreign-table-id}) IS NOT NULL; + WHERE (SELECT ${table-id} FROM ${table-name} WHERE ${table-id} = OLD.${foreign-table-id}) IS NOT NULL; END; " interpolate>string ;