'Call a stored-procedure mysql in django

I am using a procedure I have written in MySQL that I want to call in Django but I am just receiving an error : " AttributeError: 'Cursor' object has no attribute 'stored_results' " I can't find why is cursor has no attribute, all the info I get about calling a procedure with python goes with the code 'cursor.stored_results()'. Do you have an idea ?

My procedure is :

CREATE DEFINER=`root`@`localhost` PROCEDURE `ProcTime`(IN in_date int, OUT somme int)
READS SQL DATA
BEGIN
SELECT SUM(tot) INTO somme FROM(
SELECT Habitat, COUNT(DISTINCT(Transect)) AS tot FROM MyTable 
WHERE Year = @in_date 
GROUP BY Habitat
) AS t ; 
END

And I am calling it in my views :

cursor = connection.cursor()
args = ['2004', 0]
cursor.callproc('ProcTime', args)
for result in cursor.stored_results():
        print(result.fetchall())

Thanks !!



Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source