-3

I don't know Syntax Error. and if can't delete then rollback data.maybe you can advise me

#!/usr/bin/python
import mysql.connector

conn= mysql.connector.connect(host='localhost',user='user',passwd='pwd',db='dest')
cursor = conn.cursor()

sql =  "DELETE FROM dt WHERE user1 > "%d" % (60)
try:
        try:
                cursor.execute(sql)
                conn.commit()
        except:
                conn.rollback()
except:
        print "Error connect"

if conn:
        conn.close()
bod114
  • 1
  • 3

2 Answers2

1

There's a syntax error in sql =. It should be like.

sql = "DELETE FROM dt WHERE user1 > '%d' "% (60)

Hope this helps.

Harv
  • 446
  • 5
  • 12
  • If i want to delete several table. How to delete several tables. – bod114 Oct 10 '16 at 06:07
  • Try to use like this. DROP TABLE table1, table2, table3 Hope this helps. – Harv Oct 10 '16 at 06:11
  • Sorry,i want to delete table1(row1)=step1,table2(row1)=step2,table3(row1)=step3. so delete together but process delete error step any. such as delete step1=sucess step2=sucess but step3 error if error give rollback data. can you advise and thank you everything – bod114 Oct 10 '16 at 06:18
-2

To drop 3 tables, Try to use like this.

DROP TABLE table1, table2, table3

Hope this helps.

Harv
  • 446
  • 5
  • 12
  • Sorry,i want to delete table1(row1)=step1,table2(row1)=step2,table3(row1)=step3. so delete together but process delete error step any. such as delete step1=sucess step2=sucess but step3 error if error give rollback data. can you advise and thank you everything – bod114 Oct 10 '16 at 06:18
  • Then try to use them in different lines and commit () after each step. There will be no rollback for all the steps. Hope this helps. – Harv Oct 10 '16 at 06:23
  • i will try thx. – bod114 Oct 10 '16 at 06:38
  • Bro! i can chat private with you ?. I have question many. facebook? – bod114 Oct 10 '16 at 06:44
  • i has code Python `sql = "DELETE FROM dt WHERE user1 = 1"` want to delete 1row. data in mysql user1 has data user1(INT,PK),ipadd,user2,sipadd. then i need to delete but don't work – bod114 Oct 10 '16 at 07:51