From 988095298eb32eb2a52fefa174f052e7624a6be7 Mon Sep 17 00:00:00 2001 From: Federico Di Gregorio Date: Fri, 19 Nov 2004 15:50:57 +0000 Subject: [PATCH] DictCursor fixes again. --- ChangeLog | 5 +++++ lib/extras.py | 17 ++++++++++------- psycopg/connection_type.c | 2 +- 3 files changed, 16 insertions(+), 8 deletions(-) diff --git a/ChangeLog b/ChangeLog index 8756906b..8f75da70 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,8 @@ +2004-11-20 Federico Di Gregorio + + * psycopg/connection_type.c (psyco_conn_cursor): renamed 'cursor' + argument to 'cursor_factory'. + 2004-11-19 Federico Di Gregorio * psycopg/cursor_type.c (_psyco_curs_buildrow_fill): now standard diff --git a/lib/extras.py b/lib/extras.py index b9532f9e..39f9caa1 100644 --- a/lib/extras.py +++ b/lib/extras.py @@ -20,30 +20,34 @@ class DictCursor(_cursor): __query_executed = 0 def execute(self, query, vars=None, async=0): - self.tuple_factory = DictRow + self.row_factory = DictRow self.index = {} self.__query_executed = 1 return _cursor.execute(self, query, vars, async) def _build_index(self): - if self.description: + if self.__query_executed == 1 and self.description: for i in range(len(self.description)): self.index[self.description[i][0]] = i - + self.__query_executed = 0 + def fetchone(self): + res = _cursor.fetchone(self) if self.__query_executed: self._build_index() - return _cursor.fetchone(self) + return res def fetchmany(self, size=None): + res = _cursor.fetchmany(self, size) if self.__query_executed: self._build_index() - return _cursor.fetchmany(self, size) + return res def fetchall(self): + res = _cursor.fetchall(self) if self.__query_executed: self._build_index() - return _cursor.fetchall(self) + return res class DictRow(list): """A row object that allow by-colun-name access to data.""" @@ -51,7 +55,6 @@ class DictRow(list): def __init__(self, cursor): self._cursor = cursor self[:] = [None] * len(cursor.description) - print cursor, self def __getitem__(self, x): if type(x) != int: diff --git a/psycopg/connection_type.c b/psycopg/connection_type.c index 376b7e67..1d544f6e 100644 --- a/psycopg/connection_type.c +++ b/psycopg/connection_type.c @@ -48,7 +48,7 @@ psyco_conn_cursor(connectionObject *self, PyObject *args, PyObject *keywds) char *name = NULL; PyObject *obj, *factory = NULL; - static char *kwlist[] = {"name", "factory", NULL}; + static char *kwlist[] = {"name", "cursor_factory", NULL}; if (!PyArg_ParseTupleAndKeywords(args, keywds, "|sO", kwlist, &name, &factory)) {