[Zope] - ZMySQLDA/MySQLmodule.c: Bugs and fixes
Mitch Chapman
mchapman@OEE.com
Fri, 22 Jan 1999 19:00:43 -0500
This is a multi-part message in MIME format.
--------------61074178D370C0D76045FF40
Content-Type: text/plain; charset=us-ascii
Content-Transfer-Encoding: 7bit
This really concerns MySQLmodule.c, not ZMySQLDA per se.
But I found these problems while working w. Zope, so thought
it best to address the Zope list too.
Problem 1:
When compiling against MySQL 3.22.14b-gamma, this warning is
displayed:
./MySQLmodule.c: In function `pythonify_row':
./MySQLmodule.c:199: warning: assignment from incompatible pointer type
Cause:
mysql_fetch_lengths() returns 'unsigned long *'. The
result is being assigned to 'unsigned int *'. Not a problem
on many 32-bit platforms, but what the hey.
Problem 2:
When attempting to do an invalid database insert
(e.g. inserting with a duplicate key value), Python dumps
core.
Cause:
In function DBH_query(), not all fields of sth are properly
initialized. When a database insert fails, sth->res has a
random value. The subsequent free(self->res) in STH_dealloc()
generates a bus error.
The attached context diff contains the fixes I used.
Lemme know if you have any questions/corrections.
--
Mitch Chapman | 4105 Executive Drive
Ohio Electronic Engravers, Inc. | Beavercreek, OH 45430
mchapman@oee.com | import StandardDisclaimer
--------------61074178D370C0D76045FF40
Content-Type: text/plain; charset=us-ascii;
name="MySQLmodule.diff"
Content-Transfer-Encoding: 7bit
Content-Disposition: inline;
filename="MySQLmodule.diff"
*** MySQLmodule.c Tue Dec 22 12:34:23 1998
--- MySQLmodule.c.patched Fri Jan 22 18:33:43 1999
***************
*** 193,199 ****
PyObject *rowlist, *fieldobj;
MYSQL_FIELD *tf;
int i, n;
! unsigned int *lengths;
n = mysql_num_fields(res);
lengths = mysql_fetch_lengths(res);
--- 193,199 ----
PyObject *rowlist, *fieldobj;
MYSQL_FIELD *tf;
int i, n;
! unsigned long *lengths;
n = mysql_num_fields(res);
lengths = mysql_fetch_lengths(res);
***************
*** 902,907 ****
--- 902,908 ----
if (sth == NULL) return NULL;
sth->sth_use_result = self->dbh_use_result;
sth->dbh = NULL;
+ sth->res = NULL;
if (!PyArg_ParseTuple(args, "s#|i:query", &query, &size, &(sth->sth_use_result))) {
Py_XDECREF(sth);
return NULL;
--------------61074178D370C0D76045FF40--