USE temp ;
DROP TABLE IF EXISTS PILE ;
DROP TEMPORARY TABLE IF EXISTS PROPOSITION ;
DROP TABLE IF EXISTS SELECTION ;
DROP TABLE IF EXISTS INTERROGATION ;
DROP TABLE IF EXISTS QUESTIONNAIRE_PHRASE ;
DROP TABLE IF EXISTS QUESTIONNAIRE ;
DROP TABLE IF EXISTS PHRASES_NB ;
DROP TABLE IF EXISTS REPONDRE ;
DROP TABLE IF EXISTS CHOISIR ;
DROP TABLE IF EXISTS UTILISATEUR ;
DROP TABLE IF EXISTS CORRIGE ;
DROP TABLE IF EXISTS PHRASE ;
DROP TABLE IF EXISTS DIFFICULTE ;
DROP TABLE IF EXISTS COMPOSITION ;
DROP TABLE IF EXISTS REGLE ;
DROP TABLE IF EXISTS ELEMENT ;
DROP TABLE IF EXISTS TYPE_ELEMENT ;
-------------------------------------------------------------------------------------------------
CREATE TABLE TYPE_ELEMENT
(
TypeElementId INT NOT NULL
, TypeElementLibelle VARCHAR(16) NOT NULL
, CONSTRAINT TYPE_ELEMENT_PK PRIMARY KEY (TypeElementId)
) ;
CREATE TABLE ELEMENT
(
ElementId INT NOT NULL
, TypeElementId INT NOT NULL
, ElementTexte VARCHAR(64) NOT NULL
, CONSTRAINT ELEMENT_PK PRIMARY KEY (ElementId)
, CONSTRAINT ELEMENT_TYPE_ELEMENT_FK FOREIGN KEY (TypeElementId)
REFERENCES TYPE_ELEMENT (TypeElementId) ON DELETE CASCADE
) ;
CREATE TABLE COMPOSITION
(
ElementComposantId INT NOT NULL
, ElementComposeId INT NOT NULL
, CONSTRAINT COMPOSITION_ELEMENT_COMPOSANT_FK FOREIGN KEY (ElementComposantId)
REFERENCES ELEMENT (ElementId) ON DELETE CASCADE
, CONSTRAINT COMPOSITION_ELEMENT_COMPOSE_FK FOREIGN KEY (ElementComposeId)
REFERENCES ELEMENT (ElementId)
) ;
CREATE TABLE REGLE
(
RegleId INT NOT NULL
, ElementId INT NOT NULL
, RegleTexte VARCHAR(64) NOT NULL
, NbPhrases INT NOT NULL
, CONSTRAINT REGLE_PK PRIMARY KEY (RegleId)
, CONSTRAINT REGLE_ELEMENT_FK FOREIGN KEY (ElementId)
REFERENCES ELEMENT (ElementId)
) ;
CREATE TABLE DIFFICULTE
(
DifficulteId INT NOT NULL
, DifficulteNiveau INT NOT NULL DEFAULT 1
, DifficulteTexte VARCHAR(32) NOT NULL
, CONSTRAINT DIFFICULTE_PK PRIMARY KEY (DifficulteId)
, CONSTRAINT DIFFICULTE_AK UNIQUE (DifficulteNiveau)
) ;
CREATE TABLE PHRASE
(
RegleId INT NOT NULL
, PhraseId INT NOT NULL
, DifficulteId INT NOT NULL
, Texte VARCHAR(96) NOT NULL
, CONSTRAINT PHRASE_PK PRIMARY KEY (RegleId, PhraseId)
, CONSTRAINT PHRASE_REGLE_FK FOREIGN KEY (RegleId)
REFERENCES REGLE (RegleId)
, CONSTRAINT PHRASE_DIFFICULTE_FK FOREIGN KEY (DifficulteId)
REFERENCES DIFFICULTE (DifficulteId)
) ;
-- --------------------------------------------------------------------
-- TABLE PILE - Simulation de la jointure récursive
-- --------------------------------------------------------------------
CREATE TABLE PILE
(
PileId INT NOT NULL AUTO_INCREMENT
, Niveau INT NOT NULL
, TypeParentId INT NOT NULL
, TypeParentNom VARCHAR(16) NOT NULL
, ElementParentId INT NOT NULL
, ElementParentNom VARCHAR(64) NOT NULL
, TypeElementId INT NOT NULL
, TypeElementNom VARCHAR(16) NOT NULL
, ElementId INT NOT NULL
, ConcatenationNum VARCHAR(64) NOT NULL
, ElementNom VARCHAR(96) NOT NULL DEFAULT ''
, Difficulte INT NOT NULL DEFAULT 0
, CONSTRAINT PILE_PK PRIMARY KEY (PileId)
, CONSTRAINT PILE_AK UNIQUE (ElementParentId, TypeElementId, ElementId)
) ;
-- --------------------------------------------------------------
-- Table temporaire pour présenter les phrases une à une
-- --------------------------------------------------------------
CREATE TEMPORARY TABLE PROPOSITION
(
NumeroLigne INT NOT NULL AUTO_INCREMENT
, Alea FLOAT NOT NULL DEFAULT 0
, TypeParentId INT NOT NULL
, TypeParentNom VARCHAR(16) NOT NULL
, ElementParentId INT NOT NULL
, ElementParentNom VARCHAR(64) NOT NULL
, TypeElementId INT NOT NULL
, TypeElementNom VARCHAR(16) NOT NULL
, ElementId INT NOT NULL
, ElementNom VARCHAR(96) NOT NULL DEFAULT ''
, CONSTRAINT PROPOSITION_PK PRIMARY KEY (NumeroLigne)
, CONSTRAINT PROPOSITION_AK UNIQUE (ElementParentId, TypeElementId, ElementId)
) ;
-- -------------------------------------------------------------
-- Jeu d'essai
-- -------------------------------------------------------------
INSERT INTO TYPE_ELEMENT (TypeElementId, TypeElementLibelle) VALUES
(1, 'Partie'), (2, 'Sous-partie'), (3, 'Rubrique') ;
SELECT * FROM TYPE_ELEMENT ;
INSERT INTO ELEMENT (ElementId, TypeElementId, ElementTexte) VALUES
(1, 1, 'Formes et accords du verbe')
, (2, 1, 'Formes et accords du nom, de l''adjectif et de l''adverbe')
, (3, 1, 'Orthographe lexicale, signes graphiques et syntaxe')
, (4, 1, 'Ces mots que l''on confond')
, (5, 2, 'Le verbe : ses formes')
, (6, 2, 'Syntaxe')
, (7, 3, 'L''infinitif')
, (8, 3, 'Les noms : leur féminin, leur pluriel')
, (9, 3, 'L''imparfait du subjonctif')
, (10, 2, 'Le verbe, ses pièges')
, (14, 3, 'Rubrique-à-brac')
, (15, 2, 'sous-partie, piège à AK de PILE')
, (91, 1, 'Piège à récursivité')
, (92, 1, 'Piège à récursivité')
, (93, 2, 'Piège à récursivité')
;
SELECT * FROM ELEMENT ;
INSERT INTO COMPOSITION (ElementComposantId, ElementComposeId) VALUES
(5,1), (6, 3), (7, 5), (8, 2), (9, 5), (10, 1), (93, 92), (14, 1), (15, 1)
;
SELECT * FROM COMPOSITION ;
INSERT INTO REGLE (RegleId, ElementId, RegleTexte, NbPhrases) VALUES
(1, 8, 'Le pluriel des noms : cas généraux', 5)
, (2, 6, 'est-ce que', 15)
, (3, 4, 'a ; à', 2)
, (4, 4, 'ou ; où', 2)
, (5, 4, 'or ; hors', 4)
, (6, 9, 'La 3e personne du singulier', 5)
, (7, 9, 'La 3e personne du pluriel', 3)
-- /*
, (8, 5, 'Une règle de la forme spéciale du verbe', 2)
, (9, 1, 'Accord dissonant du verbe', 2)
, (10, 14, 'règle-à-brac',5)
, (11, 10, 'rg11, enfant de SP10', 5)
, (12, 10, 'rg12, enfant de SP10', 5)
, (13, 10, 'rg13, enfant de SP10', 5)
, (14, 10, 'rg14, enfant de SP10', 5)
, (15, 1, 'règle, piège à AK de PILE', 2)
-- */
;
-- SELECT * FROM REGLE ;
INSERT INTO DIFFICULTE (DifficulteId, DifficulteNiveau, DifficulteTexte) VALUES
(1, 1, 'Facile'), (2, 2, 'Assez facile'), (3, 3, 'Piège classique'), (4, 4, 'Niveau Mérimée') ;
-- SELECT * FROM DIFFICULTE ;
INSERT INTO PHRASE (RegleId, PhraseId, DifficulteId, Texte) VALUES
(1, 1, 1, 'rg1, ph1, le petit chat est morts')
, (1, 2, 2, 'rg1, ph2, il a un petit soucis')
, (1, 3, 1, 'rg1, ph3, des yeux marrons')
, (1, 4, 2, 'rg1, ph4, il est huit heure')
, (1, 5, 3, 'rg1, ph5, Huit cent deux kilos')
, (3, 1, 2, 'rg3, ph1 , Je vais à Paris')
, (3, 2, 2, 'rg3, ph2, Pierre a faim')
, (3, 3, 4, 'rg3, ph3, Ce crayon est a moi')
, (4, 1, 1, 'rg4, Il et fort et agile')
, (4, 2, 1, 'rg4, Elle est grande')
, (4, 3, 4, 'rg4, Il aime le cuissot de chevreuil')
, (4, 4, 4, 'rg4, Il aime aussi le cuissot de veau')
, (4, 5, 3, 'rg4, C''est une imbécillité')
, (5, 1, 2, 'rg5, ph1')
, (5, 2, 2, 'rg5, ph2')
, (6, 1, 3, 'rg6, ph1, 3, Qu''ils cinématographiassent cela !')
, (6, 2, 3, 'rg6, ph2, 3, Qu''ils n''aimassent pas cela !')
, (6, 3, 2, 'rg6, ph3, 2, Fallait-il qu''ils vous aimassent')
, (6, 4, 2, 'rg6, ph4, 2, Et qu''ils vous idolâtrassent')
, (6, 5, 2, 'rg6, ph5, 2, Pour que vous m''assassinassiez')
, (6, 6, 2, 'rg6, ph6, 2, Qu''elles vous plussent')
, (6, 7, 2, 'rg6, ph7, 2, Qu''elles ne pussent résister')
, (6, 8, 2, 'rg6, ph8, 2, Qu''ils sursissent')
, (6, 9, 1, 'rg6, ph9, 1, Qu''ils nageassent dans la mer')
, (7, 1, 2, 'rg7, ph1, Qu''il aimât cela !')
, (7, 2, 3, 'rg7, ph2, Qu''il n''aimat pas cela !')
, (7, 3, 2, 'rg7, ph3, Qu''il eût aimé')
, (8, 1, 2, 'rg8, ph1')
, (8, 2, 2, 'rg8, ph2')
, (9, 1, 2, 'rg9, ph1')
, (9, 2, 1, 'rg9, ph2')
, (9, 3, 2, 'rg9, ph3')
, (10, 1, 2, 'rg10, ph1')
, (10, 2, 2, 'rg10, ph2')
, (11, 1, 2, 'rg11, ph1')
, (11, 2, 2, 'rg11, ph2')
, (12, 1, 2, 'rg12, ph1')
, (12, 2, 2, 'rg12, ph2')
, (13, 1, 2, 'rg13, ph1')
, (13, 2, 2, 'rg13, ph2')
, (14, 1, 2, 'rg14, ph1')
, (14, 2, 2, 'rg14, ph2')
-- */
;
-- SELECT * FROM PHRASE ;
COMMIT ;
-- ----------------------------------------------------------------
-- Les procédures
-- ----------------------------------------------------------------
DROP PROCEDURE IF EXISTS RaoulNavigue ;
DROP PROCEDURE IF EXISTS RecursonsJoyeusement ;
DELIMITER GO
-- --------------------------------------------------------------------------------------
-- Requête Rxy
-- Raoul a choisi un sujet (TypeElementId = x et ElementId = y)
-- Pour avoir la descendance directe : TypeParentId = x et ElementParentId = y.
-- Si le descendant est une phrase (TypeElementId = 5), et si Raoul veut
-- seulement travailler sur un certain niveau de difficulté (DifficulteChoisie > 0),
-- alors on filtre sur ce niveau.
-- --------------------------------------------------------------------------------------
CREATE PROCEDURE RaoulNavigue
(
IN TypeParentChoisiId INT, ParentChoisiId INT, DifficulteChoisie INT
)
BEGIN
DECLARE theNumeroLigne INT ;
-- Pour réutiliser la table, on commence par virer ce qui a déjà été traité
DELETE FROM PROPOSITION ;
IF DifficulteChoisie = 0 OR TypeParentChoisiId < 4 THEN
INSERT INTO PROPOSITION
(TypeParentId, TypeParentNom, ElementParentId, ElementParentNom
, TypeElementId, TypeElementNom, Elementid, ElementNom)
SELECT TypeParentId, TypeParentNom, ElementParentId, ElementParentNom
, TypeElementId, TypeElementNom, Elementid, ElementNom
FROM PILE
WHERE TypeParentId = TypeParentChoisiId AND ElementParentId = ParentChoisiId
ORDER BY ElementParentId, TypeElementId ; -- Pour avoir dans l'ordre des types d'élément par partie
ELSE
-- RAND() : pour rendre aléatoire l'ordre des phrases dans la table
INSERT INTO PROPOSITION
(Alea, TypeParentId, TypeParentNom, ElementParentId, ElementParentNom
, TypeElementId, TypeElementNom, Elementid, ElementNom)
SELECT RAND() AS Alea, TypeParentId, TypeParentNom, ElementParentId, ElementParentNom
, TypeElementId, TypeElementNom, Elementid, ElementNom
FROM PILE
WHERE TypeParentId = TypeParentChoisiId AND ElementParentId = ParentChoisiId
AND Difficulte = DifficulteChoisie
AND TypeElementId = 5 -- 5 : l'élément est de type phrase
ORDER BY Alea ;
END IF ;
-- Comme MySQL ne réinitialise pas à 1 l’auto-incrémentation après delete, on s’en charge
SET theNumeroLigne = (SELECT COALESCE(MIN(NumeroLigne), 0) FROM PROPOSITION) ;
UPDATE PROPOSITION
SET NumeroLigne = NumeroLigne + 1 - theNumeroLigne ;
END
GO
CREATE PROCEDURE RecursonsJoyeusement
(
IN Amorce BOOLEAN, ElementIdIn VARCHAR(10)
)
BEGIN
DECLARE theNiveau INT ;
DECLARE NiveauRegle INT ;
DECLARE NiveauPhrase INT ;
DECLARE Kount INT ;
SET theNiveau = (SELECT DISTINCT COALESCE(MAX(Niveau) + 1, 1) FROM PILE) ;
IF Amorce = TRUE THEN
-- ----------------------------------------
-- Niveau 1 (racine)
-- ----------------------------------------
IF ElementIdIn > 0 THEN
INSERT INTO PILE (ElementId, TypeElementId, TypeElementNom, Niveau, ElementParentId, ElementParentNom, TypeParentId, TypeParentNom, ConcatenationNum, ElementNom)
SELECT ElementIdIn -- Identifiant de l'élément, passé par l'appelant
, x.TypeElementId -- Identifiant du type de l'élément
, COALESCE((SELECT z.TypeElementlibelle -- Nom du type de l'élément
FROM COMPOSITION AS x JOIN ELEMENT AS y ON x.ElementComposantId = y.ElementId
JOIN TYPE_ELEMENT AS z ON y.TypeElementId = z.TypeElementId
WHERE x.ElementComposantId = ElementIdIn), '/')
, 1 -- Niveau
, COALESCE((SELECT ElementComposeId -- Identifiant du parent de l'élément
FROM COMPOSITION
WHERE ElementComposantId = ElementIdIn), 0)
, COALESCE((SELECT y.ElementTexte -- Nom du parent de l'élément
FROM COMPOSITION AS x JOIN ELEMENT AS y ON x.ElementComposeId = y.ElementId
WHERE x.ElementComposantId = ElementIdIn), '/')
, COALESCE((SELECT y.TypeElementId -- Identifiant du type du parent de l'élément
FROM COMPOSITION AS x JOIN ELEMENT AS y ON x.ElementComposeId = y.ElementId
WHERE x.ElementComposantId = ElementIdIn), 0)
, COALESCE((SELECT z.TypeElementlibelle -- Nom du type du parent de l'élément
FROM COMPOSITION AS x JOIN ELEMENT AS y ON x.ElementComposeId = y.ElementId
JOIN TYPE_ELEMENT AS z ON y.TypeElementId = z.TypeElementId
WHERE x.ElementComposantId = ElementIdIn), 0)
, RTRIM(CAST(ElementIdIn AS CHAR(4))) -- Début concaténation des id
, x.ElementTexte -- Nom de l'élément
FROM ELEMENT AS x
WHERE x.ElementId = ElementIdIn
;
ELSE
-- ---------------------------------------------
-- ElementIdIn = 0 : on prend tout
-- ---------------------------------------------
INSERT INTO PILE (ElementId, TypeElementId, TypeElementNom, Niveau, ElementParentId, ElementParentNom, TypeParentId, TypeParentNom, ConcatenationNum, ElementNom)
SELECT ElementId -- Identifiant de chaque élément racine (0 : on prend tout)
, TypeElementId -- Identifiant du type de l'élément (à savoir : 1)
, '/' -- TypeElementNom
, 1 -- Niveau
, 0 -- Identifiant du parent de l'élément
, '/' -- Nom du parent de l'élément
, 0 -- Identifiant du type du parent de l'élément
, '/' -- Nom du type du parent de l'élément
, RTRIM(CAST(ElementId AS CHAR(4))) -- Début concaténation des id
, ElementTexte -- Nom de l'élément
FROM ELEMENT
WHERE TypeElementId = 1 ;
END IF ;
-- ------------------------------------------------------------------------------
-- Niveau 2 (rattachement direct à un racine : sous-partie ou rubrique ou règle)
-- -------------------------------------------------------------------------------
INSERT INTO PILE (ElementId, TypeElementId, TypeElementNom, Niveau, ElementParentId, ElementParentNom, TypeParentId, TypeParentNom, ConcatenationNum, ElementNom)
SELECT x.ElementComposantId -- Identifiant de l'élément à récupérer
, y.TypeElementId -- Identifiant du type de l'élément
, u.TypeElementlibelle -- Nom du type de l'élément
, 2 -- Niveau
, x.ElementComposeId -- Identifiant du parent de l'élément
, z.ElementTexte -- Nom du parent de l'élément
, z.TypeElementId -- Identifiant du type du parent de l'élément
, t.TypeElementlibelle -- Nom du type du parent de l'élément
, CONCAT(RTRIM(CAST(x.ElementComposeId AS CHAR(4))), ', ', RTRIM(CAST(x.ElementComposantId AS CHAR(4)))) -- Concaténation des id
, y.ElementTexte -- Nom de l'élément
FROM COMPOSITION AS x JOIN ELEMENT AS y ON x.ElementComposantId = y.ElementId
JOIN ELEMENT AS z ON x.ElementComposeId = z.ElementId
JOIN TYPE_ELEMENT AS t ON z.TypeElementId = t.TypeElementId
JOIN TYPE_ELEMENT AS u ON y.TypeElementId = t.TypeElementId
WHERE x.ElementComposeId = y.ElementId
;
-- -------------------------------------------
-- et un tour de manège
-- -------------------------------------------
CALL RecursonsJoyeusement(FALSE, '') ;
ELSE
-- -----------------------------------------------
-- Niveau > 2 (sous-partie ou rubrique ou règle)
-- ----------------------------------------------
SET Kount = (SELECT COUNT(*)
FROM (SELECT x.ElementComposantId, Niveau
FROM COMPOSITION AS x INNER JOIN PILE AS y
ON x.ElementComposeId = y.ElementId
WHERE Niveau = TheNiveau - 1) as truc) ;
IF Kount > 0 THEN
-- ---------------------------------------------------
-- Niveau > 2 (on n'a pas atteint le niveau règle)
-- ---------------------------------------------------
INSERT INTO PILE (ElementId, TypeElementId, TypeElementNom, Niveau, ElementParentId, ElementParentNom, TypeParentId, TypeParentNom, ConcatenationNum, ElementNom)
SELECT x.ElementComposantId -- Identifiant de l'élément à récupérer
, z.TypeElementId -- Identifiant du type de l'élément
, v.TypeElementlibelle -- Nom du type de l'élément
, theNiveau -- Niveau
, x.ElementComposeId -- Identifiant du parent de l'élément
, t.ElementTexte -- Nom du parent de l'élément
, t.TypeElementId -- Identifiant du type du parent de l'élément
, u.TypeElementlibelle -- Nom du type du parent de l'élément
, CONCAT(y.ConcatenationNum, ', ', RTRIM(CAST(x.ElementComposantId AS CHAR(4)))) -- Concaténation des id
, z.ElementTexte -- Nom de l'élément
FROM COMPOSITION AS x JOIN PILE AS y ON x.ElementComposeId = y.ElementId
JOIN ELEMENT AS z ON x.ElementComposantId = z.ElementId
JOIN ELEMENT AS t ON x.ElementComposeId = t.ElementId
JOIN TYPE_ELEMENT AS u ON t.TypeElementId = u.TypeElementId
JOIN TYPE_ELEMENT AS v ON z.TypeElementId = v.TypeElementId
WHERE Niveau = TheNiveau - 1 ;
-- -------------------------------------------
-- et un tour de manège
-- -------------------------------------------
CALL RecursonsJoyeusement(FALSE, '') ;
ELSE
-- ----------------------------------------
-- On a atteint le niveau règle
-- ----------------------------------------
SET NiveauRegle = (SELECT MAX(TypeElementId) + 1 FROM TYPE_ELEMENT) ; -- Identifiant du type de la règle : id du plus grand type d'élément + 1
SET NiveauPhrase = NiveauRegle + 1 ; -- Identifiant du type de la phrase
-- ----------------------------------------------
-- Récupération des règles
-- ----------------------------------------------
INSERT INTO PILE (ElementId, TypeElementId, TypeElementNom, Niveau, ElementParentId, ElementParentNom, TypeParentId, TypeParentNom, ConcatenationNum, ElementNom)
SELECT x.RegleId -- Identifiant de la règle à récupérer
, NiveauRegle -- Identifiant du type de la règle : id du plus grand type d'élément + 1
, 'Règle' -- Nom du type de la règle : "Règle"
, theNiveau -- Niveau
, x.ElementId -- Identifiant du parent de la règle
, z.ElementTexte -- Nom du parent de la règle
, z.TypeElementId -- Identifiant du type du parent de la règle
, t.TypeElementlibelle -- Nom du type du parent de la règle
, CONCAT(y.ConcatenationNum, ', ', RTRIM(CAST(x.RegleId AS CHAR(6)))) -- Concaténation des id
, RegleTexte -- Nom de la règle
FROM REGLE AS x JOIN PILE AS y ON x.ElementId = y.ElementId
JOIN ELEMENT AS z ON x.ElementId = z.ElementId
JOIN TYPE_ELEMENT AS t ON z.TypeElementId = t.TypeElementId
;
-- ----------------------------------------------
-- Récupération des phrases
-- ----------------------------------------------
INSERT INTO PILE (ElementId, TypeElementId, TypeElementNom, Niveau, ElementParentId, ElementParentNom, TypeParentId, TypeParentNom, ConcatenationNum, ElementNom, Difficulte)
SELECT x.PhraseId -- Identifiant de la phrase à récupérer
, NiveauPhrase -- Identifiant du type de la phrase : id du type "règle" + 1
, 'Phrase' -- Nom du type de la phrase : "Phrase"
, theNiveau + 1 -- Niveau atteint
, x.RegleId -- Identifiant de la règle parente
, y.RegleTexte -- Nom de la règle parente
, NiveauRegle -- Identifiant du type "Règle"
, 'Règle' -- Nom du type "Règle"
, CONCAT(z.ConcatenationNum, ', ', RTRIM(CAST(x.PhraseId AS CHAR(6)))) -- Concaténation des id
, x.Texte -- Nom de la phrase
, t.DifficulteNiveau -- Niveau de difficulté de la phrase
FROM PHRASE AS x JOIN REGLE AS y ON x.RegleId = y.RegleId
JOIN PILE As z ON x.RegleId = z.ElementId AND z.TypeElementId = NiveauRegle
JOIN DIFFICULTE AS t ON x.DifficulteId = t.DifficulteId
;
END IF ;
END IF;
END
GO
DELIMITER ;
-- /*
-- --------------------------------------------------------
-- Appel à la procédure récursive RecursonsJoyeusement
-- --------------------------------------------------------
SET @@GLOBAL.max_sp_recursion_depth = 4; -- Pour éviter les boucles infinies...
SET @@session.max_sp_recursion_depth = 4;
-- -------------------------------------------------------------------------------
-- @Entree : L'élément d'identifiant ElementId = @Entree dans la table ELEMENT
-- -------------------------------------------------------------------------------
SET @Entree := 1 ; -- L'élément d'identifiant ElementId = 1 dans la table ELEMENT (Formes et accords du verbe)
-- SET @Entree := 5 ; -- L'élément d'identifiant ElementId = 5 dans la table ELEMENT (Le verbe : ses formes)
-- SET @Entree := 9 ; -- L'élément d'identifiant ElementId = 9 dans la table ELEMENT (l'imparfait du subjonctif)
SET @Entree := 0 ; -- La totale
SET @Amorce := TRUE ;
DELETE FROM PILE ;
CALL RecursonsJoyeusement(@Amorce, @Entree);
-- ----------------------------
-- Au résultat
-- ----------------------------
SELECT * FROM PILE
ORDER BY ElementParentId, ElementId ;
SELECT x.elementId
, x.TypeElementNom AS TypeElement
, ConcatenationNum
, CASE x.TypeElementId
WHEN 1 THEN ElementNom
WHEN 2 THEN CONCAT('---- ', ElementNom)
WHEN 3 THEN CONCAT('-------- ', ElementNom)
WHEN 4 THEN CONCAT('------------ ', ElementNom)
ELSE CONCAT('---------------- ', ElementNom)
END
AS ElementNom
FROM PILE AS x LEFT JOIN ELEMENT AS y ON x.ElementId = y.ElementId
ORDER BY ConcatenationNum ;
-- ------------------------------
-- Sans les phrases
-- ------------------------------
SELECT x.elementId
, x.TypeElementNom AS TypeElement
, ConcatenationNum
, CASE x.TypeElementId
WHEN 1 THEN ElementNom
WHEN 2 THEN CONCAT('---- ', ElementNom)
WHEN 3 THEN CONCAT('-------- ', ElementNom)
WHEN 4 THEN CONCAT('------------ ', ElementNom)
END
AS ElementNom
FROM PILE AS x LEFT JOIN ELEMENT AS y ON x.ElementId = y.ElementId
WHERE x.TypeElementId < 5
ORDER BY ConcatenationNum ;
-- */
-- -----------------------------------------------------------------------
-- Requête R1
-- Sélection des dépendants directs des parties
-- -----------------------------------------------------------------------
SELECT TypeParentId, TypeParentNom, ElementParentId, ElementParentNom
, TypeElementId, TypeElementNom, Elementid, ElementNom
, '' AS 'Requête R1'
FROM PILE
WHERE TypeParentId = 1 -- AND ElementParentId = 0
ORDER BY ElementParentId, TypeElementId -- Pour avoir dans l'ordre des types d'élément par partie
;
SET @TypeParentId = 1 ;
SET @ElementParentId = 0 ; -- signifie : ne pas tenir compte (on est au niveau racine)
-- ---------------------------------------------------------------------------------
-- Requête R2
-- Raoul a choisi "Le verbe, ses formes" (TypeElementId = 2, ElementId = 5).
-- Pour avoir la descendance directe : TypeParentId = 2 et ElementParentId = 5.
-- ---------------------------------------------------------------------------------
SELECT TypeParentId, TypeParentNom, ElementParentId, ElementParentNom
, TypeElementId, TypeElementNom, Elementid, ElementNom
, Difficulte, RAND() as Alea
, '' AS 'Requête R2'
FROM PILE
WHERE TypeParentId = 2 AND ElementParentId = 5 -- sous-partie 5, le verbe, ses formes
-- WHERE TypeParentId = 4 AND ElementParentId = 9 -- sous-partie 9
ORDER BY ElementParentId, TypeElementId, Alea -- Dans l'ordre des types d'élément par partie, et aléatoire pour le dernier niveau
;
-- --------------------------------------------------------
-- Appel à la procédure récursive RaoulNavigue
-- --------------------------------------------------------
SET @TypeParentId = 2 ; -- 'sous-partie'
SET @ElementParentId = 5 ; -- 'le verbe, ses formes'
SET @Difficulte = 2 ; -- 'niveau de difficulté (0 si pas de filtre)'
SET @TypeParentId = 4 ;
SET @ElementParentId = 9 ;
SET @Difficulte = 2 ;
-- SET @Difficulte = 0 ;
CALL RaoulNavigue(@TypeParentId, @ElementParentId, @Difficulte) ;
SELECT * FROM PROPOSITION ;
-- --------------------------------------------------------------------------------------
-- Requête R3
-- Raoul a choisi "L'imparfait du subjonctif" (TypeElementId = 3 et ElementId = 9)
-- Pour avoir la descendance directe : TypeParentId = 3 et ElementParentId = 9.
-- --------------------------------------------------------------------------------------
SELECT TypeParentId, TypeParentNom, ElementParentId, ElementParentNom
, TypeElementId, TypeElementNom
, Elementid
, ElementNom
, Difficulte
, '' AS 'Requête R3'
FROM PILE
WHERE TypeParentId = 3 AND ElementParentId = 9
ORDER BY ElementParentId, TypeElementId -- Pour avoir dans l'ordre des types d'élément par partie
;
SET @TypeParentId = 3 ;
SET @ElementParentId = 9 ;
SET @Difficulte = 2 ;
;
CALL RaoulNavigue(@TypeParentId, @ElementParentId, @Difficulte) ;
SELECT * FROM PROPOSITION ;
-- --------------------------------------------------------------------------------------
-- Requête R4
-- Raoul a choisi "La 3e personne du pluriel" (TypeElementId = 4 et ElementId = 6)
-- Pour avoir la descendance directe : TypeParentId = 4 et ElementParentId = 6.
-- --------------------------------------------------------------------------------------
SELECT TypeParentId, TypeParentNom, ElementParentId, ElementParentNom
, TypeElementId, TypeElementNom, Elementid, ElementNom
, Difficulte
, '' AS 'Requête R4'
FROM PILE
WHERE TypeParentId = 4 AND ElementParentId = 6
ORDER BY ElementParentId, TypeElementId
;
SET @TypeParentId = 4 ;
SET @ElementParentId = 6 ;
SET @Difficulte = 2 ;
-- CALL RaoulNavigue(@TypeParentId, @ElementParentId, @Difficulte) ;
CALL RaoulNavigue(4, 6, 2) ;
SELECT Numeroligne, ElementNom FROM PROPOSITION ORDER BY NumeroLigne ;
M'enfin...
Partager