755 |
raphael |
1 |
/*
|
756 |
raphael |
2 |
Mise à jour de réferentiels NULL ou vides pour les observations dotées d'un nom_sel_nn
|
755 |
raphael |
3 |
75427 observations trouvées au 2013/07/19
|
|
|
4 |
|
|
|
5 |
Les observations problématiques sont les suivantes:
|
|
|
6 |
SELECT id_observation, nom_referentiel, nom_sel, nom_sel_nn, nom_ret, nom_ret_nn, nt, famille
|
816 |
raphael |
7 |
FROM `BASEEDIT`.`cel_obs`
|
780 |
raphael |
8 |
WHERE nom_referentiel IS NULL AND nom_sel != '' AND nom_sel IS NOT NULL AND nom_ret_nn IS NOT NULL;
|
756 |
raphael |
9 |
|
|
|
10 |
Or maj-cleanup-201307.sql reset les valeurs des observations ayant un nom_sel NULL ou '', de plus la préférence de sélection est
|
|
|
11 |
donné au nom_sel (incluant les synonymes) plutôt que nom_ret_nn.
|
|
|
12 |
|
|
|
13 |
La requête est donc:
|
|
|
14 |
SELECT id_observation, nom_referentiel, nom_sel, nom_sel_nn, nom_ret, nom_ret_nn, nt, famille
|
816 |
raphael |
15 |
FROM `BASEEDIT`.`cel_obs` WHERE nom_referentiel IS NULL AND nom_sel_nn IS NOT NULL;
|
756 |
raphael |
16 |
=> 76486
|
755 |
raphael |
17 |
*/
|
|
|
18 |
|
756 |
raphael |
19 |
|
|
|
20 |
DROP TEMPORARY TABLE IF EXISTS T_bis;
|
|
|
21 |
DROP PROCEDURE IF EXISTS majreferentiel;
|
|
|
22 |
|
|
|
23 |
CREATE TEMPORARY TABLE IF NOT EXISTS T_bis ( INDEX(`nom`(30))) AS \
|
816 |
raphael |
24 |
SELECT "bdtfx" AS valid_ref, CONCAT(b.nom_sci, ' ', b.auteur) AS nom, b.num_nom, b.num_taxonomique, b.famille FROM `BASESOURCE`.`bdtfx_v1_01` b UNION ALL \
|
|
|
25 |
SELECT "bdtxa" AS valid_ref, CONCAT(a.nom_sci, ' ', a.auteur) AS nom, a.num_nom, a.num_tax, a.famille FROM `BASESOURCE`.`bdtxa_v1_00` a;
|
756 |
raphael |
26 |
|
|
|
27 |
/* Donc nous JOINons:
|
|
|
28 |
-- INNER JOIN sur bdtfx: 69719
|
816 |
raphael |
29 |
SELECT id_observation, nom_referentiel, nom_sel, nom_sel_nn, nom_ret, nom_ret_nn, nt, c.famille FROM `BASEEDIT`.`cel_obs` c INNER JOIN `BASESOURCE`.`bdtfx_v1_01` b ON (b.num_nom = c.nom_sel_nn) WHERE nom_referentiel IS NULL AND nom_sel_nn IS NOT NULL;
|
756 |
raphael |
30 |
-- INNER JOIN sur bdtxa: 79471 dont 9752 en dup (bdtxa + bdtfx), eg: 1005047
|
816 |
raphael |
31 |
SELECT id_observation, nom_referentiel, nom_sel, nom_sel_nn, nom_ret, nom_ret_nn, nt, c.famille FROM `BASEEDIT`.`cel_obs` c INNER JOIN T_bis b ON (b.num_nom = c.nom_sel_nn) WHERE nom_referentiel AND nom_sel_nn IS NOT NULL;
|
756 |
raphael |
32 |
*/
|
|
|
33 |
|
|
|
34 |
/* d'où GROUP BY id_observation HAVING count(id_observation) = 1 */
|
755 |
raphael |
35 |
/*
|
756 |
raphael |
36 |
SELECT id_observation, nom_referentiel, nom_sel, nom_sel_nn, nom_ret, nom_ret_nn, nt, c.famille
|
816 |
raphael |
37 |
FROM `BASEEDIT`.`cel_obs` c
|
756 |
raphael |
38 |
INNER JOIN T_bis b
|
|
|
39 |
ON (b.num_nom = c.nom_sel_nn)
|
780 |
raphael |
40 |
WHERE nom_referentiel IS NULL AND nom_sel_nn IS NOT NULL GROUP BY id_observation HAVING count(id_observation) = 1;
|
756 |
raphael |
41 |
-- 59967, tous bdtfx...
|
|
|
42 |
*/
|
755 |
raphael |
43 |
|
|
|
44 |
|
756 |
raphael |
45 |
delimiter |
|
755 |
raphael |
46 |
|
756 |
raphael |
47 |
CREATE PROCEDURE majreferentiel()
|
|
|
48 |
BEGIN
|
|
|
49 |
DECLARE done INT DEFAULT 0;
|
|
|
50 |
DECLARE subst INT DEFAULT 0;
|
|
|
51 |
DECLARE _id_observation bigint(20) DEFAULT 0;
|
|
|
52 |
DECLARE _valid_ref varchar(20) DEFAULT NULL;
|
816 |
raphael |
53 |
DECLARE cur1 CURSOR FOR SELECT id_observation, valid_ref FROM `BASEEDIT`.`cel_obs` c INNER JOIN T_bis b ON (b.num_nom = c.nom_sel_nn)
|
780 |
raphael |
54 |
WHERE nom_referentiel IS NULL AND nom_sel_nn IS NOT NULL group by id_observation HAVING count(id_observation) = 1;
|
756 |
raphael |
55 |
-- DECLARE CONTINUE HANDLER FOR NOT FOUND SET done = TRUE;
|
|
|
56 |
DECLARE CONTINUE HANDLER FOR SQLSTATE '02000' SET done = 1;
|
|
|
57 |
|
|
|
58 |
OPEN cur1;
|
|
|
59 |
REPEAT
|
|
|
60 |
FETCH cur1 INTO _id_observation, _valid_ref;
|
816 |
raphael |
61 |
UPDATE `BASEEDIT`.`cel_obs` c SET nom_referentiel = _valid_ref WHERE id_observation = _id_observation;
|
756 |
raphael |
62 |
SET subst = subst + 1;
|
|
|
63 |
UNTIL done END REPEAT;
|
|
|
64 |
select subst AS 'nombre de mises à jour de référentiel effectuées';
|
|
|
65 |
CLOSE cur1;
|
|
|
66 |
END
|
|
|
67 |
|
|
|
|
68 |
|
|
|
69 |
delimiter ;
|