pears.Base29Safe
Generated schema reference. Regenerate this page from the SQL unload; keep hand-maintained business notes in the narrative namespace.
Original SQL
CREATE FUNCTION "pears"."Base29Safe"( /* Application Maintained Function / Procedure - DO NOT EDIT*/ IN "seed" INTEGER,IN "digits" SMALLINT ) RETURNS CHAR(20) BEGIN DECLARE "rv" CHAR(20); DECLARE "m" INTEGER; DECLARE "sdigits" CHAR(29); -- Where the code must be handled by humans, letters O and I can be confused with zero and one so these are left out -- By removing all vowels and also 1 & 0 from the available characters (except the padding) nothing that -- looks much like a word (rude or otherwise) should be generated SET "sdigits" = '23456789BCDFGHJKLMNPQRSTVWXYZ'; SET "rv" = ''; IF(("digits" > 20) OR("digits" < 1)) THEN SET "digits" = 20 END IF; while "seed" > 0 loop SET "m" = "mod"("seed",29); SET "rv" = "substr"("sdigits","m"+1,1) || "rv"; SET "seed" = "seed"/29 END loop; SET "rv" = "right"("string"('0000000000000000000',"rv"),"digits"); RETURN("rv") END