You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

177 lines
8.0 KiB

<?php
//header('Content-type: text/plain');
class SqliteDb extends SQLite3
{
function __construct()
{
$this->open('test.db');
$this->createLogin();
$this->createTable();
}
function createTable(){
//Création De La Table
$this->exec('DROP TABLE Correct');
$this->exec('CREATE TABLE Correct ( numquestion NUMBER,question STRING, reponse STRING,points NUMBER,aleatoire CHAR)');
$this->exec('DROP TABLE FunctionCorrect');
$this->exec('CREATE TABLE FunctionCorrect (numquestion NUMBER, question STRING, reponse STRING, type STRING, fonctionCorrect STRING,testUser STRING)');
$this->exec('DROP TABLE TriggerCorrect');
$this->exec('CREATE TABLE TriggerCorrect ( numquestion NUMBER,question STRING, reponse STRING, type STRING, fonctionCorrect STRING,testUser STRING)');
$this->exec('DROP TABLE Type');
$this->exec('CREATE TABLE Type ( numquestion NUMBER,type STRING)');
$this->exec("INSERT INTO Type VALUES(1,'query')");
$this->exec("INSERT INTO Type VALUES(2,'query')");
$this->exec("INSERT INTO Type VALUES(3,'query')");
$this->exec("INSERT INTO Type VALUES(4,'query')");
$this->exec("INSERT INTO Type VALUES(5,'functionCorrect')");
//Question 1
$type = 'query';
$points =1;
$reponse = 'SELECT count(*) FROM STATS WHERE prenomnoms=\'Kevin Durant\' ';
$q = "INSERT INTO Correct VALUES (1,'Trouver le nombre de matchs joués par Kevin Durant', ? ,?,'o')";
$stmt = $this->prepare($q);
$stmt->bindParam(1,$reponse);
$stmt->bindParam(2,$points);
$stmt->execute();
//Question 2
$type = 'query';
$points =1;
$reponse = ' SELECT prenomnoms,datematch,points,equipeadverse FROM STATS WHERE points = (SELECT max(points) FROM STATS)';
$q = "INSERT INTO Correct VALUES (2,'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 ', ? ,?,'o')";
$stmt = $this->prepare($q);
$stmt->bindParam(1,$reponse);
$stmt->bindParam(2,$points);
$stmt->execute();
//Question 3
$type = 'query';
$points =1;
$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 (3,'Lister le(s) joueur(s) ayant joué le plus de match pendant la saison', ? ,?,'o')";
$stmt = $this->prepare($q);
$stmt->bindParam(1,$reponse);
$stmt->bindParam(2,$points);
$stmt->execute();
//Question 4
$type = 'query';
$points =1;
$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 (4,'Déterminer pour Kevin Durant pour le match du 30-oct-17 quelle est l équipe qui joue à domicile', ?,?,'n' )";
$stmt = $this->prepare($q);
$stmt->bindParam(1,$reponse);
$stmt->bindParam(2,$points);
$stmt->execute();
//Question 5
$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 FunctionCorrect VALUES (5,'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();
/* //Question 9
$type = 'tablemodification';
$fonctionCorrect = 'IDJOUEUR';
$testU = null;
$testP = 'SELECT data_type FROM all_TAB_COLUMNS WHERE table_name = \'JOUEUR\' '; //pour vérifier l
$reponse = 'SELECT column_name FROM all_TAB_COLUMNS WHERE table_name = \'TEST\' ';
$q = "INSERT INTO Correct VALUES (6,'Modifier la table JOUEUR pour ajouter un champ idjoueur', ?,?,?,? )";
$stmt = $this->prepare($q);
$stmt->bindParam(1,$reponse);
$stmt->bindParam(2,$type);
$stmt->bindParam(3,$fonctionCorrect);
$stmt->bindParam(4,$testU);
//Question 10
$type = 'query';
$fonctionCorrect = null;
$testU = null;
$testP = null;
$reponse = 'SELECT id_joueur FROM STATS WHERE table_name = \'TEST\' ';
$q = "INSERT INTO Correct VALUES (7,'Modifier la table JOUEUR pour ajouter un champ idjoueur', ?,?,?,? )";
$stmt = $this->prepare($q);
$stmt->bindParam(1,$reponse);
$stmt->bindParam(2,$type);
$stmt->bindParam(3,$fonctionCorrect);
$stmt->bindParam(4,$testU);
$stmt->execute();*/
//QUESITION 1 TP2
$type='trigger';
$fonctionCorrect = 'CREATE OR REPLACE TRIGGER supprJ BEFORE DELETE ON joueur FOR EACH ROW DECLARE duser varchar2(30); ddate date; BEGIN SELECT user,sysdate INTO duser,ddate FROM DUAL; INSERT INTO TRACE VALUES(ddate, duser,\'Suppression de \' || :old.prenomnomj); END;' ;
//
}
function createLogin(){
$mdp = password_hash('mdptest', PASSWORD_DEFAULT);
$username = 'test';
$this->exec('DROP TABLE login');
$this->exec('CREATE TABLE login ( username STRING, password STRING)');
$stmt = $this->prepare("INSERT INTO login VALUES(? , ?)");
$stmt->bindParam(1, $username);
$stmt->bindParam(2, $mdp);
$stmt->execute();
}
function joueurEtDateRandom(&$nomRandom, &$dateRandom){
$conn = oci_connect('u_prems', '123456','localhost/orcl');
$listeJoueurQuery = oci_parse($conn, 'SELECT prenomnoms,datematch FROM STATS INTERSECT SELECT prenomnoms,datematch FROM randomstats ');
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];
}
function joueurEtDateRandom2(&$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];
}
function createRandomTable(){
}
function ajouterRequete($num,$consigne,$requete){
$qt = "INSERT INTO Type VALUES(?,'query')";
$prp=$this->prepare($qt);
$prp->bindParam(1, $num);
$prp->execute();
$q = "INSERT INTO Correct VALUES (?,?,? ,1,'o')";
$stmt = $this->prepare($q);
$stmt->bindParam(1,$num);
$stmt->bindParam(2,$consigne);
$stmt->bindParam(3,$requete);
$stmt->execute();
}
}