gpt4 book ai didi

python - 如何检查pyodbc游标是否为空?

转载 作者:行者123 更新时间:2023-12-05 02:07:13 45 4
gpt4 key购买 nike

使用 pyodbc 通过 SELECT 查询 MySQL 数据库。我需要确定查询是否返回任何内容,我发现人们使用的方式是行数,但是经过一些测试后,这总是为我返回 -1。我在游标的 github wiki 上找到了这个,我认为它描述了我的问题。

rowcountThe number of rows modified by the last SQL statement.

This is -1 if no SQL has been executed or if the number of rows is unknown. Note that it is not uncommon for databases to report -1 immediately after a SQL select statement for performance reasons. (The exact number may not be known before the first records are returned to the application.)

我想知道是否有办法解决这个问题,或者是否有其他方法可以做到这一点,谢谢。

最佳答案

我总是检查返回结果的长度

res=newcursor.fetchall()
if len(res)==0:##表示没有结果

关于python - 如何检查pyodbc游标是否为空?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/62029789/

45 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com