MYSQL - table not updating from Procedure











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










share|improve this question






















  • 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















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










share|improve this question






















  • 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













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










share|improve this question













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






share|improve this question













share|improve this question











share|improve this question




share|improve this question










asked Nov 5 at 2:02









Pruthviraj Mohite

268




268












  • 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


















  • 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
















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












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






share|improve this answer





















    Your Answer






    StackExchange.ifUsing("editor", function () {
    StackExchange.using("externalEditor", function () {
    StackExchange.using("snippets", function () {
    StackExchange.snippets.init();
    });
    });
    }, "code-snippets");

    StackExchange.ready(function() {
    var channelOptions = {
    tags: "".split(" "),
    id: "1"
    };
    initTagRenderer("".split(" "), "".split(" "), channelOptions);

    StackExchange.using("externalEditor", function() {
    // Have to fire editor after snippets, if snippets enabled
    if (StackExchange.settings.snippets.snippetsEnabled) {
    StackExchange.using("snippets", function() {
    createEditor();
    });
    }
    else {
    createEditor();
    }
    });

    function createEditor() {
    StackExchange.prepareEditor({
    heartbeatType: 'answer',
    convertImagesToLinks: true,
    noModals: true,
    showLowRepImageUploadWarning: true,
    reputationToPostImages: 10,
    bindNavPrevention: true,
    postfix: "",
    imageUploader: {
    brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
    contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
    allowUrls: true
    },
    onDemand: true,
    discardSelector: ".discard-answer"
    ,immediatelyShowMarkdownHelp:true
    });


    }
    });














     

    draft saved


    draft discarded


















    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
































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






    share|improve this answer

























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






      share|improve this answer























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






        share|improve this answer












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







        share|improve this answer












        share|improve this answer



        share|improve this answer










        answered Nov 5 at 7:21









        Henning Koehler

        878410




        878410






























             

            draft saved


            draft discarded



















































             


            draft saved


            draft discarded














            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




















































































            這個網誌中的熱門文章

            Xamarin.form Move up view when keyboard appear

            Post-Redirect-Get with Spring WebFlux and Thymeleaf

            Anylogic : not able to use stopDelay()