From 16990453b7d576461ccd7f560f56d02d3a897f13 Mon Sep 17 00:00:00 2001 From: Mehdi Date: Tue, 9 Jun 2020 18:54:22 +0200 Subject: [PATCH] =?UTF-8?q?Ajout=20v=C3=A9rification=20des=20fonctions=20c?= =?UTF-8?q?r=C3=A9ees=20par=20l'utilisateur?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- BddCorrect/Correcteur.php | 124 +++++++++++++---------- BddCorrect/SqliteDb.php | 85 ++++++++++++---- BddCorrect/nbproject/private/private.xml | 3 +- BddCorrect/test.db | Bin 12288 -> 12288 bytes BddCorrect/vues/VuePrincipale.php | 13 +-- 5 files changed, 142 insertions(+), 83 deletions(-) diff --git a/BddCorrect/Correcteur.php b/BddCorrect/Correcteur.php index 9d1375e..e68e84e 100644 --- a/BddCorrect/Correcteur.php +++ b/BddCorrect/Correcteur.php @@ -8,12 +8,7 @@ header('Content-type: text/plain'); $db = new SqliteDb(); $conn = oci_connect('u_prems', '123456','localhost/orcl'); -/*if(!$conn){ - echo 'conn ERRROROR'; -} -else { - echo 'conn SUCCCESSSS'; -}*/ + $cmpt = 0; $numQuestion = 0; foreach ($_POST['textbox'] as $textbox) { @@ -21,66 +16,89 @@ foreach ($_POST['textbox'] as $textbox) { $UserQuery = oci_parse($conn, $textbox); $reponseUser = oci_execute($UserQuery); - $sqliteQuery = $db->prepare('SELECT reponse FROM Correct WHERE rowid= ? '); - $sqliteQuery->bindParam(1, $numQuestion); - $result = $sqliteQuery->execute(); - $sqliteRow = $result->fetchArray(); - $vraiReponse = oci_parse($conn, $sqliteRow['reponse']); - $enAttente = oci_execute($vraiReponse); - /*$spool = $db->prepare('SPOOL ? '); - $spool->bindParam(1, 'jytdj'); - $result = $spol->execute(); - $fileUser = fopen("fileus.txt","w");*/ + $typeQuery = $db->prepare('SELECT type FROM Correct WHERE rowid = ?'); + $typeQuery->bindParam(1, $numQuestion); + $resultType = $typeQuery->execute(); + $typeRow = $resultType->fetchArray(); $err = 0; $verif =0; - while( ($oracleRow = oci_fetch_array($UserQuery, OCI_NUM)) && $err == 0 ){ - $verif = 1; - $vraiReponseRow = oci_fetch_array($vraiReponse,OCI_NUM ); - /*echo oci_num_rows($UserQuery) . " lignes insérées.
\n"; - echo oci_num_rows($vraiReponse) . " lignes insérées sqlite.
\n";*/ + //si la question attend un SELECT + if($typeRow['type'] == 'query'){ + $sqliteQuery = $db->prepare('SELECT reponse FROM Correct WHERE rowid= ? '); + $sqliteQuery->bindParam(1, $numQuestion); + $result = $sqliteQuery->execute(); + $sqliteRow = $result->fetchArray(); + $vraiReponse = oci_parse($conn, $sqliteRow['reponse']); + $enAttente = oci_execute($vraiReponse); + if(oci_num_rows($UserQuery) != oci_num_rows($vraiReponse)){ $err=-3; break; } - if(sizeof($oracleRow) == sizeof($vraiReponseRow)){ - /*foreach($vraiReponseRow as $key => $value) - { - echo $key." has the value " . $value ."\n"; + while( ($oracleRow = oci_fetch_array($UserQuery, OCI_NUM)) && $err == 0 ){ + $verif = 1; + $vraiReponseRow = oci_fetch_array($vraiReponse,OCI_NUM ); + + if(sizeof($oracleRow) == sizeof($vraiReponseRow)){ + for($i=0 ; $i< sizeof($vraiReponseRow)-1 ; $i++){ + if($oracleRow[$i] != $vraiReponseRow[$i]){ + $err = -1; + break; + } + } } - foreach($oracleRow as $key => $value) - { - echo $key." BLASE the value " . $value ."\n"; - }*/ - for($i=0 ; $i< sizeof($vraiReponseRow)-1 ; $i++){ - if($oracleRow[$i] != $vraiReponseRow[$i]){ - $err = -1; - break; - } + else { + $err = -2; + break; } + } + if($err == 0 ){ + echo "La réponse à la question " .$numQuestion. " est JUSTE ! \n"; + $cmpt++; } - else { - $err = -2; - break; + else echo "La réponse à la question " .$numQuestion. " est FAUSSE ! \n"; + } + //si la question attend un CREATE FUNCTION + else{ + $fonctionQuery = $db->prepare('SELECT * FROM Correct WHERE rowid= ? '); + $fonctionQuery->bindParam(1, $numQuestion); + $result = $fonctionQuery->execute(); + $fonctionRow = $result->fetchArray(); + + $creationFonction = oci_parse($conn, $fonctionRow['fonctionCorrect']); + $creatF = oci_execute($creationFonction); + + $testUser = oci_parse($conn, $fonctionRow['testUser']); + $testu = oci_execute($testUser); + $testF = oci_parse($conn, $fonctionRow['reponse']); + $testf = oci_execute($testF); + + if(oci_num_rows($testUser) != oci_num_rows($testF)){ + $err=-3; } - /*for($i=0 ; $i< sizeof($vraiReponseRow)-2 ; $i++){ - echo $vraiReponseRow[$i]; - fwrite($fileUser,$vraiReponseRow[$i] . "\t"); + while( ($reponseRow = oci_fetch_array($testUser,OCI_NUM)) && $err == 0){ + $vraiReponseRow = oci_fetch_array($testF,OCI_NUM ); + if(sizeof($reponseRow) == sizeof($vraiReponseRow)){ + for($i=0 ; $i< sizeof($vraiReponseRow)-1 ; $i++){ + if($reponseRow[$i] != $vraiReponseRow[$i]){ + $err = -1; + break; + } + } + } + else { + $err = -2; + break; + } } - fwrite($fileUser, "\n");*/ - /* echo 'vrai ' . $vraiReponseRow[0] . ' || ora = ' . $oracleRow[0] . "\n"; - if ($vraiReponseRow[0] == $oracleRow[0]) { - echo "La réponse à la question n° " . $i . " est JUSTE\n"; - $cmpt++; - } else { - echo 'La réponse à la question n° ' . $i . " est FAUSSE\n\n"; - }*/ - } - if($err == 0 && $verif==1){ - echo "La réponse à la question " .$numQuestion. " est JUSTE ! \n"; - $cmpt++; + if($err == 0 ){ + echo "La réponse à la question " .$numQuestion. " est JUSTE ! \n"; + $cmpt++; + } + else echo "La réponse à la question " .$numQuestion. " est FAUSSE ! \n"; } - else echo "La réponse à la question " .$numQuestion. " est FAUSSE ! \n"; + } echo 'Résultat : ' . $cmpt . '/' . $numQuestion; diff --git a/BddCorrect/SqliteDb.php b/BddCorrect/SqliteDb.php index 3c5ec69..df00206 100644 --- a/BddCorrect/SqliteDb.php +++ b/BddCorrect/SqliteDb.php @@ -1,4 +1,5 @@ exec('DROP TABLE Correct'); - $this->exec('CREATE TABLE Correct ( question STRING, reponse STRING)'); + $this->exec('CREATE TABLE Correct ( question STRING, reponse STRING, type STRING, fonctionCorrect STRING,testUser STRING)'); - //Question 1 - $test = 'SELECT count(*) FROM stats WHERE prenomnoms=\'Kevin Durant\' '; - $q = "INSERT INTO Correct VALUES ('Trouver le nombre de matchs joués par Kevin Durant', ? )"; + /* //Question 1 + $type = 'query'; + $fonctionCorrect = null; + $testU = null; + $reponse = 'SELECT count(*) FROM stats WHERE prenomnoms=\'Kevin Durant\' '; + $q = "INSERT INTO Correct VALUES ('Trouver le nombre de matchs joués par Kevin Durant', ? ,?,?,?)"; $stmt = $this->prepare($q); - $stmt->bindParam(1,$test); + $stmt->bindParam(1,$reponse); + $stmt->bindParam(2,$type); + $stmt->bindParam(3,$fonctionCorrect); + $stmt->bindParam(4,$testU); $stmt->execute(); - //Question 2 - $test = ' SELECT prenomnoms,datematch,points,equipeadverse FROM stats WHERE points = (SELECT max(points) FROM stats)'; - $q = "INSERT INTO Correct VALUES ('Lister le(s) joueur(s) ayant marqué le plus de points dans la saison en indiquant son nom, la date du match, le nombre de points, l équipe adverse et le nombre de points marqués ', ? )"; + //Question 2 + $type = 'query'; + $fonctionCorrect = null; + $testU = null; + $reponse = ' SELECT prenomnoms,datematch,points,equipeadverse FROM stats WHERE points = (SELECT max(points) FROM stats)'; + $q = "INSERT INTO Correct VALUES ('Lister le(s) joueur(s) ayant marqué le plus de points dans la saison en indiquant son nom, la date du match, le nombre de points, l équipe adverse et le nombre de points marqués ', ? ,?,?,?)"; $stmt = $this->prepare($q); - $stmt->bindParam(1,$test); + $stmt->bindParam(1,$reponse); + $stmt->bindParam(2,$type); + $stmt->bindParam(3,$fonctionCorrect); + $stmt->bindParam(4,$testU); $stmt->execute(); - //Question 3 - $test = ' SELECT prenomnoms, COUNT(*) FROM stats GROUP BY prenomnoms HAVING count(*) = (SELECT MAX(c) FROM (SELECT COUNT(*) AS c FROM stats GROUP BY prenomnoms))'; - $q = "INSERT INTO Correct VALUES ('Lister le(s) joueur(s) ayant joué le plus de match pendant la saison', ? )"; + //Question 3 + $type = 'query'; + $fonctionCorrect = null; + $testU = null; + $reponse = ' SELECT prenomnoms, COUNT(*) FROM stats GROUP BY prenomnoms HAVING count(*) = (SELECT MAX(c) FROM (SELECT COUNT(*) AS c FROM stats GROUP BY prenomnoms))'; + $q = "INSERT INTO Correct VALUES ('Lister le(s) joueur(s) ayant joué le plus de match pendant la saison', ? ,?,?,?)"; $stmt = $this->prepare($q); - $stmt->bindParam(1,$test); + $stmt->bindParam(1,$reponse); + $stmt->bindParam(2,$type); + $stmt->bindParam(3,$fonctionCorrect); + $stmt->bindParam(4,$testU); $stmt->execute(); //Question 5 - $test = 'SELECT * FROM equipe WHERE nom= \'Hawks\' '; - $q = "INSERT INTO Correct VALUES ('Déterminer pour Kevin Durant pour le match du 30-oct-17 quelle est l équipe qui joue à domicile', ? )"; + $type = 'query'; + $fonctionCorrect = null; + $testU = null; + $reponse = 'SELECT nom FROM Equipe, Stats WHERE datematch = \'30-OCT-17\' AND prenomnoms = \'Kevin Durant\' AND idequipe = CASE WHEN locationjoueur = \'Away\' THEN equipeadverse WHEN locationjoueur = \'Home\' THEN equipejoueur END '; + $q = "INSERT INTO Correct VALUES ('Déterminer pour Kevin Durant pour le match du 30-oct-17 quelle est l équipe qui joue à domicile', ?,?,?,? )"; $stmt = $this->prepare($q); - $stmt->bindParam(1,$test); - $stmt->execute(); + $stmt->bindParam(1,$reponse); + $stmt->bindParam(2,$type); + $stmt->bindParam(3,$fonctionCorrect); + $stmt->bindParam(4,$testU); + + $stmt->execute();*/ + //Question 6 + $this->joueurEtDateRandom($joueurRandom, $dateRandom); + $type = 'fonction'; + $fonctionCorrect = 'CREATE OR REPLACE FUNCTION fpointsmarques(date_match IN VARCHAR2, joueur IN VARCHAR2 ) RETURN NUMBER IS nbPoints NUMBER ; BEGIN SELECT points INTO nbPoints FROM stats WHERE datematch = date_match AND prenomnoms=joueur; RETURN nbPoints; END;' ; + $reponse = 'SELECT fpointsmarques(\''.$dateRandom.'\', \''.$joueurRandom.'\') FROM DUAL'; + $testU = 'SELECT pointsmarques(\''.$dateRandom.'\', \''.$joueurRandom.'\') FROM DUAL' ; + $q = "INSERT INTO Correct VALUES ('Ecrire une fonction pointsmarques qui détermine pour une date de match et un joueur donnés quelle est le nombre de points marqués par ce joueur', ?,?,?,? )"; + $stmt = $this->prepare($q); + $stmt->bindParam(1,$reponse); + $stmt->bindParam(2,$type); + $stmt->bindParam(3,$fonctionCorrect); + $stmt->bindParam(4,$testU); + $stmt->execute(); } + + function joueurEtDateRandom(&$nomRandom, &$dateRandom){ + $conn = oci_connect('u_prems', '123456','localhost/orcl'); + $listeJoueurQuery = oci_parse($conn, 'SELECT prenomnoms,datematch FROM stats'); + oci_execute($listeJoueurQuery); + $listeJoueurRows = oci_fetch_all($listeJoueurQuery, $listeJoueurArray); + //print_r($listeJoueurArray); + $rand_keys = array_rand($listeJoueurArray['PRENOMNOMS'], 1); + $nomRandom = $listeJoueurArray['PRENOMNOMS'][$rand_keys]; + $dateRandom = $listeJoueurArray['DATEMATCH'][$rand_keys]; + } + } diff --git a/BddCorrect/nbproject/private/private.xml b/BddCorrect/nbproject/private/private.xml index 6f1ea0e..74b6be9 100644 --- a/BddCorrect/nbproject/private/private.xml +++ b/BddCorrect/nbproject/private/private.xml @@ -3,9 +3,8 @@ - file:/C:/xampp/htdocs/BddCorrect/index.php - file:/C:/xampp/htdocs/BddCorrect/vues/VuePrincipale.php file:/C:/xampp/htdocs/BddCorrect/SqliteDb.php + file:/C:/xampp/htdocs/BddCorrect/vues/VuePrincipale.php file:/C:/xampp/htdocs/BddCorrect/Correcteur.php diff --git a/BddCorrect/test.db b/BddCorrect/test.db index fa45fd437622f0a0e27a2cdc7aaaf56b76609896..8336f9b150b76d837ff799959f7b246b24304b7e 100644 GIT binary patch literal 12288 zcmeI&L66cv6bJBjF>X9;;O1dt@)8d$2}?vxJdjN+Wp)<>1xs0vrofP`fwoSEO*|Nb z*)Ox7V-F^N1V4?h&4i};Ow)KxWEc-G z48th!vB!tWm*4pOfRB9R*nJznqxO;xIL$0x8O5vO=ld$~90Cx400bZa0SG_<0uX=z z1R(JL2rT!_{l|xg=2B{ZG?R9ulpO2qRIpuPd4fEv*%6cl>4-iqWTJy8q=DzQowF(_ z8Ao9vf8Fa(@#bb4h2u0kug{7!zhjt4l@(RCObf;DTX(pG00bZa0SG_<0uX=z1Rwwb z2teR36etz;D&A#~5br*v|MN?GzeUWuk=5G#!4HFXY!H9|1Rwwb2tWV=5P$##An;EL zTt77*eXTFeC)edKVyprsX%VJhdau`oDUO0rCv#t=>&m>i9MI(UMoTphI4h18YL!0m z`RnkBB>p;ld`VJskUm5U$&V*d7~bBbrE)ft#D6%6Phm74@laf{9)K%(gfuVq6^&(9 zJrEsXdoLckz3!T@6hp2LV!}P6`GY-yE`+Uo%v=j*1EUb5r)Hisrt;ovNdbjwzUdi zSv6r>Y5g-D$k-)e4dHdL~{gAgM=4Wu3J}K8qao@CMK2+OXx3z2EnL~rm*XcbMyw+OB zh4Lk6!XV+=2pK`o>ptJ!SOmpm8EIawoe8GZ`mc!>Y5g-CY zfCvzQ|B%3Jwc>aOLIXYw41V^{R<20w%aZJFzIOMwRsS&)On=1*H6lO+hyW2F0z`la z5CI}U1c<2_U+ zWPb%3o9yVLZb0f+r_#BTryZd&A_#d?JGrw&Wixi11%%Frr>KKCOf&?e$YLG^nL1>k znb6r4Z?S8vIBtTEUWE3}-nQ3VaEd@c8)h_Yba(b%!rEInw}j2sE4&^CUnY^s>{p;! zy4z~KY5Jvuk!xi)Xg1)VO$8 OBN!ivmB!>@Z@?c#ms8yU diff --git a/BddCorrect/vues/VuePrincipale.php b/BddCorrect/vues/VuePrincipale.php index bed2a1e..4b7200e 100644 --- a/BddCorrect/vues/VuePrincipale.php +++ b/BddCorrect/vues/VuePrincipale.php @@ -10,19 +10,10 @@ and open the template in the editor. - prepare('SELECT question FROM Correct'); - $result->execute(array()); - $listeQuestion = $result->fetchAll();*/ - - - //$Question1 = $db->querySingle('SELECT question FROM Correct'); - ?> +
-

getQuestion(); ?>

+

getQuestion(); ?>