So I’m trying to use a stored procedure via a cursor and callproc() but I always get the error:
OperationalError: (1305, 'PROCEDURE myapp.LatLonDistance does not exist')
Here’s the chunk of code that throws the error in my app:
cursor = connection.cursor()
result = cursor.callproc("myapp.LatLonDistance", (lat1, lon1, lat2, lon2))
cursor.close()
And here’s a direct query that I can run on the DB that works just fine:
SELECT id,myapp.LatLonDistance(lat1, lon1, lat2, lon2) AS distance FROM myapp.users_userprofile;
And here’s the script I use to write the stored procedure to the DB:
delimiter //
CREATE FUNCTION airrun.LatLonDistance (lat1 double, lon1 double, lat2 double, lon2 double)
RETURNS double
DETERMINISTIC
READS SQL DATA
BEGIN
DECLARE theta double;
DECLARE dist double;
DECLARE miles double;
SET theta = lon1 - lon2;
SET dist = SIN(RADIANS(lat1)) * SIN(RADIANS(lat2)) + COS(RADIANS(lat1)) * COS(RADIANS(lat2)) * COS(RADIANS(theta));
SET dist = ACOS(dist);
SET dist = DEGREES(dist);
SET miles = dist * 60 * 1.1515;
RETURN miles;
END
//
delimiter ;
Using a MySQL db. Any thoughts?
Since that is a function, and not actually a stored procedure, you should be able to call it using
cursor.execute: