MYSQL - table not updating from Procedure

Multi tool use
up vote
0
down vote
favorite
I want to get distance between two GeoPoints (using LatLong) for that I wrote GETDISTANCE function from solution provided [MySQL Function to calculate distance between two latitudes and longitudes. If I call function independently it works like charm.
As per my understanding I cannot return ResultSet
from Function in MySQL so I created Procedure and called function inside procedure As follows:
DELIMITER $$
CREATE PROCEDURE GetNearByGeoPoints(IN Lat REAL, IN Longi REAL)
BEGIN
DECLARE v_max int;
DECLARE v_counter int unsigned default 0;
SET @v_max = (SELECT COUNT(*) FROM TransmitterPointsData);
START TRANSACTION;
WHILE v_counter < v_max
DO
SELECT @coverageID :=CoverageID, @tableLatitude := Latitude, @tableLongitude :=Longitude FROM TransmitterPointsData LIMIT v_counter,1;
SET @Dist= GETDISTANCE(Lat, Longi, tableLatitude, tableLongitude);
UPDATE TransmitterPointsData SET DynamicDistance = @Dist WHERE CoverageID= @coverageID;
set v_counter=v_counter+1;
END WHILE;
COMMIT;
SELECT * FROM TransmitterPointsData;
END $$
DELIMITER ;
What I am trying to do is taking a set of LatLong parameters from user and comparing it with each set of LatLong from table. And after getting output from function I am updating TransmitterPointsData table with where condition on coverageID.
This is my first MySQL query so far I was following syntax but I do not know why I am getting all null
values in DynammicDistance
Column.
Thank You in Advance
mysql phpmyadmin procedure mysql-function
add a comment |
up vote
0
down vote
favorite
I want to get distance between two GeoPoints (using LatLong) for that I wrote GETDISTANCE function from solution provided [MySQL Function to calculate distance between two latitudes and longitudes. If I call function independently it works like charm.
As per my understanding I cannot return ResultSet
from Function in MySQL so I created Procedure and called function inside procedure As follows:
DELIMITER $$
CREATE PROCEDURE GetNearByGeoPoints(IN Lat REAL, IN Longi REAL)
BEGIN
DECLARE v_max int;
DECLARE v_counter int unsigned default 0;
SET @v_max = (SELECT COUNT(*) FROM TransmitterPointsData);
START TRANSACTION;
WHILE v_counter < v_max
DO
SELECT @coverageID :=CoverageID, @tableLatitude := Latitude, @tableLongitude :=Longitude FROM TransmitterPointsData LIMIT v_counter,1;
SET @Dist= GETDISTANCE(Lat, Longi, tableLatitude, tableLongitude);
UPDATE TransmitterPointsData SET DynamicDistance = @Dist WHERE CoverageID= @coverageID;
set v_counter=v_counter+1;
END WHILE;
COMMIT;
SELECT * FROM TransmitterPointsData;
END $$
DELIMITER ;
What I am trying to do is taking a set of LatLong parameters from user and comparing it with each set of LatLong from table. And after getting output from function I am updating TransmitterPointsData table with where condition on coverageID.
This is my first MySQL query so far I was following syntax but I do not know why I am getting all null
values in DynammicDistance
Column.
Thank You in Advance
mysql phpmyadmin procedure mysql-function
Shouldn't it beGETDISTANCE(Lat, Longi, @tableLatitude, @tableLongitude)
? I'm surprised that the procedure compiles ...
– Henning Koehler
Nov 5 at 2:13
I treid that also, but it still giving me null values at end
– Pruthviraj Mohite
Nov 5 at 2:15
My best guess at this point is that your computation of the input values to GETDISTANCE is faulty. Try adding some debug info (storing / printing the inputs computed along with the results).
– Henning Koehler
Nov 5 at 2:19
I tried calling function like GETDISTANCE(10, 12, 12, 12) from stored procedure by giving hard coded values, but still its null in DynammicDistance column. But if I call function independently GETDISTANCE(10, 12, 12, 12) I am getting 138.11138916015625 as output. As per mysql query it should update 138.111*** value in DynamicDistance column
– Pruthviraj Mohite
Nov 5 at 2:27
add a comment |
up vote
0
down vote
favorite
up vote
0
down vote
favorite
I want to get distance between two GeoPoints (using LatLong) for that I wrote GETDISTANCE function from solution provided [MySQL Function to calculate distance between two latitudes and longitudes. If I call function independently it works like charm.
As per my understanding I cannot return ResultSet
from Function in MySQL so I created Procedure and called function inside procedure As follows:
DELIMITER $$
CREATE PROCEDURE GetNearByGeoPoints(IN Lat REAL, IN Longi REAL)
BEGIN
DECLARE v_max int;
DECLARE v_counter int unsigned default 0;
SET @v_max = (SELECT COUNT(*) FROM TransmitterPointsData);
START TRANSACTION;
WHILE v_counter < v_max
DO
SELECT @coverageID :=CoverageID, @tableLatitude := Latitude, @tableLongitude :=Longitude FROM TransmitterPointsData LIMIT v_counter,1;
SET @Dist= GETDISTANCE(Lat, Longi, tableLatitude, tableLongitude);
UPDATE TransmitterPointsData SET DynamicDistance = @Dist WHERE CoverageID= @coverageID;
set v_counter=v_counter+1;
END WHILE;
COMMIT;
SELECT * FROM TransmitterPointsData;
END $$
DELIMITER ;
What I am trying to do is taking a set of LatLong parameters from user and comparing it with each set of LatLong from table. And after getting output from function I am updating TransmitterPointsData table with where condition on coverageID.
This is my first MySQL query so far I was following syntax but I do not know why I am getting all null
values in DynammicDistance
Column.
Thank You in Advance
mysql phpmyadmin procedure mysql-function
I want to get distance between two GeoPoints (using LatLong) for that I wrote GETDISTANCE function from solution provided [MySQL Function to calculate distance between two latitudes and longitudes. If I call function independently it works like charm.
As per my understanding I cannot return ResultSet
from Function in MySQL so I created Procedure and called function inside procedure As follows:
DELIMITER $$
CREATE PROCEDURE GetNearByGeoPoints(IN Lat REAL, IN Longi REAL)
BEGIN
DECLARE v_max int;
DECLARE v_counter int unsigned default 0;
SET @v_max = (SELECT COUNT(*) FROM TransmitterPointsData);
START TRANSACTION;
WHILE v_counter < v_max
DO
SELECT @coverageID :=CoverageID, @tableLatitude := Latitude, @tableLongitude :=Longitude FROM TransmitterPointsData LIMIT v_counter,1;
SET @Dist= GETDISTANCE(Lat, Longi, tableLatitude, tableLongitude);
UPDATE TransmitterPointsData SET DynamicDistance = @Dist WHERE CoverageID= @coverageID;
set v_counter=v_counter+1;
END WHILE;
COMMIT;
SELECT * FROM TransmitterPointsData;
END $$
DELIMITER ;
What I am trying to do is taking a set of LatLong parameters from user and comparing it with each set of LatLong from table. And after getting output from function I am updating TransmitterPointsData table with where condition on coverageID.
This is my first MySQL query so far I was following syntax but I do not know why I am getting all null
values in DynammicDistance
Column.
Thank You in Advance
mysql phpmyadmin procedure mysql-function
mysql phpmyadmin procedure mysql-function
asked Nov 5 at 2:02
Pruthviraj Mohite
268
268
Shouldn't it beGETDISTANCE(Lat, Longi, @tableLatitude, @tableLongitude)
? I'm surprised that the procedure compiles ...
– Henning Koehler
Nov 5 at 2:13
I treid that also, but it still giving me null values at end
– Pruthviraj Mohite
Nov 5 at 2:15
My best guess at this point is that your computation of the input values to GETDISTANCE is faulty. Try adding some debug info (storing / printing the inputs computed along with the results).
– Henning Koehler
Nov 5 at 2:19
I tried calling function like GETDISTANCE(10, 12, 12, 12) from stored procedure by giving hard coded values, but still its null in DynammicDistance column. But if I call function independently GETDISTANCE(10, 12, 12, 12) I am getting 138.11138916015625 as output. As per mysql query it should update 138.111*** value in DynamicDistance column
– Pruthviraj Mohite
Nov 5 at 2:27
add a comment |
Shouldn't it beGETDISTANCE(Lat, Longi, @tableLatitude, @tableLongitude)
? I'm surprised that the procedure compiles ...
– Henning Koehler
Nov 5 at 2:13
I treid that also, but it still giving me null values at end
– Pruthviraj Mohite
Nov 5 at 2:15
My best guess at this point is that your computation of the input values to GETDISTANCE is faulty. Try adding some debug info (storing / printing the inputs computed along with the results).
– Henning Koehler
Nov 5 at 2:19
I tried calling function like GETDISTANCE(10, 12, 12, 12) from stored procedure by giving hard coded values, but still its null in DynammicDistance column. But if I call function independently GETDISTANCE(10, 12, 12, 12) I am getting 138.11138916015625 as output. As per mysql query it should update 138.111*** value in DynamicDistance column
– Pruthviraj Mohite
Nov 5 at 2:27
Shouldn't it be
GETDISTANCE(Lat, Longi, @tableLatitude, @tableLongitude)
? I'm surprised that the procedure compiles ...– Henning Koehler
Nov 5 at 2:13
Shouldn't it be
GETDISTANCE(Lat, Longi, @tableLatitude, @tableLongitude)
? I'm surprised that the procedure compiles ...– Henning Koehler
Nov 5 at 2:13
I treid that also, but it still giving me null values at end
– Pruthviraj Mohite
Nov 5 at 2:15
I treid that also, but it still giving me null values at end
– Pruthviraj Mohite
Nov 5 at 2:15
My best guess at this point is that your computation of the input values to GETDISTANCE is faulty. Try adding some debug info (storing / printing the inputs computed along with the results).
– Henning Koehler
Nov 5 at 2:19
My best guess at this point is that your computation of the input values to GETDISTANCE is faulty. Try adding some debug info (storing / printing the inputs computed along with the results).
– Henning Koehler
Nov 5 at 2:19
I tried calling function like GETDISTANCE(10, 12, 12, 12) from stored procedure by giving hard coded values, but still its null in DynammicDistance column. But if I call function independently GETDISTANCE(10, 12, 12, 12) I am getting 138.11138916015625 as output. As per mysql query it should update 138.111*** value in DynamicDistance column
– Pruthviraj Mohite
Nov 5 at 2:27
I tried calling function like GETDISTANCE(10, 12, 12, 12) from stored procedure by giving hard coded values, but still its null in DynammicDistance column. But if I call function independently GETDISTANCE(10, 12, 12, 12) I am getting 138.11138916015625 as output. As per mysql query it should update 138.111*** value in DynamicDistance column
– Pruthviraj Mohite
Nov 5 at 2:27
add a comment |
1 Answer
1
active
oldest
votes
up vote
0
down vote
Try replacing the while loop with this:
UPDATE TransmitterPointsData
SET DynamicDistance = GETDISTANCE(Lat, Longi, Latitude, Longitude)
Much shorter, and you avoid potential issues with row selection via limit + offset (which is poor style at best, and gives you a random row each time at worse).
add a comment |
1 Answer
1
active
oldest
votes
1 Answer
1
active
oldest
votes
active
oldest
votes
active
oldest
votes
up vote
0
down vote
Try replacing the while loop with this:
UPDATE TransmitterPointsData
SET DynamicDistance = GETDISTANCE(Lat, Longi, Latitude, Longitude)
Much shorter, and you avoid potential issues with row selection via limit + offset (which is poor style at best, and gives you a random row each time at worse).
add a comment |
up vote
0
down vote
Try replacing the while loop with this:
UPDATE TransmitterPointsData
SET DynamicDistance = GETDISTANCE(Lat, Longi, Latitude, Longitude)
Much shorter, and you avoid potential issues with row selection via limit + offset (which is poor style at best, and gives you a random row each time at worse).
add a comment |
up vote
0
down vote
up vote
0
down vote
Try replacing the while loop with this:
UPDATE TransmitterPointsData
SET DynamicDistance = GETDISTANCE(Lat, Longi, Latitude, Longitude)
Much shorter, and you avoid potential issues with row selection via limit + offset (which is poor style at best, and gives you a random row each time at worse).
Try replacing the while loop with this:
UPDATE TransmitterPointsData
SET DynamicDistance = GETDISTANCE(Lat, Longi, Latitude, Longitude)
Much shorter, and you avoid potential issues with row selection via limit + offset (which is poor style at best, and gives you a random row each time at worse).
answered Nov 5 at 7:21
Henning Koehler
878410
878410
add a comment |
add a comment |
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53147387%2fmysql-table-not-updating-from-procedure%23new-answer', 'question_page');
}
);
Post as a guest
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
WBA4vUk,zIgknjoe6lmFMXD GDijoL9Te Dln0ZUqVsu
Shouldn't it be
GETDISTANCE(Lat, Longi, @tableLatitude, @tableLongitude)
? I'm surprised that the procedure compiles ...– Henning Koehler
Nov 5 at 2:13
I treid that also, but it still giving me null values at end
– Pruthviraj Mohite
Nov 5 at 2:15
My best guess at this point is that your computation of the input values to GETDISTANCE is faulty. Try adding some debug info (storing / printing the inputs computed along with the results).
– Henning Koehler
Nov 5 at 2:19
I tried calling function like GETDISTANCE(10, 12, 12, 12) from stored procedure by giving hard coded values, but still its null in DynammicDistance column. But if I call function independently GETDISTANCE(10, 12, 12, 12) I am getting 138.11138916015625 as output. As per mysql query it should update 138.111*** value in DynamicDistance column
– Pruthviraj Mohite
Nov 5 at 2:27