From b300cd2550399a676d7e639c7adcd1f82632cfb9 Mon Sep 17 00:00:00 2001 From: Federico Di Gregorio Date: Thu, 2 Jun 2005 04:30:31 +0000 Subject: [PATCH] Fixed .execute() segfault. --- ChangeLog | 5 +++++ psycopg/cursor_type.c | 6 ++++++ tests/types_basic.py | 8 ++++++++ 3 files changed, 19 insertions(+) diff --git a/ChangeLog b/ChangeLog index 0d775798..3da6e54b 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,8 @@ +2005-06-02 Federico Di Gregorio + + * psycopg/cursor_type.c (_psyco_curs_execute): fixed segfault when + not passing string or unicode to .execute(). + 2005-05-31 Federico Di Gregorio * psycopg/cursor_type.c (_psyco_curs_execute): if a diff --git a/psycopg/cursor_type.c b/psycopg/cursor_type.c index b2a05d70..ba139cfb 100644 --- a/psycopg/cursor_type.c +++ b/psycopg/cursor_type.c @@ -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); diff --git a/tests/types_basic.py b/tests/types_basic.py index 64f2c878..8612739c 100644 --- a/tests/types_basic.py +++ b/tests/types_basic.py @@ -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."""