diff --git a/schema/routines.sql b/schema/routines.sql index 8ffdae91..6eec989e 100644 --- a/schema/routines.sql +++ b/schema/routines.sql @@ -1,8 +1,8 @@ --- MySQL dump 10.17 Distrib 10.3.13-MariaDB, for Linux (x86_64) +-- MySQL dump 10.17 Distrib 10.3.14-MariaDB, for Linux (x86_64) -- -- Host: localhost Database: ispyb_build -- ------------------------------------------------------ --- Server version 10.3.13-MariaDB +-- Server version 10.3.14-MariaDB /*!40101 SET @OLD_CHARACTER_SET_CLIENT=@@CHARACTER_SET_CLIENT */; /*!40101 SET @OLD_CHARACTER_SET_RESULTS=@@CHARACTER_SET_RESULTS */; @@ -3806,6 +3806,39 @@ DELIMITER ; /*!50003 SET character_set_client = @saved_cs_client */ ; /*!50003 SET character_set_results = @saved_cs_results */ ; /*!50003 SET collation_connection = @saved_col_connection */ ; +/*!50003 DROP PROCEDURE IF EXISTS `retrieve_sessions_for_beamline_and_run` */; +/*!50003 SET @saved_cs_client = @@character_set_client */ ; +/*!50003 SET @saved_cs_results = @@character_set_results */ ; +/*!50003 SET @saved_col_connection = @@collation_connection */ ; +/*!50003 SET character_set_client = utf8 */ ; +/*!50003 SET character_set_results = utf8 */ ; +/*!50003 SET collation_connection = utf8_general_ci */ ; +/*!50003 SET @saved_sql_mode = @@sql_mode */ ; +/*!50003 SET sql_mode = 'STRICT_TRANS_TABLES,ERROR_FOR_DIVISION_BY_ZERO,NO_AUTO_CREATE_USER,NO_ENGINE_SUBSTITUTION' */ ; +DELIMITER ;; +CREATE PROCEDURE `retrieve_sessions_for_beamline_and_run`( + IN p_beamline varchar(15), + IN p_run varchar(7) +) + READS SQL DATA + COMMENT 'Returns a multi-row result-set with the sessions (mx12345-123), their start and end dates for beamline p_beamline and run p_run' +BEGIN + SELECT + bs.sessionId "sessionId", + concat(p.proposalCode, p.proposalNumber, '-', bs.visit_number) "session", + bs.startDate "startDate", + bs.endDate "endDate" + FROM Proposal p + INNER JOIN BLSession bs on p.proposalId = bs.proposalId + INNER JOIN v_run vr ON bs.startDate BETWEEN vr.startDate AND vr.endDate + WHERE bs.beamlinename = p_beamline AND vr.run = p_run + ORDER BY bs.startDate, bs.sessionId; +END ;; +DELIMITER ; +/*!50003 SET sql_mode = @saved_sql_mode */ ; +/*!50003 SET character_set_client = @saved_cs_client */ ; +/*!50003 SET character_set_results = @saved_cs_results */ ; +/*!50003 SET collation_connection = @saved_col_connection */ ; /*!50003 DROP PROCEDURE IF EXISTS `retrieve_sessions_for_person_login` */; /*!50003 SET @saved_cs_client = @@character_set_client */ ; /*!50003 SET @saved_cs_results = @@character_set_results */ ; @@ -7290,4 +7323,4 @@ DELIMITER ; /*!40101 SET COLLATION_CONNECTION=@OLD_COLLATION_CONNECTION */; /*!40111 SET SQL_NOTES=@OLD_SQL_NOTES */; --- Dump completed on 2019-04-08 16:26:29 +-- Dump completed on 2019-04-23 10:22:27 diff --git a/schema/stored_programs/sp_retrieve_sessions_for_beamline_and_run.sql b/schema/stored_programs/sp_retrieve_sessions_for_beamline_and_run.sql new file mode 100644 index 00000000..781d099d --- /dev/null +++ b/schema/stored_programs/sp_retrieve_sessions_for_beamline_and_run.sql @@ -0,0 +1,21 @@ +DELIMITER ;; +CREATE OR REPLACE DEFINER=`ispyb_root`@`%` PROCEDURE `retrieve_sessions_for_beamline_and_run`( + IN p_beamline varchar(15), + IN p_run varchar(7) +) +READS SQL DATA +COMMENT 'Returns a multi-row result-set with the sessions (mx12345-123), their start and end dates for beamline p_beamline and run p_run' +BEGIN + SELECT + bs.sessionId "sessionId", + concat(p.proposalCode, p.proposalNumber, '-', bs.visit_number) "session", + bs.startDate "startDate", + bs.endDate "endDate" + FROM Proposal p + INNER JOIN BLSession bs on p.proposalId = bs.proposalId + INNER JOIN v_run vr ON bs.startDate BETWEEN vr.startDate AND vr.endDate + WHERE bs.beamlinename = p_beamline AND vr.run = p_run + ORDER BY bs.startDate, bs.sessionId; +END;; + +DELIMITER ;