pyodbc rowcount 只返回 -1 [英] pyodbc rowcount only returns -1
问题描述
行计数是如何工作的.我正在使用 pyodbc,它总是返回 -1.
How does rowcount work. I am using pyodbc and it's always returning -1.
return_query = conn.query_db_param(query, q_params)
print(return_query.rowcount)
def query_db_param(self, query, params):
self.cursor.execute(query,params)
print(self.cursor.rowcount)
推荐答案
rowcount
指的是上次操作影响的行数.所以,如果你做一个 insert
并且只插入一行,那么它会返回 1.如果你更新 200 行,那么它会返回 200.另一方面,如果你 SELECT
,最后一个操作并没有真正影响行,它是一个结果集.在这种情况下,0
将在语法上不正确,因此接口返回 -1
.
rowcount
refers to the number of rows affected by the last operation. So, if you do an insert
and insert only one row, then it will return 1. If you update 200 rows, then it will return 200. On the other hand, if you SELECT
, the last operation doesn't really affect rows, it is a result set. In that case, 0
would be syntactically incorrect, so the interface returns -1
instead.
对于执行设置变量或使用创建/更改命令等操作的操作,它还将返回 -1
.
It will also return -1
for operations where you do things like set variables or use create/alter commands.
这篇关于pyodbc rowcount 只返回 -1的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!