pears.URLSafe

Generated schema reference. Regenerate this page from the SQL unload; keep hand-maintained business notes in the narrative namespace.

CREATE FUNCTION "pears"."URLSafe"( 
  /* Application Maintained Function / Procedure - DO NOT EDIT*/
  IN "OldString" long VARCHAR ) 
RETURNS long VARCHAR
BEGIN
  -- Partial solution. £ is the only multi-byte utf-8 char handled. If possible use the Delphi or jobrunner httpsafe implementations
  DECLARE "NewString" long VARCHAR;
  DECLARE "StringLength" SMALLINT;
  DECLARE "CurrentChar" CHAR(10);
  DECLARE "CurrentPos" SMALLINT;
  DECLARE "AsciiVal" SMALLINT;
  DECLARE "SafeChars" CHAR(250);
  IF "OldString" IS NULL THEN RETURN(NULL)
  END IF;
  SET "stringlength" = "length"("OldString");
  SET "CurrentPos" = 1;
  SET "NewString" = '';
  SET "SafeChars" = 'abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789-_.!~*''()';
  "process": loop
    SET "CurrentChar" = "substr"("OldString","CurrentPos",1);
    IF "CurrentChar" = '£' THEN
      SET "CurrentChar" = '%C2%A3'
    ELSE IF "charindex"("CurrentChar","SafeChars") = 0 THEN
        SET "CurrentChar" = "ucase"("string"('%',"right"("IntToHex"("ascii"("CurrentChar")),2)))
      END IF END IF;
    SET "NewString" = "NewString" || "CurrentChar";
    SET "CurrentPos" = "CurrentPos"+1;
    IF "CurrentPos" > "StringLength" THEN leave "process"
    END IF
  END loop "process";
  RETURN("NewString")
END
  • database/functions/pears_urlsafe.txt
  • Last modified: 2026/08/07 19:24
  • by 127.0.0.1