2015-11-04 62 views
1

我想在Django調用存儲過程,但是這表明此消息(1305, 'PROCEDURE storedprocedureservice.MyStoredProcedure does not exist')Django的 - 存儲過程不存在

這是我的代碼:

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()

回答

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"})