Fixed .execute() segfault.

This commit is contained in:
Federico Di Gregorio 2005-06-02 04:30:31 +00:00
parent 5322b4e92f
commit b300cd2550
3 changed files with 19 additions and 0 deletions

View File

@ -1,3 +1,8 @@
2005-06-02 Federico Di Gregorio <fog@debian.org>
* psycopg/cursor_type.c (_psyco_curs_execute): fixed segfault when
not passing string or unicode to .execute().
2005-05-31 Federico Di Gregorio <fog@debian.org>
* psycopg/cursor_type.c (_psyco_curs_execute): if a

View File

@ -259,6 +259,12 @@ _psyco_curs_execute(cursorObject *self,
return 0;
}
}
else if (!PyString_Check(operation)) {
/* the operation is not unicode or string, raise an error */
PyErr_SetString(PyExc_TypeError,
"argument 1 must be a string or unicode object");
return 0;
}
IFCLEARPGRES(self->pgres);

View File

@ -52,6 +52,14 @@ class TypesBasicTests(TestCase):
r = str(self.execute("SELECT %s::bytea AS foo", (b,)))
self.failUnless(r == s, "wrong binary quoting")
def testArray(self):
s = self.execute("SELECT %s AS foo", ([[1,2],[3,4]],))
self.failUnless(s == [[1,2],[3,4]], "wrong array quoting " + str(s))
s = self.execute("SELECT %s AS foo", (['one', 'two', 'three'],))
self.failUnless(s == ['one', 'two', 'three'],
"wrong array quoting " + str(s))
class TypesBasicSuite(TestSuite):
"""Build a suite of all tests."""