-
Notifications
You must be signed in to change notification settings - Fork 0
/
database.py
73 lines (53 loc) · 2.62 KB
/
database.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
import sqlite3
#creation de la table contact
create_table_contact = """ CREATE TABLE IF NOT EXISTs contact(
ID INTEGER PRIMARY KEY AUTOINCREMENT,
Nom TEXT NOT NULL,
Prenom TEXT NOT NULL,
Email TEXT NOT NULL,
Numero_Telephone INTEGER NOT NULL,
Adresse TEXT NOT NULL
);
"""
#inserer un contact
insertion_contact = """INSERT INTO contact ('Nom' , 'Prenom' , 'Email' , 'Numero_telephone' , 'Adresse')
VALUES (? , ? , ? , ? , ?); """
#afficher la liste des contacts
AFFICHER_LISTE_CONTACT = "select * from contact"
#Supprimer un contact via son numero de telephone
SUPPRIMER_CONTACT_TEL ="delete from contact where Numero_Telephone =?"
#Supprimer un contact via son id
SUPPRIMER_CONTACT_ID ="delete from contact where ID =?"
#modifier contact via son id
MODIFIER_CONTACT = "update contact set Numero_Telephone =? where ID=?"
#recherch un contact via son numero de telephone
RECHERCHE_CONTACT ="select Nom ,Prenom from contact where Numero_Telephone =?"
class Connect:
def __init__(self):
self.bd = sqlite3.connect("Moncontact.db")
self.bd.row_factory = sqlite3.Row
self.bd.execute(create_table_contact)
self.bd.commit()
def ajouter_contact(self, Nom,Prenom,Email,Numero_telephone,Adresse):
self.bd.row_factory = sqlite3.Row
self.bd.execute(insertion_contact, (Nom,Prenom,Email,Numero_telephone,Adresse))
self.bd.commit()
def afficher_liste_contact(self):
cursor = self.bd.execute(AFFICHER_LISTE_CONTACT).fetchall()
return cursor
def supprimer_contact_tel(self, Numero_Telephone):
self.bd.row_factory = sqlite3.Row
self.bd.execute(SUPPRIMER_CONTACT_TEL , (Numero_Telephone ,)).fetchall()
self.bd.commit()
def supprimer_contact_id(self, ID):
self.bd.row_factory = sqlite3.Row
self.bd.execute(SUPPRIMER_CONTACT_ID , (ID ,)).fetchall()
self.bd.commit()
def modifier_contact(self, Numero_Telephone, ID):
self.bd.row_factory = sqlite3.Row
self.bd.execute(MODIFIER_CONTACT, (Numero_Telephone, ID)).fetchall()
self.bd.commit()
def recherche_contact(self, Numero_Telephone):
self.bd.row_factory = sqlite3.Row
self.bd.execute(RECHERCHE_CONTACT, (Numero_Telephone,)).fetchall()
self.bd.commit()