python - Which cursor object is pyodbc's `Cursor.execute` returning? -


according pep249, cursor.execute has no defined return values. pyodbc, however, seems make return cursor object; docs so, too, albeit rather briefly:

execute(...)
c.execute(sql, [params]) --> cursor

is guaranteed/documented somewhere in more detail?

looking @ identities, object returned appears same cursor, perhaps chaining calls?

>>> thing_called_cursor = conn.cursor() >>> result = thing_called_cursor.execute("select * item") >>> result <pyodbc.cursor object @ 0x10b3290f0> >>> thing_called_cursor <pyodbc.cursor object @ 0x10b3290f0> 

also,

>>> id(result) 4482830576 >>> id(thing_called_cursor) 4482830576 

i try looking sources, i'd rather not depend on find there. perhaps best ignore whatever being returned cursor.execute doing best meets specification in pep?

you can see source @ end returns return (pyobject*)cur; cursor execute passed in first place. however, there cases returns 0.

it looks covered in readme.md well

the db api specification not specify return value of cursor.execute. previous versions of pyodbc (2.0.x) returned different values, 2.1 versions return cursor itself.

this allows compact code such as:

for row in cursor.execute("select album_id, photo_id photos user_id=1"):     print row.album_id, row.photo_id  row  = cursor.execute("select * tmp").fetchone() rows = cursor.execute("select * tmp").fetchall()  count = cursor.execute("update photos set processed=1 user_id=1").rowcount count = cursor.execute("delete photos user_id=1").rowcount 

so looks reason advocating compact code.


Comments

Popular posts from this blog

shopping cart - Page redirect not working PHP -

php - How to modify a menu to show sub-menus -

python - Installing PyDev in eclipse is failed -