mirror of
https://github.com/psycopg/psycopg2.git
synced 2025-02-07 12:50:32 +03:00
DictCursor fixes again.
This commit is contained in:
parent
818caa5637
commit
988095298e
|
@ -1,3 +1,8 @@
|
||||||
|
2004-11-20 Federico Di Gregorio <fog@debian.org>
|
||||||
|
|
||||||
|
* psycopg/connection_type.c (psyco_conn_cursor): renamed 'cursor'
|
||||||
|
argument to 'cursor_factory'.
|
||||||
|
|
||||||
2004-11-19 Federico Di Gregorio <fog@debian.org>
|
2004-11-19 Federico Di Gregorio <fog@debian.org>
|
||||||
|
|
||||||
* psycopg/cursor_type.c (_psyco_curs_buildrow_fill): now standard
|
* psycopg/cursor_type.c (_psyco_curs_buildrow_fill): now standard
|
||||||
|
|
|
@ -20,30 +20,34 @@ class DictCursor(_cursor):
|
||||||
__query_executed = 0
|
__query_executed = 0
|
||||||
|
|
||||||
def execute(self, query, vars=None, async=0):
|
def execute(self, query, vars=None, async=0):
|
||||||
self.tuple_factory = DictRow
|
self.row_factory = DictRow
|
||||||
self.index = {}
|
self.index = {}
|
||||||
self.__query_executed = 1
|
self.__query_executed = 1
|
||||||
return _cursor.execute(self, query, vars, async)
|
return _cursor.execute(self, query, vars, async)
|
||||||
|
|
||||||
def _build_index(self):
|
def _build_index(self):
|
||||||
if self.description:
|
if self.__query_executed == 1 and self.description:
|
||||||
for i in range(len(self.description)):
|
for i in range(len(self.description)):
|
||||||
self.index[self.description[i][0]] = i
|
self.index[self.description[i][0]] = i
|
||||||
|
self.__query_executed = 0
|
||||||
|
|
||||||
def fetchone(self):
|
def fetchone(self):
|
||||||
|
res = _cursor.fetchone(self)
|
||||||
if self.__query_executed:
|
if self.__query_executed:
|
||||||
self._build_index()
|
self._build_index()
|
||||||
return _cursor.fetchone(self)
|
return res
|
||||||
|
|
||||||
def fetchmany(self, size=None):
|
def fetchmany(self, size=None):
|
||||||
|
res = _cursor.fetchmany(self, size)
|
||||||
if self.__query_executed:
|
if self.__query_executed:
|
||||||
self._build_index()
|
self._build_index()
|
||||||
return _cursor.fetchmany(self, size)
|
return res
|
||||||
|
|
||||||
def fetchall(self):
|
def fetchall(self):
|
||||||
|
res = _cursor.fetchall(self)
|
||||||
if self.__query_executed:
|
if self.__query_executed:
|
||||||
self._build_index()
|
self._build_index()
|
||||||
return _cursor.fetchall(self)
|
return res
|
||||||
|
|
||||||
class DictRow(list):
|
class DictRow(list):
|
||||||
"""A row object that allow by-colun-name access to data."""
|
"""A row object that allow by-colun-name access to data."""
|
||||||
|
@ -51,7 +55,6 @@ class DictRow(list):
|
||||||
def __init__(self, cursor):
|
def __init__(self, cursor):
|
||||||
self._cursor = cursor
|
self._cursor = cursor
|
||||||
self[:] = [None] * len(cursor.description)
|
self[:] = [None] * len(cursor.description)
|
||||||
print cursor, self
|
|
||||||
|
|
||||||
def __getitem__(self, x):
|
def __getitem__(self, x):
|
||||||
if type(x) != int:
|
if type(x) != int:
|
||||||
|
|
|
@ -48,7 +48,7 @@ psyco_conn_cursor(connectionObject *self, PyObject *args, PyObject *keywds)
|
||||||
char *name = NULL;
|
char *name = NULL;
|
||||||
PyObject *obj, *factory = 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,
|
if (!PyArg_ParseTupleAndKeywords(args, keywds, "|sO", kwlist,
|
||||||
&name, &factory)) {
|
&name, &factory)) {
|
||||||
|
|
Loading…
Reference in New Issue
Block a user