logo       

[psycopg] #99: Patch for cursor.execute and cursor.executemany to return cu: msg#00001

python.db.psycopg.devel

Subject: [psycopg] #99: Patch for cursor.execute and cursor.executemany to return cursor object

#99: Patch for cursor.execute and cursor.executemany to return cursor object
-------------------------------------------------+--------------------------
Reporter: Miki Tebeka <miki.tebeka@xxxxxxxxx> | Owner: fog
Type: defect | Status: new
Priority: normal | Milestone: PSYCOPG 2.0
Component: psycopg2 | Version: 2.0beta
Severity: patch | Keywords:
-------------------------------------------------+--------------------------
This patch makes `cursor.execute` and `cursor.executemany` return the
cursor object.
This way you can write:
{{{
#!python
for login, in cursor.execute("select login from users"):
print login
}}}

The patch:
{{{
Index: cursor_type.c
===================================================================
--- cursor_type.c (revision 745)
+++ cursor_type.c (working copy)
@@ -395,6 +395,7 @@
{
long int async = 0;
PyObject *vars = NULL, *operation = NULL;
+ PyObject *pyself = NULL;

static char *kwlist[] = {"query", "vars", "async", NULL};

@@ -425,8 +426,9 @@
EXC_IF_CURS_CLOSED(self);

if (_psyco_curs_execute(self, operation, vars, async)) {
- Py_INCREF(Py_None);
- return Py_None;
+ pyself = (PyObject *)self;
+ Py_INCREF(pyself);
+ return pyself;
}
else {
return NULL;
@@ -441,6 +443,7 @@
{
PyObject *operation = NULL, *vars = NULL;
PyObject *v, *iter = NULL;
+ PyObject *pyself = NULL;

static char *kwlist[] = {"query", "vars", NULL};

@@ -473,8 +476,9 @@
}
Py_XDECREF(iter);

- Py_INCREF(Py_None);
- return Py_None;
+ pyself = (PyObject *)self;
+ Py_INCREF(pyself);
+ return pyself;
}

}}}

--
Ticket URL: <http://initd.org/tracker/psycopg/ticket/99>
psycopg <http://initd.org/>
psycopg_______________________________________________
Psycopg mailing list
Psycopg-IAPFreCvJWPBWskQ1e/+sw@xxxxxxxxxxxxxxxx
http://lists.initd.org/mailman/listinfo/psycopg
<Prev in Thread] Current Thread [Next in Thread>
Google Custom Search

News | FAQ | advertise