我在Django中尝试调用存储过程,但这显示了此消息(1305, 'PROCEDURE storedprocedureservice.MyStoredProcedure does not exist')
这是我的代码:
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()
答案 0 :(得分:1)
我解决了我的问题,感谢这个答案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"})