Menu

#460 Function parameters and comments

4.2.3
closed-fixed
nobody
5
2018-01-24
2015-06-10
Knut Kohl
No

Try this in SQL Command:

DELIMITER ;;

drop function if exists GCDist ;;
CREATE FUNCTION GCDist (
        _lat1 DOUBLE,  -- Scaled Degrees north for one point
        _lon1 DOUBLE,  -- Scaled Degrees west for one point
        _lat2 DOUBLE,  -- other point
        _lon2 DOUBLE
    ) RETURNS DOUBLE
    DETERMINISTIC
CONTAINS SQL  -- SQL but does not read or write
BEGIN
    -- Hardcoded constant:
    DECLARE _deg2rad DOUBLE DEFAULT PI() / 1800000;  -- For scaled by 1e4 to MEDIUMINT
    DECLARE _rlat1 DOUBLE DEFAULT _deg2rad * _lat1;
    DECLARE _rlat2 DOUBLE DEFAULT _deg2rad * _lat2;
    -- compute as if earth's radius = 1.0
    DECLARE _rlond DOUBLE DEFAULT _deg2rad * (_lon1 - _lon2);
    DECLARE _m     DOUBLE DEFAULT COS(_rlat2);
    DECLARE _x     DOUBLE DEFAULT COS(_rlat1) - _m * COS(_rlond);
    DECLARE _y     DOUBLE DEFAULT               _m * SIN(_rlond);
    DECLARE _z     DOUBLE DEFAULT SIN(_rlat1) - SIN(_rlat2);
    DECLARE _n     DOUBLE DEFAULT SQRT(_x * _x + _y * _y + _z * _z );
    RETURN  2 * ASIN(_n / 2) / _deg2rad;   -- again--scaled degrees
END;;

Afterwards try to alter the function, no parameters, no function body is shown.

"Export" displays correct, with comments.

Discussion

  • Jakub Vrána

    Jakub Vrána - 2017-02-20
    • status: open --> pending
     
  • Jakub Vrána

    Jakub Vrána - 2017-02-20

    Which driver is this?

     
  • Jakub Vrána

    Jakub Vrána - 2018-01-24
    • status: pending --> closed-fixed
     
  • Jakub Vrána

    Jakub Vrána - 2018-01-24

    This is MySQL. The problem was with the comments next to the params.

     

Log in to post a comment.