|
From: Yuval T. <yu...@il...> - 2003-10-26 18:31:49
|
Hello everyone -
I've been testing the module extensively in the past few days using the
following code:
import DB2,sys,random
for x in range(5000):
conn = DB2.Connect('uvrerch','db2rerch','db2rerch')
curs = conn.cursor()
id = random.randint(0, 500)
curs.execute("SELECT * FROM MYTABLE WHERE ID=%d" % id)
Here are some comments:
1. In line 414 - default autocommit mode was changed to "no auto
commit" - this change causes the select query to consume plenty of
memory. Of course, if I add a conn.commit() after the execute statement
(or call conn.autocommit(1) after creating the connection object), the
memory is stable. Is this the kind of behaviour that we want? I mean
"commit" is meant to be called only after inserts, no ?
2. In the dealloc functions (for both cursor, and connection objects)
we call PyMem_DEL after we initialized those objects with PyObject_NEW.
According to the python api, objects should be deleted using PyObject_DEL.
3. In DB2_connection_object_cursor (line 666 :-), there's a commented
out call to Py_INCREF(self) right after the assignment of cursor->conn =
self. If we want to make sure that the connection object stays alive
while the cursor is alive, we must call incref ( and decref upon
destruction ).
4. We clear the cursor data prior to fetching instead of after fetching
- this can cause leaks. After we converted the data to pyobjects, we
need to clear the data. So, to fix this (potential) problem I did the
following:
A. I changed the name of DB2_cursor_object_fetchone to
DB2_cursor_object_do_fetch, and created the following new wrapper function:
static PyObject *
DB2_cursor_object_fetchone(DB2CursorObject *self, PyObject *args)
{
PyObject *pRet = DB2_cursor_object_do_fetch(self, args);
DB2_cursor_object_clear_data(self);
return pRet;
}
B. In fetchall and fetchmany, I changed the calls from fetchone to
do_fetch, and added a calls to DB2_cursor_object_clear_data(self); at
the end of the loops.
That's what I got till now.
I have those code changes - and I'm currently testing them. They're looking good.
If you want me to commit those changes to the CVS, then drop me a note.
--
Yuval Turgeman
Content Technology, Aduva LTD.
|