maillist_frogs test@testovich.com
DELETE FROM 'maillist_frogs' WHERE email LIKE 'test@testovich.com'
Traceback (most recent call last):
File "./compare.py", line 123, in <module>
main()
File "./compare.py", line 117, in main
remove_mailgust = sql_mailgust.removeRow ("maillist_frogs",x)
File "./compare.py", line 81, in removeRow
self.cursor.execute(statmt)
File "build/bdist.macosx-10.6-intel/egg/MySQLdb/cursors.py", line 174, in execute
File "build/bdist.macosx-10.6-intel/egg/MySQLdb/connections.py", line 36, in defaulterrorhandler
_mysql_exceptions.ProgrammingError: (1064, "You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near ''maillist_frogs' WHERE email LIKE 'test@testovich.com'' at line 1")

3 Answers
3

After further research, I realized I'd forgotten to do a connection.commit() after the delete, or, as I found somewhere else, you could just do cursor.execute("set autocommit = 1") before doing any other data operations to have them automatically committed right away, if you don't need control over transactions commits.

This could have been the trouble with Cmag's code, though without seeing more, it's hard to tell.

By the way, using string formatting on MySQLdb queries exposes you to SQL injection in case you're going to use your application on the Web or something. You should not be using string formatting to create queries.

But no exceptions get raised? The cursor.execute call should return the number of rows deleted, could you print that and check it? Can you double-check that the records do exist in the DB?
–
Thomas Orozco♦Jan 1 '12 at 20:56

the script at first compares the databases, so yes, records exist for sure
–
CmagJan 1 '12 at 21:03

Well, I tried using your code, it works for me, so your problem is probably somewhere in the DB, did you double-check it? Do you have the necessary permissions? Maybe you could try doing it using MySQL's CLI? Are you sure remove, and x[0] are what you expect? It seems strange that the cursor.execute call would return None given that if no rows are deleted, it returns 0, is everything OK there?
–
Thomas Orozco♦Jan 1 '12 at 21:08