diff options
author | polo <ordipolo@gmx.fr> | 2022-12-14 12:55:46 +0100 |
---|---|---|
committer | polo <ordipolo@gmx.fr> | 2022-12-14 12:55:46 +0100 |
commit | ff14091476a35de16a9ea3208501040cfae93a06 (patch) | |
tree | 89ebd00ad68fbb97aac71ef8a2972748f82dee0d /src/model | |
parent | a45a3e0345890b9df3c5fa7c82966a64491eca02 (diff) | |
download | AppliGestionPHP-ff14091476a35de16a9ea3208501040cfae93a06.zip |
MODEL + reorganisation
Diffstat (limited to 'src/model')
-rw-r--r-- | src/model/CESU.php | 46 | ||||
-rw-r--r-- | src/model/Clients.php | 50 | ||||
-rw-r--r-- | src/model/DB.php | 48 | ||||
-rw-r--r-- | src/model/DevisFactures.php | 98 | ||||
-rw-r--r-- | src/model/Locations.php | 74 | ||||
-rw-r--r-- | src/model/Model.php | 162 | ||||
-rw-r--r-- | src/model/Prestations.php | 62 | ||||
-rw-r--r-- | src/model/StructTablesDB.php | 35 |
8 files changed, 575 insertions, 0 deletions
diff --git a/src/model/CESU.php b/src/model/CESU.php new file mode 100644 index 0000000..4679da2 --- /dev/null +++ b/src/model/CESU.php | |||
@@ -0,0 +1,46 @@ | |||
1 | <?php | ||
2 | // model/CESU.php | ||
3 | |||
4 | class CESU extends Model | ||
5 | { | ||
6 | const TABLE = 'cesu'; | ||
7 | |||
8 | // lecture des données ou hydratation | ||
9 | private $ID; | ||
10 | private $ID_presta; | ||
11 | private $taches; | ||
12 | private $duree_travail; | ||
13 | private $salaire; | ||
14 | |||
15 | public function __construct() | ||
16 | { | ||
17 | $this->table = self::TABLE; // => Model::$table | ||
18 | } | ||
19 | |||
20 | // setters | ||
21 | public function setID(int $value) | ||
22 | { | ||
23 | $this->ID = $value; | ||
24 | return($this); | ||
25 | } | ||
26 | public function setIDPresta(int $value) | ||
27 | { | ||
28 | $this->ID_presta = $value; | ||
29 | return($this); | ||
30 | } | ||
31 | public function setTaches(string $value) | ||
32 | { | ||
33 | $this->taches = $value; | ||
34 | return($this); | ||
35 | } | ||
36 | public function setDureeTravail(string $value) | ||
37 | { | ||
38 | $this->duree_travail = $value; | ||
39 | return($this); | ||
40 | } | ||
41 | public function setSalaire(float $value) | ||
42 | { | ||
43 | $this->salaire = $value; | ||
44 | return($this); | ||
45 | } | ||
46 | } | ||
diff --git a/src/model/Clients.php b/src/model/Clients.php new file mode 100644 index 0000000..1256458 --- /dev/null +++ b/src/model/Clients.php | |||
@@ -0,0 +1,50 @@ | |||
1 | <?php | ||
2 | // model/Clients.php | ||
3 | |||
4 | class Clients extends Model | ||
5 | { | ||
6 | // lecture des données ou hydratation | ||
7 | public $ID; | ||
8 | public $prenom_nom; | ||
9 | public $adresse; | ||
10 | public $code_client; | ||
11 | public $commentaires; | ||
12 | |||
13 | public function __construct() | ||
14 | { | ||
15 | $this->table = strtolower(__CLASS__); // simple parce que la classe a le nom de la table | ||
16 | } | ||
17 | |||
18 | //~ public function set(string $variable, $value) | ||
19 | //~ { | ||
20 | //~ $this->$variable = $value; | ||
21 | //~ return($this); | ||
22 | //~ } | ||
23 | |||
24 | // setters | ||
25 | public function setID(int $value) // inutile? il s'autoincrémente | ||
26 | { | ||
27 | $this->ID = $value; | ||
28 | return($this); | ||
29 | } | ||
30 | public function setPrenom_nom(string $value) | ||
31 | { | ||
32 | $this->prenom_nom = $value; | ||
33 | return($this); | ||
34 | } | ||
35 | public function setAdresse(string $value) | ||
36 | { | ||
37 | $this->adresse = $value; | ||
38 | return($this); | ||
39 | } | ||
40 | public function setCode_client(string $value) | ||
41 | { | ||
42 | $this->code_client = $value; | ||
43 | return($this); | ||
44 | } | ||
45 | public function setCommentaires(string $value) | ||
46 | { | ||
47 | $this->commentaires = $value; | ||
48 | return($this); | ||
49 | } | ||
50 | } | ||
diff --git a/src/model/DB.php b/src/model/DB.php new file mode 100644 index 0000000..381623b --- /dev/null +++ b/src/model/DB.php | |||
@@ -0,0 +1,48 @@ | |||
1 | <?php | ||
2 | // php/DB.php | ||
3 | |||
4 | // cette classe suit le pattern "singleton" | ||
5 | // but: ne permettre qu'une seule instance de la classe (laquelle sera éventuellement globale) | ||
6 | |||
7 | // comment? | ||
8 | // - Un attribut privé et statique contiendra l'instance unique de la classe | ||
9 | // - Un constructeur privé afin d'empêcher l'instanciation depuis l'extérieur de la classe | ||
10 | // - Une méthode statique qui permet soit d'instancier la classe soit de retourner l'unique instance créée. | ||
11 | |||
12 | class DB extends PDO | ||
13 | { | ||
14 | // paramètres du constructeur de PDO (avec sqlite seul le premier est nécessaire) | ||
15 | public static $dsn = ''; // Data Source Name = 1er paramètre | ||
16 | //~ public static $dbms = 'sqlite'; | ||
17 | //~ public static $user = ''; | ||
18 | //~ public static $password = ''; | ||
19 | //~ public static $options = ''; | ||
20 | private static $Instance; | ||
21 | |||
22 | private function __construct() // exécuté une seul fois à cause du "if" dans getInstance() | ||
23 | { | ||
24 | try | ||
25 | { | ||
26 | parent::__construct(self::$dsn); // => PDO::$dsn | ||
27 | //$this->setAttribute(PDO::MYSQL_ATTR_INIT_COMMAND, 'SET NAMES utf8'); // pour mysql/mariadb | ||
28 | $this->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION); // $this pour la méthode du parent PDO | ||
29 | $this->setAttribute(PDO::ATTR_DEFAULT_FETCH_MODE, PDO::FETCH_ASSOC); // pour PDO:fetch() et PDO::fetchAll() | ||
30 | // avec PDO::FETCH_ASSOC on obtient un tableau associatif, marche très bien puisqu'on utilise déjà des ID avec incrémentation automatique | ||
31 | // avec PDO::FETCH_BOTH (par défaut) on récupère les données en double (identifiants partant de 0 + tableau associatif) | ||
32 | } | ||
33 | catch(PDOException $e) | ||
34 | { | ||
35 | die("Impossible de se connecter à la base de données.\n" . $e->getMessage()); | ||
36 | } | ||
37 | } | ||
38 | |||
39 | // créer son objet avec: $Bdd = parent::getInstance(); | ||
40 | public static function getInstance(): self | ||
41 | { | ||
42 | if(self::$Instance === null) | ||
43 | { | ||
44 | self::$Instance = new self(); | ||
45 | } | ||
46 | return self::$Instance; | ||
47 | } | ||
48 | } | ||
diff --git a/src/model/DevisFactures.php b/src/model/DevisFactures.php new file mode 100644 index 0000000..be733dd --- /dev/null +++ b/src/model/DevisFactures.php | |||
@@ -0,0 +1,98 @@ | |||
1 | <?php | ||
2 | // model/DevisFactures.php | ||
3 | |||
4 | class DevisFactures extends Model | ||
5 | { | ||
6 | // lecture des données ou hydratation | ||
7 | private $ID; | ||
8 | private $ID_presta; | ||
9 | private $validite_devis; | ||
10 | private $signature_devis; | ||
11 | private $taches; | ||
12 | private $machine; | ||
13 | private $OS; | ||
14 | private $donnees; | ||
15 | private $cles_licences; | ||
16 | private $total_main_d_oeuvre; | ||
17 | private $pieces; | ||
18 | private $total_pieces; | ||
19 | private $deplacement; | ||
20 | private $total_HT; | ||
21 | |||
22 | public function __construct() | ||
23 | { | ||
24 | $this->table = strtolower(__CLASS__); | ||
25 | } | ||
26 | |||
27 | // setters | ||
28 | public function setID(int $value) | ||
29 | { | ||
30 | $this->ID = $value; | ||
31 | return($this); | ||
32 | } | ||
33 | public function setIDPresta(int $value) | ||
34 | { | ||
35 | $this->ID_presta = $value; | ||
36 | return($this); | ||
37 | } | ||
38 | public function setValiditeDdevis(string $value) | ||
39 | { | ||
40 | $this->validite_devis = $value; | ||
41 | return($this); | ||
42 | } | ||
43 | public function setSignatureDevis(string $value) | ||
44 | { | ||
45 | $this->signature_devis = $value; | ||
46 | return($this); | ||
47 | } | ||
48 | public function setTaches(string $value) | ||
49 | { | ||
50 | $this->taches = $value; | ||
51 | return($this); | ||
52 | } | ||
53 | public function setMachine(string $value) | ||
54 | { | ||
55 | $this->machine = $value; | ||
56 | return($this); | ||
57 | } | ||
58 | public function setOS(string $value) | ||
59 | { | ||
60 | $this->OS = $value; | ||
61 | return($this); | ||
62 | } | ||
63 | public function setDonnees(string $value) | ||
64 | { | ||
65 | $this->donnees = $value; | ||
66 | return($this); | ||
67 | } | ||
68 | public function setClesLicences(string $value) | ||
69 | { | ||
70 | $this->cles_licences = $value; | ||
71 | return($this); | ||
72 | } | ||
73 | public function setTotalMainDOeuvre(float $value) | ||
74 | { | ||
75 | $this->total_main_d_oeuvre = $value; | ||
76 | return($this); | ||
77 | } | ||
78 | public function setPieces(string $value) | ||
79 | { | ||
80 | $this->pieces = $value; | ||
81 | return($this); | ||
82 | } | ||
83 | public function setTotalPieces(float $value) | ||
84 | { | ||
85 | $this->total_pieces = $value; | ||
86 | return($this); | ||
87 | } | ||
88 | public function setDeplacement(float $value) | ||
89 | { | ||
90 | $this->deplacement = $value; | ||
91 | return($this); | ||
92 | } | ||
93 | public function setTotalHT(float $value) | ||
94 | { | ||
95 | $this->total_HT = $value; | ||
96 | return($this); | ||
97 | } | ||
98 | } | ||
diff --git a/src/model/Locations.php b/src/model/Locations.php new file mode 100644 index 0000000..2aa175a --- /dev/null +++ b/src/model/Locations.php | |||
@@ -0,0 +1,74 @@ | |||
1 | <?php | ||
2 | // model/Locations.php | ||
3 | |||
4 | class Locations extends Model | ||
5 | { | ||
6 | // lecture des données ou hydratation | ||
7 | private $ID; | ||
8 | private $ID_presta; | ||
9 | private $nature_bien; | ||
10 | private $modele; | ||
11 | private $valeur; | ||
12 | private $etat_des_lieux_debut; | ||
13 | private $etat_des_lieux_fin; | ||
14 | private $duree_location; | ||
15 | private $loyer_mensuel; | ||
16 | private $total_HT; | ||
17 | |||
18 | public function __construct() | ||
19 | { | ||
20 | $this->table = strtolower(__CLASS__); | ||
21 | } | ||
22 | |||
23 | // setters | ||
24 | public function setID(int $value) | ||
25 | { | ||
26 | $this->ID = $value; | ||
27 | return($this); | ||
28 | } | ||
29 | public function setIDPresta(int $value) | ||
30 | { | ||
31 | $this->ID_presta = $value; | ||
32 | return($this); | ||
33 | } | ||
34 | public function setNatureBien(string $value) | ||
35 | { | ||
36 | $this->nature_bien = $value; | ||
37 | return($this); | ||
38 | } | ||
39 | public function setModele(string $value) | ||
40 | { | ||
41 | $this->modele = $value; | ||
42 | return($this); | ||
43 | } | ||
44 | public function setValeur(float $value) | ||
45 | { | ||
46 | $this->valeur = $value; | ||
47 | return($this); | ||
48 | } | ||
49 | public function setEtatDesLieuxDebut(string $value) | ||
50 | { | ||
51 | $this->etat_des_lieux_debut = $value; | ||
52 | return($this); | ||
53 | } | ||
54 | public function setEtatDesLieuxFin(string $value) | ||
55 | { | ||
56 | $this->etat_des_lieux_fin = $value; | ||
57 | return($this); | ||
58 | } | ||
59 | public function setDureeLocation(string $value) | ||
60 | { | ||
61 | $this->duree_location = $value; | ||
62 | return($this); | ||
63 | } | ||
64 | public function setlLyerMensuel(float $value) | ||
65 | { | ||
66 | $this->loyer_mensuel = $value; | ||
67 | return($this); | ||
68 | } | ||
69 | public function setTotalHT(float $value) | ||
70 | { | ||
71 | $this->total_HT = $value; | ||
72 | return($this); | ||
73 | } | ||
74 | } | ||
diff --git a/src/model/Model.php b/src/model/Model.php new file mode 100644 index 0000000..ad9e6c7 --- /dev/null +++ b/src/model/Model.php | |||
@@ -0,0 +1,162 @@ | |||
1 | <?php | ||
2 | // php/Model.php | ||
3 | |||
4 | class Model extends DB | ||
5 | { | ||
6 | private $db; // instance de PDO | ||
7 | protected $table; // <= enfant | ||
8 | //static protected $tableStructure; | ||
9 | |||
10 | public function __construct() | ||
11 | { | ||
12 | $this->db = parent::getInstance(); // connexion | ||
13 | } | ||
14 | |||
15 | |||
16 | // setters (plusieurs en même temps) | ||
17 | public function hydrate(array $data) // $data = tableau associatif en entrée: nom_du_champ => valeur | ||
18 | { | ||
19 | foreach($data as $key => $value) | ||
20 | { | ||
21 | // nom d'un setter, forme "setMachin()" | ||
22 | $setterName = 'set' . ucfirst($key); // ucfirst met la première lettre en majuscule | ||
23 | // détection | ||
24 | if(method_exists($this, $setterName)) // on trouve aussi la méthode is_callable() | ||
25 | { | ||
26 | // on renseigne les propriétés des l'instance | ||
27 | $this->$setterName($value); // nom d'une méthode dans une variable | ||
28 | } | ||
29 | } | ||
30 | return($this); | ||
31 | } | ||
32 | |||
33 | |||
34 | // exécuter le SQL | ||
35 | // les attributs correspondent aux ? dans les requêtes préparées | ||
36 | // ne pas surcharger la méthode PDO::query() qui n'est pas compatible | ||
37 | protected function execQuery(string $sql, array $attributes = null) | ||
38 | { | ||
39 | $this->db = parent::getInstance(); // connexion | ||
40 | |||
41 | if($attributes !== null) // requête préparée | ||
42 | { | ||
43 | $query = $this->db->prepare($sql); | ||
44 | $query->execute($attributes); | ||
45 | return $query; | ||
46 | } | ||
47 | else // requête simple | ||
48 | { | ||
49 | return $this->db->query($sql); | ||
50 | } | ||
51 | } | ||
52 | |||
53 | |||
54 | // méthodes CRUD qui marchent (les spécifiques sont dans les classes enfant) | ||
55 | |||
56 | // create INSERT | ||
57 | public function create() // = write | ||
58 | { | ||
59 | $fields = []; | ||
60 | $question_marks = []; // ? | ||
61 | $values = []; | ||
62 | foreach($this as $field => $value) | ||
63 | { | ||
64 | // champs non renseignées et variables de l'objet qui ne sont pas des champs | ||
65 | // note: avec le !== (au lieu de !=) une valeur 0 passe le filtre | ||
66 | if($value !== null && $field != 'db' && $field != 'table') | ||
67 | { | ||
68 | $fields[] = $field; // push | ||
69 | $question_marks[] = '?'; | ||
70 | $values[] = $value; | ||
71 | } | ||
72 | } | ||
73 | $field_list = implode(', ', $fields); | ||
74 | $question_mark_list = implode(', ', $question_marks); | ||
75 | |||
76 | // INSERT INTO annonces (titre, description, actif) VALUES (?, ?, ?) | ||
77 | return($this->execQuery('INSERT INTO ' . $this->table . ' (' . $field_list . ') VALUES (' . $question_mark_list . ')', $values)); | ||
78 | } | ||
79 | |||
80 | |||
81 | // read SELECT | ||
82 | public function readAll() | ||
83 | { | ||
84 | $query = $this->execQuery('SELECT * FROM ' . $this->table . ';'); // fonctionne aussi sans le point virgule dans le SQL!! | ||
85 | return($query->fetchAll()); | ||
86 | } | ||
87 | public function findById(int $id) | ||
88 | { | ||
89 | return($this->execQuery('SELECT * FROM ' . $this->table . ' WHERE id = ' . $id)->fetch()); | ||
90 | } | ||
91 | |||
92 | public function find(array $criteria) | ||
93 | { | ||
94 | $fields = []; | ||
95 | $values = []; | ||
96 | |||
97 | // change "'ID' => 2" en "'ID' = ?" et "2" | ||
98 | foreach($criteria as $field => $value) | ||
99 | { | ||
100 | $fields[] = "$field = ?"; // même chose que: $field . " = ?" | ||
101 | $values[] = $value; | ||
102 | } | ||
103 | $field_list = implode(' AND ', $fields); // créer une chaîne reliant les morceaux avec le morceau AND en paramètre: 'adresse = ? AND ID = ?' | ||
104 | |||
105 | // SELECT * FROM annonces WHERE actif = 1; | ||
106 | return($this->execQuery('SELECT * FROM ' . $this->table . ' WHERE ' . $field_list, $values)->fetchAll()); | ||
107 | } | ||
108 | |||
109 | |||
110 | // update UPDATE | ||
111 | public function update(int $id) | ||
112 | { | ||
113 | $fields = []; | ||
114 | $values = []; | ||
115 | foreach($this as $field => $value) | ||
116 | { | ||
117 | if($value !== null && $field != 'db' && $field != 'table') // champs non renseignées et variables de l'objet qui ne sont pas des champs | ||
118 | { | ||
119 | $fields[] = $field . ' = ?'; | ||
120 | $values[] = $value; | ||
121 | } | ||
122 | } | ||
123 | $values[] = $id; | ||
124 | $field_list = implode(', ', $fields); | ||
125 | |||
126 | // UPDATE annonces SET titre = ?, description = ?, actif = ? WHERE id= ? | ||
127 | return($this->execQuery('UPDATE ' . $this->table . ' SET ' . $field_list . ' WHERE id = ?', $values)); | ||
128 | } | ||
129 | |||
130 | |||
131 | // delete DELETE | ||
132 | public function delete(int $id) | ||
133 | { | ||
134 | return($this->execQuery("DELETE FROM {$this->table} WHERE id = ?", [$id])); // double quotes "" pour insertion de variable, paramètre [$id] parce qu'on veut un tableau | ||
135 | } | ||
136 | |||
137 | |||
138 | // fonction appelée une seule fois pour chaque table | ||
139 | // le tableau nécessaire n'est pas copié en mémoire à l'instanciation (pas de fuite de mémoire), mais uniquement à l'appel de cette fonction statique, à la fin de la fonction la mémoire est libérée | ||
140 | // DBStructure::${self::$tableStructure} permet de nommer une variable statique de classe | ||
141 | static public function createTables() | ||
142 | { | ||
143 | //~ var_dump(StructTablesDB::$structureOfTables); | ||
144 | foreach(StructTablesDB::$structureOfTables as $tableName => $oneTable) | ||
145 | { | ||
146 | //var_dump(StructTablesDB::${self::$tableStructure}); => propriété statique de classe dans une variable | ||
147 | $fields_and_types = []; | ||
148 | $query = 'CREATE TABLE IF NOT EXISTS ' . $tableName . ' ('; | ||
149 | foreach($oneTable as $key => $value) | ||
150 | { | ||
151 | $fields_and_types[] = $key . ' ' . $value; | ||
152 | } | ||
153 | $query .= implode(', ', $fields_and_types); // implode() convertit un tableau en une chaîne avec un séparateur entre chaque élément | ||
154 | $query .= ', PRIMARY KEY(ID AUTOINCREMENT));'; | ||
155 | //echo($query . "\n\n"); | ||
156 | |||
157 | parent::getInstance()->exec($query); // merci singleton! | ||
158 | } | ||
159 | |||
160 | |||
161 | } | ||
162 | } | ||
diff --git a/src/model/Prestations.php b/src/model/Prestations.php new file mode 100644 index 0000000..4f58d70 --- /dev/null +++ b/src/model/Prestations.php | |||
@@ -0,0 +1,62 @@ | |||
1 | <?php | ||
2 | // model/Prestations.php | ||
3 | |||
4 | class Prestations extends Model | ||
5 | { | ||
6 | // lecture des données ou hydratation | ||
7 | private $ID; | ||
8 | private $IDClient; | ||
9 | private $combientieme_fois; | ||
10 | private $code_presta; | ||
11 | private $date; | ||
12 | private $type; | ||
13 | private $mode_paiement; | ||
14 | private $commentaires; | ||
15 | |||
16 | public function __construct() | ||
17 | { | ||
18 | $this->table = strtolower(__CLASS__); | ||
19 | } | ||
20 | |||
21 | // setters | ||
22 | public function setID(int $value) | ||
23 | { | ||
24 | $this->ID = $value; | ||
25 | return($this); | ||
26 | } | ||
27 | public function setIDClient(int $value) | ||
28 | { | ||
29 | $this->ID_client = $value; | ||
30 | return($this); | ||
31 | } | ||
32 | public function setCombientiemeFois(int $value) | ||
33 | { | ||
34 | $this->combientieme_fois = $value; | ||
35 | return($this); | ||
36 | } | ||
37 | public function setCodePresta(string $value) | ||
38 | { | ||
39 | $this->code_presta = $value; | ||
40 | return($this); | ||
41 | } | ||
42 | public function setDate(int $value) | ||
43 | { | ||
44 | $this->date = $value; | ||
45 | return($this); | ||
46 | } | ||
47 | public function setType(string $value) | ||
48 | { | ||
49 | $this->type = $value; | ||
50 | return($this); | ||
51 | } | ||
52 | public function setModePaiement(string $value) | ||
53 | { | ||
54 | $this->mode_paiement = $value; | ||
55 | return($this); | ||
56 | } | ||
57 | public function setCommentaires(string $value) | ||
58 | { | ||
59 | $this->commentaires = $value; | ||
60 | return($this); | ||
61 | } | ||
62 | } | ||
diff --git a/src/model/StructTablesDB.php b/src/model/StructTablesDB.php new file mode 100644 index 0000000..cf6de5d --- /dev/null +++ b/src/model/StructTablesDB.php | |||
@@ -0,0 +1,35 @@ | |||
1 | <?php | ||
2 | // model/StructTablesDB.php | ||
3 | |||
4 | // structure de données façon C | ||
5 | // créer les requêtes avec implode(', ', $DbStructure) | ||
6 | class StructTablesDB | ||
7 | { | ||
8 | // possibilité de lire un fichier JSON | ||
9 | static public $structureOfTables = [ | ||
10 | // la table prestations est liée à la table clients | ||
11 | // les tables devis_factures, cesu et locations sont liées à la table prestations | ||
12 | 'clients' => ['ID' => 'INTEGER', 'prenom_nom' => 'TEXT', 'adresse' => 'TEXT', 'code_client' => 'TEXT', 'commentaires' => 'TEXT'], | ||
13 | 'prestations' => ['ID' => 'INTEGER', 'ID_client' => 'INTEGER', 'combientieme_fois' => 'INTEGER', 'code_presta' => 'TEXT', 'date' => 'INTEGER', 'type' => 'TEXT', 'mode_paiement' => 'TEXT', 'commentaires' => 'TEXT'], | ||
14 | 'devisfactures' => ['ID' => 'INTEGER', 'ID_presta' => 'INTEGER', 'validite_devis' => 'TEXT', 'signature_devis' => 'TEXT', 'taches' => 'TEXT', 'machine' => 'TEXT', 'OS' => 'TEXT', 'donnees' => 'TEXT', 'cles_licences' => 'TEXT', 'total_main_d_oeuvre' => 'REAL', 'pieces' => 'TEXT', 'total_pieces' => 'REAL', 'deplacement' => 'REAL', 'total_HT' => 'REAL'], | ||
15 | 'cesu' => ['ID' => 'INTEGER', 'ID_presta' => 'INTEGER', 'taches' => 'TEXT', 'duree_travail' => 'TEXT', 'salaire' => 'REAL'], | ||
16 | 'locations' => ['ID' => 'INTEGER', 'ID_presta' => 'INTEGER', 'nature_bien' => 'TEXT', 'modele' => 'TEXT', 'valeur' => 'REAL', 'etat_des_lieux_debut' => 'TEXT', 'etat_des_lieux_fin' => 'TEXT', 'duree_location' => 'TEXT', 'loyer_mensuel' => 'REAL', 'total_HT' => 'REAL'] | ||
17 | ]; | ||
18 | |||
19 | // les types de variables de sqlite sont peu nombreux et autorisent un typage automatique | ||
20 | // le "type indiqué" est indiqué dans l'instruction CREATE TABLE | ||
21 | // https://www.leppf.com/site/spip.php?article89 | ||
22 | |||
23 | // || type indiqué || type choisi automatiquement || autre types possibles || | ||
24 | // --------------------------------------------------------------------------- | ||
25 | // || TEXT || TEXT || BLOB, NULL || | ||
26 | // || INTEGER || INTEGER (de 1 à 8 octets) || REAL, TEXT, BLOB, NULL || | ||
27 | // || REAL || REAL (flottant sur 9 octets) || TEXT, BLOB, NULL || | ||
28 | // || NUMERIC || INTEGER ou REAL || TEXT, BLOB, NULL || | ||
29 | // || NONE || indéfini || dépend des données || | ||
30 | |||
31 | // du code SQL écrit pour d'autres SGBD devrait fonctionner, | ||
32 | // sqlite fera des conversions dans ses propres types avec les problèmes qu'on peut imaginer | ||
33 | |||
34 | // pour les dates, on stockera à priori le timestamp | ||
35 | } | ||