python操作mysql 抛出Unread result found的处理方法
来源:互联网 发布:网络大电影的宣传 编辑:程序博客网 时间:2024/06/06 20:18
def _select(sql, num, *args):
"""
执行SQL,返回一个结果 或者多个结果组成的列表
"""
cursor.execute(sql, num,args)
d = cursor.fetchall()
vaules = d[0:num]
if cursor.description:
names = [x[0] for x in cursor.description]
if cursor:
cursor.execute(sql, num,args)
#d = cursor.fetchall()
#vaules = d[0:num]
if cursor.description:
names = [x[0] for x in cursor.description]
if cursor:
"""
执行SQL,返回一个结果 或者多个结果组成的列表
"""
try:
if num > 100:
print "num can't big than 100"
return
engine = mysql.connector.connect(user=user, password=password, database=database, host=host, port=port)
cursor = engine.cursor()cursor.execute(sql, num,args)
d = cursor.fetchall()
vaules = d[0:num]
if cursor.description:
names = [x[0] for x in cursor.description]
return [Dict(names, x) for x in vaules]
finally:if cursor:
cursor.close()
定义了一个方法_select(),本意想封装一个方法,方便对mysql的方便操作:返回num条查询结果,但是发觉如果没有对查询结果全部取回的话,会报错:Unread result found,所以如果换成如下的代码就会抛出异常:
try:
if num > 100:
print "num can't big than 100"
return
engine = mysql.connector.connect(user=user, password=password, database=database, host=host, port=port)
cursor = engine.cursor()cursor.execute(sql, num,args)
#d = cursor.fetchall()
#vaules = d[0:num]
if cursor.description:
names = [x[0] for x in cursor.description]
return [Dict(names, x) for x in cursor.fetchmany(num)]
finally:if cursor:
cursor.close()
0 0
- python操作mysql 抛出Unread result found的处理方法
- mysql数据库的unread result found异常
- mysqlconnector-python出现Unread result found错误
- win10,python2.7,mysql-connector-python 报错 mysql.connector.errors.InternalError: Unread result found
- JAVA操作MySQL tImestamp列值为0时抛出异常的处理
- 根据源码分析python列表的插入、抛出操作时当条目索引为负数时的处理
- python操作MySQL数据库的方法分享
- python操作mysql的两个方法
- python操作的处理
- 抛出异常的方法
- Java操作MySQL的中文处理方法一则
- Python的MySQL操作
- python 的MySQL操作
- Python 的 mysql 操作
- python的 mysql 操作
- python操作mysql数据库的常用方法使用详解
- Python操作MySQL数据库的三种方法
- mysql 触发器 trigger 中断操作 抛出异常
- Redis代码阅读3--Redis网络监听(2)
- Visual Studio vs解决方案sln版本升级/高低版本转换工具
- 文件包含漏洞
- Google JavaScript 编码规范指南
- CNTK学习笔记 -- Computational Network Toolkit part4 -- Advanced Command Line Parsing Rules
- python操作mysql 抛出Unread result found的处理方法
- SSL证书与Https应用部署小结(转发)
- 收集的检测工具
- spring security helloworld例子操作
- Xutils3——网络连接
- CoreData的简单使用<三、CoreData分页查询和模糊查询>
- Redis代码阅读3--Redis网络监听(3)
- UVa 12299 RMQ with Shifts(线段树)
- CDO/CDS与次贷危机