Last active
May 27, 2024 17:26
-
-
Save technetium/549917077aa690a0d2f254ff70bf773f to your computer and use it in GitHub Desktop.
MySql functions to convert geocaching codes to id and back (Remove the GC, PR, and other prefixes)
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
CREATE FUNCTION GC_ID_TO_CODE(p_id INT) | |
RETURNS TEXT | |
DETERMINISTIC | |
RETURN IF ( | |
p_id < 65536, | |
CONV(p_id, 10, 16), | |
REPLACE(REPLACE(REPLACE(REPLACE(REPLACE(REPLACE(REPLACE(REPLACE(REPLACE(REPLACE(REPLACE(REPLACE(REPLACE(CONV(p_id+411120, 10, 31), | |
'U', 'Z'), 'T', 'Y'), 'S', 'X'), 'R', 'W'), 'Q', 'V'), 'P', 'T'), 'O', 'R'), 'N', 'Q'), 'M', 'P'), 'L', 'N'), 'K', 'M'), 'J', 'K'), 'I', 'J') | |
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
CREATE FUNCTION GC_ID_TO_CODE(p_id INT) | |
RETURNS TEXT | |
DETERMINISTIC | |
RETURN IF ( | |
p_id < 65536, | |
CONV(p_id, 10, 16), | |
REPLACE(REPLACE(REPLACE(REPLACE(REPLACE(REPLACE(REPLACE(REPLACE(REPLACE(REPLACE(REPLACE(REPLACE(REPLACE( | |
CONV(p_id+411120, 10, 31), | |
'J', 'I'), 'K', 'J'), 'M', 'K'), 'N', 'L'), 'P', 'M'), 'Q', 'N'), 'R', 'O'), 'T', 'P'), 'V', 'Q'), 'W', 'R'), 'X', 'S'), 'Y', 'T'), 'Z', 'U') | |
) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment