gpt4 book ai didi

python - pyodbc 错误 : 'pyodbc.Cursor' object has no attribute 'commit'

转载 作者:太空狗 更新时间:2023-10-30 01:21:09 37 4
gpt4 key购买 nike

我想使用 pyodbcfreetds 从 Python 连接到 SQL SERVER 数据库。

我的连接正常。

我的代码:

class GetSystems(Resource):
def get(self):
try:
cur = Connection.conn.cursor()
cur.execute(
"SELECT id,systemName,SystemDescription FROM MEFSystem")
rows = cur.fetchall()
objects_list = []
for row in rows:
d = collections.OrderedDict()
d['id'] = row[0]
d['systemName'] = row[1]
d['systemDescription'] = row[2]
objects_list.append(d)
logger.info(objects_list)
cur.commit()
cur.close()
logger.info(objects_list)
except Exception as inst:
cur.rollback()
cur.close()
print type(inst)
print inst.args
print inst
logger.error(type(inst))
logger.error(inst.args)
logger.error(inst)
return objects_list

这会在 cur.commit() 中产生错误:pyodbc.Cursor object has no attribute 'commit' 并返回未知数据:

[
{
"id": 2,
"systemDescription": "",
"systemName": "\uda00\udc53\ud940\udc41"
},
{
"id": 3,
"systemDescription": "",
"systemName": "\uda00\udc53\ud800\udc47"
},
{
"id": 4,
"systemDescription": "",
"systemName": "\ud900\udc52\ud8c0\udc4e\ud880\udc41"
}
]

数据应该是:

[
{
"id": 2,
"systemDescription": "",
"systemName": "SIAF"
},
{
"id": 3,
"systemDescription": "",
"systemName": "SIGA"
},
{
"id": 4,
"systemDescription": "",
"systemName": "RENTAS"
}
]

更新
我评论了提交,但从数据库返回未知数据。 look => "systemName": "\uda00\udc53\ud940\udc41", 应该是 "systemName": "SIGA"

最佳答案

问题的解决办法是pyodbc的版本,从这里下载pyodbc link并安装。

谢谢!!!

关于python - pyodbc 错误 : 'pyodbc.Cursor' object has no attribute 'commit' ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/33572947/

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