Python (2.7.3) breaks my mysql connector cursor in some strange way when I return it from a function. This first example works fine ...
cnx = connect() sql = "SELECT * FROM MyTable" cursor = cnx.cursor() cursor.execute(sql) row = cursor.fetchone()
However, if I return the cursor and try fetchone () (or fetchall ()) from the outside, it throws an exception ...
def run_query(): cnx = connect() sql = "SELECT * FROM MyTable" cursor = cnx.cursor() cursor.execute(sql) return cursor mycursor = run_query() row = mycursor.fetchone()
He throws ...
File "/usr/lib/pymodules/python2.7/mysql/connector/cursor.py", line 533, in fetchone row = self._fetch_row() File "/usr/lib/pymodules/python2.7/mysql/connector/cursor.py", line 508, in _fetch_row (row, eof) = self.db().protocol.get_row() AttributeError: 'NoneType' object has no attribute 'protocol'
This is despite the fact that "print type (mycursor)" will print "mysql.connector.cursor.MySQLCursor"
What type of unholy corruption is Python running on objects returned from functions? (Keep in mind that this will be done for the cursors passed in the module ... so this does not look like an object passed from the "import mysql.connector" area ...)
source share