0

Helo ,

I am working actualy on a function that delete a row from a table in a database , it works good with this python code :

def supprimer():
            global rows
            global element
            global listelement
            idsupprvar = idsuppr_entry.get()
            db = MySQLdb.connect(host = "localhost", user = "user", passwd = "123456",db = "users",charset = "utf8" , use_unicode=True) 
            curs = db.cursor()
            #curs.execute('SELECT idpersonne FROM parcinfo;')
            #rows = curs.fetchall()
            #if rows :                
               # for z in rows:
                 #   if idsupprvar == z[0] :
            print idsupprvar
            curs.execute("DELETE FROM users.parcinfo WHERE idpersonne = %s"%(idsupprvar))
            curs.close()
            db.commit()
            lab1.config(text="l'enregistrement dont l'id = '%s' a été bien supprimé de la base de données"%(idsupprvar))
            idsuppr_entry.delete(0,END)
            labsupprimer.config(text="Pour supprimer un autre enregistrement , saisir son id puis cliquer sur supprimer")

my question is how to check if the "idpersonne" exist before deleting it row .

1
Contributor
1
Reply
19
Views
4 Years
Discussion Span
Last Post by Ismatus3
0

Hello again , the problem was , that the elements of the colomne "idpersonne" are long integers , and that add an "L" after elements , now after having a list of elements of the the colomne "idpersonne" how can i check if the received value exist in the list , i tried :

if idsupprvar in tmp :
               curs.execute("DELETE FROM Users.parcinfo WHERE idpersonne = %s"%(idsupprvar))
               curs.close()
               db.commit()
               lab1.config(text="l'enregistrement dont l'id = '%s' a été bien supprimé de la base de données"%(idsupprvar))
               idsuppr_entry.delete(0,END)
               labsupprimer.config(text="Pour supprimer un autre enregistrement , saisir son id puis cliquer sur supprimer")
            else :
               lab1.config(text="l'enregistrement dont l'id = '%s' n'existe pas  dans la base de données"%(idsupprvar))

tmp is the list of elements of the colomne "idpersonne" , that go directly to execute the "else" function !

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.