Skip to content

Commit

Permalink
Modify sproc upsert_session_for_proposal_code_number: rm removed cols
Browse files Browse the repository at this point in the history
  • Loading branch information
KarlLevik committed Jan 9, 2024
1 parent c78fa6e commit 34b9c44
Showing 1 changed file with 9 additions and 9 deletions.
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
-- To test:
-- SET @id := NULL;
-- CALL upsert_session_for_proposal_code_number(@id, 'cm', 14451, 1, NULL, '2024-01-09 09:00:00', '2024-01-09 17:00:00', 'i04', 'Karl', NULL, NULL, NULL, 'Karl was here', NULL);

DELIMITER ;;
CREATE OR REPLACE DEFINER=`ispyb_root`@`%` PROCEDURE `upsert_session_for_proposal_code_number`(
INOUT p_id int(11) unsigned,
Expand All @@ -8,30 +12,28 @@ CREATE OR REPLACE DEFINER=`ispyb_root`@`%` PROCEDURE `upsert_session_for_proposa
p_startDate datetime,
p_endDate datetime,
p_beamlineName varchar(45),
p_title varchar(255),
p_beamlineOperator varchar(45),
p_nbShifts int(10) unsigned,
p_scheduled tinyint(1),
p_usedFlag tinyint(1),
p_comments varchar(255),
p_externalPkId int(11) unsigned,
p_externalPkUUID varchar(32)
)
MODIFIES SQL DATA
COMMENT 'Inserts or updates a session for a proposal with given code and number.\nMandatory columns: p_id OR (p_proposalCode and p_proposalNumber)\nReturns: Record ID in p_id.'
BEGIN
DECLARE row_proposal_id int(10) unsigned DEFAULT NULL;
DECLARE row_session_id int(10) unsigned DEFAULT NULL;

IF p_id IS NOT NULL OR (p_proposalCode IS NOT NULL AND p_proposalNumber IS NOT NULL) THEN

IF p_proposalCode IS NOT NULL AND p_proposalNumber IS NOT NULL THEN
SELECT min(proposalId) INTO row_proposal_id FROM Proposal WHERE proposalCode=p_proposalCode AND proposalNumber=p_proposalNumber;
IF row_proposal_id IS NULL THEN
SIGNAL SQLSTATE '45000' SET MYSQL_ERRNO=1644, MESSAGE_TEXT='Proposal given by p_proposalCode + p_proposalNumber does not exist.';
END IF;
END IF;

IF p_id IS NULL AND row_proposal_id IS NOT NULL THEN
SELECT sessionId INTO row_session_id FROM BLSession WHERE proposalId = row_proposal_id AND visit_number = p_visitNumber;
ELSEIF p_id IS NOT NULL THEN
Expand All @@ -40,9 +42,9 @@ BEGIN

IF row_session_id IS NULL THEN
INSERT INTO BLSession(sessionId, proposalId, visit_number, beamLineSetupId, startDate, endDate,
beamLineName, sessionTitle, beamLineOperator, nbShifts, scheduled, usedFlag, comments, expSessionPk, externalId)
beamLineName, beamLineOperator, nbShifts, scheduled, usedFlag, comments, externalId)
VALUES (p_id, row_proposal_id, p_visitNumber, p_beamLineSetupId, p_startDate, p_endDate,
p_beamlineName, p_title, p_beamlineOperator, p_nbShifts, p_scheduled, p_usedFlag, p_comments, p_externalPkId, unhex(p_externalPkUUID));
p_beamlineName, p_beamlineOperator, p_nbShifts, p_scheduled, p_usedFlag, p_comments, unhex(p_externalPkUUID));
SET p_id = LAST_INSERT_ID();

ELSE
Expand All @@ -55,13 +57,11 @@ BEGIN
startDate = IFNULL(p_startDate, startDate),
endDate = IFNULL(p_endDate, endDate),
beamLineName = IFNULL(p_beamlineName, beamLineName),
sessionTitle = IFNULL(p_title, sessionTitle),
beamLineOperator = IFNULL(p_beamlineOperator, beamLineOperator),
nbShifts = IFNULL(p_nbShifts, nbShifts),
scheduled = IFNULL(p_scheduled, scheduled),
usedFlag = IFNULL(p_usedFlag, usedFlag),
comments = IFNULL(p_comments, comments),
expSessionPk = IFNULL(p_externalPkId, expSessionPk),
externalId = IFNULL(unhex(p_externalPkUUID), externalId)
WHERE sessionId = row_session_id;
SET p_id := row_session_id;
Expand Down

0 comments on commit 34b9c44

Please sign in to comment.