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 fa45fd4..8336f9b 100644 Binary files a/BddCorrect/test.db and b/BddCorrect/test.db differ 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(); ?>