""" version info: mysql-python-test-1.1.8 Python 2.4 (#1, Jan 2 2005, 09:38:24) [GCC 3.3.3 20040412 (Red Hat Linux 3.3.3-7)] on linux2 mysql client and server 4.1.7-standard. server is Linux (FC2) Kernel 2.6.5-1.358 """ import MySQLdb from MySQLdb.constants import CLIENT from MySQLdb.cursors import BaseCursor, Cursor, CursorTupleRowsMixIn from MySQLdb.cursors import CursorUseResultMixIn, CursorStoreResultMixIn from MySQLdb import escape_string class CursorStoreResultMixIn2(CursorStoreResultMixIn): def nextset(self): """Advance to the next result set. Returns None if there are no more result sets. The only change to this method is the addition of the two lines that trigger the row fetch from the result set. this mirrors the behaviour in CursorStoreResultMixIn._query (which is only called once.) """ if self._executed: self.fetchall() del self.messages[:] db = self._get_db() nr = db.next_result() if nr == -1: return None self._do_get_result() # compliment what hapens in CursorStoreResultMixIn _query override. self._rows = self._fetch_row(0) self._result = None self._warning_check() return 1 class CursorStandardUseResults(CursorUseResultMixIn, CursorTupleRowsMixIn, BaseCursor): pass class CursorTweakedStoreResults(CursorStoreResultMixIn2, CursorTupleRowsMixIn, BaseCursor): pass def tests(): results1 = test1(cursorclass=Cursor, **connectionParams) results2 = test2(cursorclass=Cursor, **connectionParams) results3 = test2(cursorclass=CursorStandardUseResults, **connectionParams) results4 = test2(cursorclass=CursorTweakedStoreResults, **connectionParams) print results1 print results2 print results3 print results4 def test1(**connect): stmt = """\ set @a=1; set @b=2; select @a,@b;""" conn = MySQLdb.connect(**connect) c = conn.cursor() c.execute(stmt) results = [] while 1: results.append(c._rows) if c.nextset() is None: return results c._rows = c._fetch_row(0) def test2(**connect): stmt = """\ set @a=1; set @b=2; select @a,@b;""" conn = MySQLdb.connect(**connect) c = conn.cursor() c.execute(stmt) results = [] while 1: results.append(c.fetchall()) if c.nextset() is None: return results # ?? mysql_free_result # # I beleive mysql_free_result should be explicitly called in _mysql.c # for the prev result set. http://dev.mysql.com/doc/mysql/en/mysql_next_result.html # It is called in the dealloc method of the ResultObject. AFAIKS both # ConnectionObject use_result and store_result setup a 'fresh' result # obect. Implying that it is determined by the GC when the # mysql_free_result is invoked on the 'old' result. If the requirement # for calling mysql_free_result is in order to clear out result ( # a MYSQL*) before re-using it then this seems fine as _mysql.c is not # resusing (again, afaiks) the result (MYSQL*) object. if __name__ == "__main__": tests()