Unable to DELETE records using cursor

93 views
Skip to first unread message

tnn...@gmail.com

unread,
Jul 15, 2016, 3:30:53 PM7/15/16
to 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

unread,
Jul 16, 2016, 4:39:00 AM7/16/16
to PyMySQL Users
Do you know transaction?

Tushar Niras

unread,
Jul 16, 2016, 5:18:37 AM7/16/16
to 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
Reply all
Reply to author
Forward
0 new messages