python语言中,对于cursor的查询明明有结果,为什么print cursor.rowcount结果为-1?
来源:互联网 发布:dvi线和vga线的端口 编辑:程序博客网 时间:2024/05/22 15:03
从网上搜了很多资料,没有对口的,抓狂。没办法自己研究了一下,相信写出来能够帮到很多人。
下边是我写的一段代码,为了方便大家看我加了行号。从下边代码中第4行可以看到,rowcount结果为-1,但是从第5行却可以将查询结果打印出来。显然查询是有结果的,为什么rowcount为-1呢?
第1行>>> db = mysql.connector.Connect(host=‘10.1.1.47’, port=2205, user=‘boss’, passwd=‘qwekkk’,charset=utf8,db='PP_01')第2行>>> cursor_pet = db.cursor()第3行>>> cursor_pet.execute('select userid,petid from t_pp_pet_01')第4行>>> print cursor_pet.rowcount-1第5行>>> for list in cursor_pet.fetchall():... print list... (1, 11)(1, 12)(2, 11)(3, 11)(2, 10)(4, 15)
下边是解决方案。我们应该在打印查询行数之前先调用一下fetchall()这个函数,然后行数rowcount就打印出来啦:
第1行>>>db = mysql.connector.Connect(host=‘10.1.1.47’, port=2205, user=‘boss’, passwd=‘qwekkk’,charset=utf8,db='PP_01')第2行>>> cursor_pet = db.cursor()第3行>>> cursor_pet = db.cursor()第4行>>> cursor_pet.execute('select userid,petid from t_pp_pet_01')第5行>>> cursor_pet.fetchall()[(1, 11), (1, 12), (2, 11), (3, 11), (2, 10), (4, 15)]第6行>>> print cursor_pet.rowcount6
- python语言中,对于cursor的查询明明有结果,为什么print cursor.rowcount结果为-1?
- 关于cursor的rowcount
- Oralce中返回结果集的存储过程ref cursor
- cursor中明明有数据,但是moveToNext失败
- mysql数据库,存储过程中如何判断游标Cursor中结果集是否为空
- oralce返回结果集cursor
- Android Cursor返回结果数为0的几种方法
- 使用REF CURSOR处理Oracle的结果集
- 关于PHP中PDO抽象层,采用rowCount();方法出现返回结果为0的解决方案
- ref cursor sys_refcursor传递结果集
- 对于 hibernate 查询结果List 中数据的拷贝。。。。。。。
- 为什么查询结果总为空?
- 查询包含有%的结果
- python中cursor操作数据库
- python中cursor操作数据库
- python中cursor操作数据库
- python中cursor操作数据库
- oracle存储过程中使用Ref Cursor强类型游标返回结果集
- 分治法--用C++实现合并排序
- yii 屏蔽错误提示
- 通过FFmpeg将多媒体文件解码后保存成Bmp图像(YUV420 RGB32)
- 自动kill掉超时的mysql show processlist进程
- 浅谈动态规划法与贪心法和回溯法的联系
- python语言中,对于cursor的查询明明有结果,为什么print cursor.rowcount结果为-1?
- Spring 定时器的时间设置规则
- php判断str是否是xml格式
- /usr/local/php/bin/phpize 时出错 : warning: AC_CACHE_VAL(pdo_inc_path, ...): suspicious cache-id, must
- C# xml模糊查询的实现
- Hive partition 分区表
- yii添加字段后model及视图修改
- android线程池
- 解决 :php 无法定位程序输入点 于动态链接库