Subject | Help to convert function from MySql to Firebird |
---|---|
Author | nenhumpois |
Post date | 2013-01-02T22:47:42Z |
Hello,
Can any one help converting a function wroten in MySQL to Firebird?
CREATE FUNCTION `url_amigavel`(s VARCHAR(4096)) RETURNS varchar(4096) CHARSET utf8 COLLATE utf8_unicode_ci
DETERMINISTIC
BEGIN
DECLARE c VARCHAR(4096) DEFAULT '';
DECLARE pointer INT DEFAULT 1;
DECLARE s2 VARCHAR(4096) DEFAULT '';
set s=trim(lower(s));
IF ISNULL(s) THEN
RETURN NULL;
ELSE
SET s2 = '';
WHILE pointer < length(s)+1 DO
SET c = MID(s,pointer,1);
IF NOT (ASCII(c) BETWEEN 48 AND 57 OR
ASCII(c) BETWEEN 65 AND 90 OR
ASCII(c) BETWEEN 97 AND 122) THEN
begin
SET c = replace(c,'ç','c');
SET c = replace(c,'ã','a');
SET c = replace(c,'á','a');
SET c = replace(c,'à','a');
SET c = replace(c,'ä','a');
SET c = replace(c,'é','e');
SET c = replace(c,'è','e');
SET c = replace(c,'ë','e');
SET c = replace(c,'õ','o');
SET c = replace(c,'ó','o');
SET c = replace(c,'ò','o');
SET c = replace(c,'ö','o');
SET c = replace(c,'í','i');
SET c = replace(c,'ì','i');
SET c = replace(c,'ï','i');
SET c = replace(c,'ü','u');
SET c = replace(c,'ú','u');
SET c = replace(c,'ù','u');
SET c = replace(c,' ','-');
set c=regex_replace('[^a-zA-Z0-9-]','',c);
end;
END IF;
SET s2 = CONCAT(s2,c);
SET pointer = pointer + 1;
END while;
END IF;
RETURN s2;
END */;;
DELIMITER ;
So far i managed to write this incomplete code:
SET TERM ^ ;
ALTER PROCEDURE URL_AMIGAVEL (
s VARCHAR(4096) )
RETURNS (
s2 VARCHAR(4096) )
AS
DECLARE variable c VARCHAR(4096) DEFAULT '';
DECLARE variable pointer INT DEFAULT 1;
BEGIN
s2='';
s=trim(lower(s));
IF (s is not null) THEN
begin
s2 = '';
WHILE (pointer < CHAR_LENGTH(s)+1) DO
begin
c = substring(s from pointer for 1);
s2=s2||c;
end
end
end^
SET TERM ; ^
GRANT EXECUTE
ON PROCEDURE URL_AMIGAVEL TO PHPUSER;
GRANT EXECUTE
ON PROCEDURE URL_AMIGAVEL TO SYSDBA;
Thank you
Can any one help converting a function wroten in MySQL to Firebird?
CREATE FUNCTION `url_amigavel`(s VARCHAR(4096)) RETURNS varchar(4096) CHARSET utf8 COLLATE utf8_unicode_ci
DETERMINISTIC
BEGIN
DECLARE c VARCHAR(4096) DEFAULT '';
DECLARE pointer INT DEFAULT 1;
DECLARE s2 VARCHAR(4096) DEFAULT '';
set s=trim(lower(s));
IF ISNULL(s) THEN
RETURN NULL;
ELSE
SET s2 = '';
WHILE pointer < length(s)+1 DO
SET c = MID(s,pointer,1);
IF NOT (ASCII(c) BETWEEN 48 AND 57 OR
ASCII(c) BETWEEN 65 AND 90 OR
ASCII(c) BETWEEN 97 AND 122) THEN
begin
SET c = replace(c,'ç','c');
SET c = replace(c,'ã','a');
SET c = replace(c,'á','a');
SET c = replace(c,'à','a');
SET c = replace(c,'ä','a');
SET c = replace(c,'é','e');
SET c = replace(c,'è','e');
SET c = replace(c,'ë','e');
SET c = replace(c,'õ','o');
SET c = replace(c,'ó','o');
SET c = replace(c,'ò','o');
SET c = replace(c,'ö','o');
SET c = replace(c,'í','i');
SET c = replace(c,'ì','i');
SET c = replace(c,'ï','i');
SET c = replace(c,'ü','u');
SET c = replace(c,'ú','u');
SET c = replace(c,'ù','u');
SET c = replace(c,' ','-');
set c=regex_replace('[^a-zA-Z0-9-]','',c);
end;
END IF;
SET s2 = CONCAT(s2,c);
SET pointer = pointer + 1;
END while;
END IF;
RETURN s2;
END */;;
DELIMITER ;
So far i managed to write this incomplete code:
SET TERM ^ ;
ALTER PROCEDURE URL_AMIGAVEL (
s VARCHAR(4096) )
RETURNS (
s2 VARCHAR(4096) )
AS
DECLARE variable c VARCHAR(4096) DEFAULT '';
DECLARE variable pointer INT DEFAULT 1;
BEGIN
s2='';
s=trim(lower(s));
IF (s is not null) THEN
begin
s2 = '';
WHILE (pointer < CHAR_LENGTH(s)+1) DO
begin
c = substring(s from pointer for 1);
s2=s2||c;
end
end
end^
SET TERM ; ^
GRANT EXECUTE
ON PROCEDURE URL_AMIGAVEL TO PHPUSER;
GRANT EXECUTE
ON PROCEDURE URL_AMIGAVEL TO SYSDBA;
Thank you