Python cursor.callproc返回空结果
我有这样一种方法:Python cursor.callproc返回空结果,python,sqlalchemy,Python,Sqlalchemy,我有这样一种方法: from app.database import db def get_channels_list(user_token): data = jwt.decode(user_token, app.config.get('JWT_SECRET')) connection = db.engine.raw_connection() try: cursor = connection.cursor() cursor.callpro
from app.database import db
def get_channels_list(user_token):
data = jwt.decode(user_token, app.config.get('JWT_SECRET'))
connection = db.engine.raw_connection()
try:
cursor = connection.cursor()
cursor.callproc("permission_list_user", [958539, 'web'])
results = list(cursor.fetchall())
cursor.close()
connection.commit()
finally:
connection.close()
print(len(results))
return success(results)
当我运行它时,我得到len(results)==0
,但当我通过mysql控制台运行相同的过程时,如下所示:
CALL permission_list_user(958539, 'web');
我得到了它应该返回的结果。我也有同样的问题,我不喜欢这种方式,但我解决了在调用过程后运行SELECT查询的问题:
query ='call loginAPI("{0}","{1}",@logged, @hashAPI)'.format(user,password)
select = 'select @logged, @hashAPI'
cursor.execute(query)
cursor.execute(select)
rv = cursor.fetchall()
正在寻找更漂亮的解决方案。您是否使用同一个MySQL帐户进行呼叫?如果您没有执行权限,可能会发生这种情况。我猜是这样的,因为当我运行以下命令时:
cursor.EXECUTE(“select*from users limit 10;”
而不是callproc,我得到的是结果OK,我已经从这里发布的代码中找到了答案:我回顾了如何在中访问调用存储过程的结果