1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21
| delimiter $$
DROP procedure IF EXISTS inscription$$
CREATE procedure inscription(IN nom varchar(255),IN sexe char(1)/*...les autres trucs à mettre*/)
begin
declare y smallint DEFAULT year(current_date);
declare i mediumint;
SET autocommit=0;
start transaction;
SELECT valeur+1
INTO i
FROM semaphores
WHERE nom=inscrits
for update; #on met un verrou de lecture jusqu'a un update
INSERT INTO etudiants(arrivee,depart,nom,...,matricule)VALUES
(CURRENT_DATE,NULL,nom,/*...*/concat(y,'-',lpad(i,6,'0'),'-',sexe));
update semaphores
set valeur=valeur+1
where nom='inscrits'; #on libère le verrou sur 'inscrits'
commit;
end$$
delimiter ; |
Partager