====== pears.Base34 ======
Generated schema reference. Regenerate this page from the SQL unload; keep hand-maintained business notes in the narrative namespace.
===== Original SQL =====
create function "pears"."Base34"(
/* 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(34);
-- 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 base34
set "sdigits" = '0123456789ABCDEFGHJKLMNPQRSTUVWXYZ';
set "rv" = '';
if(("digits" > 20) or("digits" < 1)) then
set "digits" = 20
end if;
while "seed" > 0 loop
set "m" = "mod"("seed",34);
set "rv" = "substr"("sdigits","m"+1,1) || "rv";
set "seed" = "seed"/34
end loop;
while "length"("rv") < "digits" loop
set "rv" = '0' || "rv"
end loop;
return("rv")
end