From 6107088537258071b4499b133138d73fb4df073c Mon Sep 17 00:00:00 2001 From: Karl Levik Date: Wed, 16 Aug 2023 10:11:14 +0100 Subject: [PATCH] New stored procedure to update the barcode of a registered container (#205) --- .../sp_update_reg_container_barcode.sql | 24 +++++++++++++++++++ 1 file changed, 24 insertions(+) create mode 100644 schemas/ispyb/stored_programs/sp_update_reg_container_barcode.sql diff --git a/schemas/ispyb/stored_programs/sp_update_reg_container_barcode.sql b/schemas/ispyb/stored_programs/sp_update_reg_container_barcode.sql new file mode 100644 index 00000000..4462e6aa --- /dev/null +++ b/schemas/ispyb/stored_programs/sp_update_reg_container_barcode.sql @@ -0,0 +1,24 @@ +-- Test call: +-- CALL update_reg_container_barcode('DLS123', 'DLS456'); + +DELIMITER ;; +CREATE OR REPLACE DEFINER=`ispyb_root`@`%` PROCEDURE `update_reg_container_barcode`(IN p_oldBarcode varchar(20), IN p_newBarcode varchar(20)) +MODIFIES SQL DATA +COMMENT 'For Registered Container with barcode==p_oldBarcode: Sets barcode=p_newBarcode' +BEGIN + DECLARE row_containerRegistryId int(11) unsigned DEFAULT NULL; + + IF NOT (p_oldBarcode IS NULL) AND NOT (p_newBarcode IS NULL) THEN + START TRANSACTION; + SELECT containerRegistryId INTO row_containerRegistryId FROM ContainerRegistry WHERE barcode = p_oldBarcode FOR UPDATE; + IF NOT (row_containerRegistryId IS NULL) THEN + UPDATE ContainerRegistry SET barcode = p_newBarcode WHERE containerRegistryId = row_containerRegistryId; + ELSE + SIGNAL SQLSTATE '02000' SET MYSQL_ERRNO=1643, MESSAGE_TEXT='Barcode given by p_oldBarcode not found'; + END IF; + COMMIT; + ELSE + SIGNAL SQLSTATE '45000' SET MYSQL_ERRNO=1644, MESSAGE_TEXT='Mandatory argument(s) p_oldBarcode and/or p_newBarcode are NULL'; + END IF; +END ;; +DELIMITER ;