Thursday, June 23, 2005

First take at the new MySQL Functions

The functionality we produced through MySQL source hacking can be done with a following User Defined Function (UDF). It would be interesting to see the performance characteristics. I broke the pins on my HDD (which has Linux installed) so it would take a while to upload the benchmarks. The compiled version will defintely be much more faster but there is a tradeoff, UDFs can be created and destroyed on the fly!


DROP FUNCTION IF EXISTS encrypto2;

delimiter //

CREATE FUNCTION encrypto2 (s CHAR(255)) RETURNS char(255)
BEGIN
DECLARE mylen INT;
DECLARE cnt INT;
DECLARE result CHAR(255);

SET result = "";
SET mylen = LENGTH(s); -- oohh, this hurts multibyte!
SET cnt = 1; -- SUBSTRING starts from index 1!

WHILE mylen >= cnt DO
SET result = CONCAT(result,CHAR(ORD(SUBSTRING(s,cnt,1))+1));
SET cnt = cnt + 1;
END WHILE;

RETURN result;
END
//

Comments: Post a Comment

<< Home

This page is powered by Blogger. Isn't yours?