Unable to DELETE records using cursor

93 visualizzazioni
Passa al primo messaggio da leggere

tnn...@gmail.com

da leggere,
15 lug 2016, 15:30:5315/07/16
a PyMySQL Users
Hi Team,

I'm using PyMySQL since list week. I found it really useful for my DB operations. But I'm facing some problem with deleting records from user table.
Am I doing something wrong? Please help... the code is given below:

connection = pymysql.connect(host='localhost',
                             user
='root',
                             password
='',
                             db
='sherlock',
                             charset
='utf8mb4')
       
cursor
=  connection.cursor()

cursor
.execute("DELETE FROM users")

Thanks,
Tushar <tnn...@gmail.com>

Naoki INADA

da leggere,
16 lug 2016, 04:39:0016/07/16
a PyMySQL Users
Do you know transaction?

Tushar Niras

da leggere,
16 lug 2016, 05:18:3716/07/16
a PyMySQL Users
No, I wasn't aware about transactions. But did some research and came to know that transactions are used to perform multiple operations (statements) sequentially as a Group.
And PyMySQL uses something like that.

I uses commit() method after query execution. like this:

sql = "DELETE FROM users"
self.cursor.execute(sql)
self.connection.commit()

And this worked for me!!! Is there anything  you would like to mention? Or is there anything I missed?

Thanks,
Tushar
Rispondi a tutti
Rispondi all'autore
Inoltra
0 nuovi messaggi