def getCursor(self,renew=True,klass=None):
'''
returns the Cursor for the database
renew will force the creation of a new cursor object
klass may be any of MySQLdb.cursors classes (e.g. DictCursor)
MySQLdb.cursors.SSCursor allows to minimize mem usage in clients (although it relies memory cleanup to the server!)
'''
try:
if klass in ({},dict):
klass = MySQLdb.cursors.DictCursor
if (renew or klass) and self._cursor:
if not self._recursion:
self._cursor.close()
del self._cursor
if renew or klass or not self._cursor:
self._cursor = self.db.cursor(self.default_cursor) if klass is None else self.db.cursor(cursorclass=klass)
return self._cursor
except:
print traceback.format_exc()
self.renewMySQLconnection()
self._recursion += 1
return self.getCursor(renew=True,klass=klass)
评论列表
文章目录