Clone wiki

compatibility / mysql-python

MySQL-Python (MySQLdb)

MySQL-Python works with PyPy. New versions (at least 1.2.4c1) work as is, but you may need to apply a small patch for old versions of MySQL-Python. Its test suite runs as successfully on PyPy nightly as on Python 2.7, both needing silencing of PendingDeprecationWarnings to pass. C patch is by Amaury.

There is also a reimplementation of the same API using ctypes, which is known to work under PyPy: https://github.com/quora/mysql-ctypes

Here's the patch.

diff -ru orig/_mysql.c ./_mysql.c
--- orig/_mysql.c       2010-06-17 04:21:56.000000000 -0300
+++ ./_mysql.c  2011-02-08 23:14:34.000000000 -0200
@@ -413,6 +413,7 @@
 					PyObject *pmask=NULL;
 					pmask = PyTuple_GET_ITEM(t, 0);
 					fun2 = PyTuple_GET_ITEM(t, 1);
+					Py_XINCREF(fun2);
 					if (PyInt_Check(pmask)) {
 						mask = PyInt_AS_LONG(pmask);
 						if (mask & fields[i].flags) {
@@ -430,8 +431,10 @@
 			  cleanup:
 				Py_DECREF(t);
 			}
-			if (!fun2) fun2 = Py_None;
-			Py_INCREF(fun2);
+			if (!fun2) {
+				fun2 = Py_None;
+				Py_INCREF(fun2);
+			}
 			Py_DECREF(fun);
 			fun = fun2;
 		}
@@ -1054,7 +1057,9 @@
 				"no default type converter defined");
 		goto error;
 	}
+	Py_INCREF(d);
 	quoted = PyObject_CallFunction(itemconv, "OO", item, d);
+	Py_DECREF(d);
 	Py_DECREF(itemconv);
 error:
 	return quoted;
@@ -2786,6 +2791,9 @@
 	if (!(e = PyDict_GetItemString(edict, name)))
 		return NULL;
 	if (PyDict_SetItemString(dict, name, e)) return NULL;
+#ifdef PYPY_VERSION
+	Py_INCREF(e);
+#endif
 	return e;
 }
 
diff -ru orig/MySQLdb/converters.py ./MySQLdb/converters.py
--- orig/MySQLdb/converters.py  2010-06-17 04:21:56.000000000 -0300
+++ ./MySQLdb/converters.py     2011-02-08 23:21:44.000000000 -0200
@@ -39,6 +39,10 @@
 import array

 try:
+    array.ArrayType
+except AttributeError:
+    array.ArrayType = array.array
+try:
     set
 except NameError:
     from sets import Set as set
diff -ru orig/tests/capabilities.py ./tests/capabilities.py
--- orig/tests/capabilities.py  2010-06-17 04:21:55.000000000 -0300
+++ ./tests/capabilities.py     2011-02-08 23:10:26.000000000 -0200
@@ -8,7 +8,8 @@
 from time import time
 import array
 import unittest
-
+import warnings
+warnings.simplefilter("ignore")

 class DatabaseTest(unittest.TestCase):

diff -ru orig/tests/dbapi20.py ./tests/dbapi20.py
--- orig/tests/dbapi20.py       2010-06-17 04:21:55.000000000 -0300
+++ ./tests/dbapi20.py  2011-02-08 23:10:34.000000000 -0200
@@ -17,7 +17,8 @@

 import unittest
 import time
-
+import warnings
+warnings.simplefilter("ignore")
 # $Log$
 # Revision 1.1.2.1  2006/02/25 03:44:32  adustman
 # Generic DB-API unit test module
diff -ru orig/tests/test_MySQLdb_capabilities.py ./tests/test_MySQLdb_capabilities.py
--- orig/tests/test_MySQLdb_capabilities.py     2010-06-17 04:21:55.000000000 -0300
+++ ./tests/test_MySQLdb_capabilities.py        2011-02-08 23:10:51.000000000 -0200
@@ -4,7 +4,7 @@
 import MySQLdb
 import warnings

-warnings.filterwarnings('error')
+warnings.filterwarnings('ignore')

 class test_MySQLdb(capabilities.DatabaseTest):

diff -ru orig/tests/test_MySQLdb_dbapi20.py ./tests/test_MySQLdb_dbapi20.py
--- orig/tests/test_MySQLdb_dbapi20.py  2010-06-17 04:21:55.000000000 -0300
+++ ./tests/test_MySQLdb_dbapi20.py     2011-02-08 23:10:58.000000000 -0200
@@ -2,7 +2,8 @@
 import dbapi20
 import unittest
 import MySQLdb
-
+import warnings
+warnings.simplefilter("ignore")
 class test_MySQLdb(dbapi20.DatabaseAPI20Test):
     driver = MySQLdb
     connect_args = ()
diff -ru orig/tests/test_MySQLdb_nonstandard.py ./tests/test_MySQLdb_nonstandard.py
--- orig/tests/test_MySQLdb_nonstandard.py      2010-06-17 04:21:55.000000000 -0300
+++ ./tests/test_MySQLdb_nonstandard.py 2011-02-08 23:11:03.000000000 -0200
@@ -3,7 +3,8 @@
 import _mysql
 import MySQLdb
 from MySQLdb.constants import FIELD_TYPE
-
+import warnings
+warnings.simplefilter("ignore")

 class TestDBAPISet(unittest.TestCase):
     def test_set_equality(self):

URL:http://mysql-python.sourceforge.net/
Category:DB adaptors
Compatible:Compatible

Updated