From baaa9bb106af01c0d6d5fd9cde87a27852bb8622 Mon Sep 17 00:00:00 2001 From: Masaya Tojo Date: Sun, 12 Mar 2023 17:36:46 +0900 Subject: Add function to delete item. --- verify/delete_item.sql | 37 +++++++++++++++++++++++++++++++++++++ 1 file changed, 37 insertions(+) create mode 100644 verify/delete_item.sql (limited to 'verify') diff --git a/verify/delete_item.sql b/verify/delete_item.sql new file mode 100644 index 0000000..b1c3dd7 --- /dev/null +++ b/verify/delete_item.sql @@ -0,0 +1,37 @@ +-- Verify kakeibo:delete_item on pg + +BEGIN; + +SELECT has_function_privilege('kakeibo.delete_item(INTEGER)', 'EXECUTE'); + +SET search_path = kakeibo; + +DO $$ + DECLARE + v_transaction_id INTEGER; + v_item_id INTEGER; + v_item_id_2 INTEGER; + BEGIN + SELECT insert_transaction(0, '2023-03-15', 'テスト') INTO v_transaction_id; + SELECT insert_item(v_transaction_id, 'カテ', 'サブカテ', 298, 'メモ') INTO v_item_id; + SELECT insert_item(v_transaction_id, 'カテ', 'サブカテ', 298, 'メモ') INTO v_item_id_2; + + PERFORM * FROM items WHERE id = v_item_id; + IF NOT FOUND THEN + RAISE EXCEPTION 'Inserted data is not found.'; + END IF; + + PERFORM delete_item(v_item_id); + PERFORM * FROM items WHERE id = v_item_id; + IF FOUND THEN + RAISE EXCEPTION 'Deleted data still exists.'; + END IF; + + PERFORM * FROM items WHERE id = v_item_id_2; + IF NOT FOUND THEN + RAISE EXCEPTION 'Unexpected delete data.'; + END IF; + END +$$; + +ROLLBACK; -- cgit v1.2.3