[Tutor] Overriding MySQLdb.cursors.DictCursor.execute()

Tim Johnson tim at johnsons-web.com
Sat Aug 8 04:18:57 CEST 2009


Hello:
I am currently using python 2.5 and do a lot of database programming
with MySQLdb.
I have developed a wrapper class that uses two cursors:
1)a MySQLdb.cursors.DictCursor object
2)a MySQLdb.cursors.Cursor object
#1 returning a dictionary from query results, #2 returning a tuple
from query results - :) but you all know that.

I need to tighten up control over queries since I am concerned about
malicious injections.
It would seem to me that overriding the execute() methods for both
objects would entail the least amount of code maintenance and
modification. I've used python for a long time, but not done much
with object inheritance. 
The following code:
class mysql_row_cursor(MySQLdb.cursors.DictCursor):
	def __init__(self):
			pass
# results in the following error message:
    class mysql_row_cursor(MySQLdb.cursors.DictCursor):
	AttributeError: 'module' object has no attribute 'cursors'
# say what? MySQLdb has been imported...
I would welcome both comments on why I am getting this error
message and whether my original thinking is correct.
thanks -- forever and always a noob --
-- 
Tim 
tim at johnsons-web.com
http://www.akwebsoft.com


More information about the Tutor mailing list