Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/webpack/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python 哪个游标对象是pyodbc';s`Cursor.execute`returning?_Python_Pyodbc - Fatal编程技术网

Python 哪个游标对象是pyodbc';s`Cursor.execute`returning?

Python 哪个游标对象是pyodbc';s`Cursor.execute`returning?,python,pyodbc,Python,Pyodbc,根据,Cursor.execute没有定义的返回值pyodbc似乎使它返回一个游标对象;医生们也这么说,尽管相当简短: 执行(…) C.execute(sql,[params])-->游标 是否有更详细的保证/记录 查看标识,返回的对象似乎是同一个游标,可能用于链接调用 >>> thing_called_cursor = conn.cursor() >>> result = thing_called_cursor.execute("SELECT * FROM

根据,
Cursor.execute
没有定义的返回值<然而,code>pyodbc似乎使它返回一个游标对象;医生们也这么说,尽管相当简短:

执行(…)
C.execute(sql,[params])-->游标

是否有更详细的保证/记录

查看标识,返回的对象似乎是同一个游标,可能用于链接调用

>>> thing_called_cursor = conn.cursor()
>>> result = thing_called_cursor.execute("SELECT * FROM Item")
>>> result
<pyodbc.Cursor object at 0x10b3290f0>
>>> thing_called_cursor
<pyodbc.Cursor object at 0x10b3290f0>
我可以试着查一下资料来源,但我不想依赖我在那里找到的任何东西。也许最好忽略当前由
游标返回的内容。执行
,因为这样做最符合PEP中的规范?

您可以从中看到,它最终返回
返回(PyObject*)cur
这是首先传递的执行游标。但是,它看起来确实存在返回
0
的情况

看起来这本书也包括在内

DB API规范没有指定 Cursor.execute。pyodbc(2.0.x)的早期版本返回了不同的 值,但2.1版本始终返回光标本身

这允许压缩代码,例如:

for row in cursor.execute("select album_id, photo_id from photos where user_id=1"):
    print row.album_id, row.photo_id

row  = cursor.execute("select * from tmp").fetchone()
rows = cursor.execute("select * from tmp").fetchall()

count = cursor.execute("update photos set processed=1 where user_id=1").rowcount
count = cursor.execute("delete from photos where user_id=1").rowcount

因此,它的原因似乎是提倡紧凑的代码。

谢谢,@C.B.。我想,这种实现选择将建立习惯,并可能在返回0(
NULL
?)及其
.rowcount
时产生一些意外的异常。。。
for row in cursor.execute("select album_id, photo_id from photos where user_id=1"):
    print row.album_id, row.photo_id

row  = cursor.execute("select * from tmp").fetchone()
rows = cursor.execute("select * from tmp").fetchall()

count = cursor.execute("update photos set processed=1 where user_id=1").rowcount
count = cursor.execute("delete from photos where user_id=1").rowcount