| 12
 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
 
 |  
# -*- coding: cp1252 -*-
import MySQLdb
class employe:
    def __init__(self, db):
        self.db = db
        self.cursor = db.cursor()
 
    # Creation d'un nouvel employé
    def creer(self, matricule, patronyme, prenom, date_embauche, salaire, emploi_id, poste_id, unite_id):
        t = (matricule, patronyme, prenom, date_embauche, salaire, emploi_id, poste_id, unite_id)
        self.cursor.execute('INSERT INTO employe VALUES( %s, %s, %s, %s, %s, %s, %s, %s)',t)
        self.db.commit();
 
    # Modification d'un employé
    def modifier(self, matricule, patronyme, prenom, date_embauche, salaire, emploi_id, poste_id, unite_id):
        t = (patronyme, prenom, date_embauche, salaire, emploi_id, poste_id, unite_id, matricule) 
        self.cursor.execute('UPDATE employe SET patronyme = %s, prenom = %s, date_embauche = %s \
                             , salaire = %s, emploi_id = %s, poste_id = %s, unite_id = %s where matricule = %s', t)
        self.db.commit();
        pass
    # Suppression d'un employé
    def supprimer(self, matricule):
        self.cursor.execute('DELETE FROM employe WHERE matricule = %s', matricule)
        self.db.commit();
 
    # récuperation des informations d'un employé suivant un matricule
    def lecture(self,matricule):
        self.cursor.execute('select * from employe where matricule = %s', matricule)
        numrows = int(self.cursor.rowcount)
        # get and display one row at a time
        for x in range(0,numrows):
            row = self.cursor.fetchone()
            print row[0], "-", row[1], "-", row[2], "-", row[3]
 
mydb = MySQLdb.connect(host="localhost", user="root", passwd="XXXX", db="base")
x = employe(mydb)
x.creer('AAAAA','AAAA','aaaa','2009-05-15', 15000.0, 1, 4, 1)
x.modifier('AAAAA','AAAAAA','aaaaa','2009-05-15', 15000.0, 1, 4, 1)
x.lecture('AAAAA')
x.supprimer('AAAAA') |