I'm making a MySQL Stored Procedure which takes a string representation of an IPv4 or v6 address and converts it to binary using
INET6_ATON. I know that my version of MySQL supports this function because I can run
SELECT HEX(INET6_ATON("::ffff:127.0.0.1")); and it returns the correct representation.
However, when I try to put this in to a Stored Procedure and use an input parameter, it always returns NULL no matter what I put in to it.
Here's a simplified version I made using a Stored Function instead:
DROP FUNCTION IF EXISTS `addrToBinary`; DELIMITER ;; CREATE FUNCTION `addrToBinary` (`in_remote_ip` varchar(45)) RETURNS varchar(45) DETERMINISTIC BEGIN RETURN HEX(INET6_ATON(in_remote_ip)); END;; DELIMITER ; SELECT addrToBinary("::ffff:127.0.0.1"), -- NULL HEX(INET6_ATON("::ffff:127.0.0.1")); -- 00000000000000000000FFFF7F000001
Any ideas on how I can get this function to work the same inside a Stored Procedure/Function as it does typing it in manually?
UPDATE: I've just found out that I'm in fact running MariaDB (
5.5.5-10.0.17-MariaDB). Here's a screenshot of the issues when I run it using Adminer: