【问题标题】:cursor.callproc returns empty resultscursor.callproc 返回空结果
【发布时间】:2017-03-23 14:41:59
【问题描述】:

我有这样的方法:

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');

我得到了它应该返回的结果。

【问题讨论】:

  • 您是否从同一个 MySQL 帐户拨打电话?如果您没有 EXECUTE 权限,可能会发生这种情况
  • 我猜是因为当我运行这个时:cursor.execute("select * from users limit 10;") 而不是 callproc 我得到结果
  • 好的,我已经从这里发布的代码中弄清楚了:stackoverflow.com/questions/15320265/…

标签: python sqlalchemy


【解决方案1】:

我有同样的问题,我不喜欢这种方式,但我解决了在调用过程后运行 SELECT 查询:

query ='call loginAPI("{0}","{1}",@logged, @hashAPI)'.format(user,password)
 select = 'select @logged, @hashAPI'

  cursor.execute(query)
  cursor.execute(select)
  rv = cursor.fetchall()

寻找更漂亮的解决方案。

【讨论】:

  • 我回顾了如何访问this answer中的存储过程调用结果
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2021-09-15
  • 2021-05-01
  • 2017-08-25
  • 2013-09-27
相关资源
最近更新 更多