且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

在第二个数据库上的Django调用存储过程

更新时间:2023-02-04 21:43:31

我采取了以下步骤:

  1. 将存储过程转储结果制作到临时表中,以便将结果集展平为单个结果集.这摆脱了multi=True
  2. 的需要
  3. 此外,我确保IP地址的用户可以访问数据库本身中的调用存储过程.
  4. 最后,我继续研究 callproc 函数.最终,另一个站点上的某个人提出了以下有效的代码:

  1. Made my stored procedure dump results into a temporary table so as to flatten the result set to a single result set. This got rid of the need for multi=True
  2. In addition, I made sure the user at my IP address had access to call stored procedures in the database itself.
  3. Finally, I continued to research the callproc function. Eventually someone on another site suggested the following code, which worked:

cur = connections["SomeDB"].cursor()
cur.callproc("spGetLocationPath", [id, someval])
res = next(cur.stored_results()).fetchall()
cur.close()