gpt4 book ai didi

python - Django - 存储过程不存在

转载 作者:太空宇宙 更新时间:2023-11-03 17:17:33 24 4
gpt4 key购买 nike

我尝试在 Django 中调用存储过程,但这显示了此消息(1305, 'PROCEDURE storeprocedureservice.MyStoredProcedure does not exit')

这是我的代码:

class StoredProcedureService():
def close_service(self, param1, param2, param3):
cursor = connection.cursor()
ret = cursor.callproc("StoredProcedureService.MyStoredProcedure", (self, param1, param2, param3))
cursor.close()
return ret

@csrf_exempt
def service(request):

if request.is_ajax:
value = request.POST.get('value')
stored_procedure = StoredProcedureService()
ret = stored_procedure.close_service(value, 1, 'Lorem Ipsum')

return JsonResponse({"status":"ok"})

我的程序在其他数据库中,我准备配置它,但不知道如何调用它。

我尝试了一下,但不起作用:cursor = connection.using("myOtherDatabase").cursor()

最佳答案

感谢这个答案,我解决了我的问题 https://stackoverflow.com/a/28029109/3464573

我的代码是这样的:

class StoredProcedureService():
def close_service(self, param1, param2, param3):
cursor = connections["mydatabase"].cursor()
cursor.callproc("StoredProcedureService.MyStoredProcedure", [param1, param2, param3])
results = cursor.fetchall()
cursor.close()
return results

@csrf_exempt
def service(request):

if request.is_ajax:
value = request.POST.get('value')
stored_procedure = StoredProcedureService()
ret = stored_procedure.close_service(value, 1, 'Lorem Ipsum')

return JsonResponse({"status":"ok"})

关于python - Django - 存储过程不存在,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/33521894/

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