|
Re: #99: Patch for cursor.execute and cursor.executemany to return cursor o: msg#00004python.db.psycopg.devel
I assume that you really meant to write this: His example would work : a cursor is an iterable which yields rows : for id, login in cursor.execute("select id, login from users"): print id, login would print the ids and logins of all users. for id, login in cursor.execute("select id, login from users").fetchone(): print id, login would fail, because fetchone() would return one [id_value, login_value]. Now I'd like this : for id, login in cursor("select id, login from users"): print id, login I find the DBAPI way a bit kludgey... When I only need 1 cursor for quick scripts, I use some helper function which does this. def Query( sql, *args ): cursor.execute( sql, args ) return cursor.fetchall() for id, login in Query( "blah" ): ... Oh, and by the way : thanks for psycopg. The speed of this thing is insane. FYI the postgres driver for PHP is about 10 times slower, without doing any object adaptation.
|
|
| <Prev in Thread] | Current Thread | [Next in Thread> |
|---|---|---|
| Previous by Date: | Re: #99: Patch for cursor.execute and cursor.executemany to return cursor object: 00004, Tim Roberts |
|---|---|
| Next by Date: | Bug report with dictcursor: 00004, PFC |
| Previous by Thread: | Re: #99: Patch for cursor.execute and cursor.executemany to return cursor objecti: 00004, Tim Roberts |
| Next by Thread: | Re: #99: Patch for cursor.execute and cursor.executemany to return cursor object: 00004, Markus Bertheau |
| Indexes: | [Date] [Thread] [Top] [All Lists] |
| News | FAQ | advertise |