Skip to content

Commit

Permalink
Added DELIMITER
Browse files Browse the repository at this point in the history
  • Loading branch information
recipe committed Feb 19, 2024
1 parent d05667c commit 5887c3e
Showing 1 changed file with 13 additions and 7 deletions.
20 changes: 13 additions & 7 deletions semver.sql
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@

-- This file is part of Project recipe/mysql-semver, a program for working with Semantic Versions in MySQL.
-- Copyright (C) 2024 Vitaliy Demidov
--
Expand All @@ -13,29 +14,32 @@
-- You should have received a copy of the GNU General Public License
-- along with this program. If not, see <https://www.gnu.org/licenses/>.

DROP FUNCTION IF EXISTS `SEMANTIC_VERSION`;
DELIMITER //

DROP FUNCTION IF EXISTS `SEMANTIC_VERSION` //

CREATE FUNCTION `SEMANTIC_VERSION`(version VARCHAR(255)) RETURNS VARCHAR(255)
DETERMINISTIC
NO SQL
SQL SECURITY INVOKER
BEGIN
DECLARE re VARCHAR(255) DEFAULT '^(0|[1-9]\\d*)\\.(0|[1-9]\\d*)\\.(0|[1-9]\\d*)(?:-((?:0|[1-9]\\d*|\\d*[a-zA-Z-][0-9a-zA-Z-]*)(?:\\.(?:0|[1-9]\\d*|\\d*[a-zA-Z-][0-9a-zA-Z-]*))*))?(?:\\+([0-9a-zA-Z-]+(?:\\.[0-9a-zA-Z-]+)*))?$';
DECLARE sem_ver VARCHAR(255) DEFAULT NULL;

IF version IS NULL THEN
RETURN NULL;
END IF;

SET sem_ver = REGEXP_REPLACE(version, '^(0|[1-9]\\d*)\\.(0|[1-9]\\d*)\\.(0|[1-9]\\d*)(?:-((?:0|[1-9]\\d*|\\d*[a-zA-Z-][0-9a-zA-Z-]*)(?:\\.(?:0|[1-9]\\d*|\\d*[a-zA-Z-][0-9a-zA-Z-]*))*))?(?:\\+([0-9a-zA-Z-]+(?:\\.[0-9a-zA-Z-]+)*))?$', '$1,$2,$3,$4,$5');
SET sem_ver = REGEXP_REPLACE(version, re, '$1,$2,$3,$4,$5');

IF version = sem_ver THEN
SET sem_ver = NULL;
END IF;

RETURN sem_ver;
END;
END //

DROP FUNCTION IF EXISTS `NAT_VERSION`;
DROP FUNCTION IF EXISTS `NAT_VERSION` //

CREATE FUNCTION `NAT_VERSION` (version VARCHAR(255)) RETURNS VARCHAR(255)
DETERMINISTIC
Expand All @@ -58,10 +62,10 @@ BEGIN
END IF;

RETURN ver;
END;
END //


DROP FUNCTION IF EXISTS `VERSION_COMPARE`;
DROP FUNCTION IF EXISTS `VERSION_COMPARE`//

CREATE FUNCTION `VERSION_COMPARE`(version1 VARCHAR(255), version2 VARCHAR(255)) RETURNS TINYINT
DETERMINISTIC
Expand Down Expand Up @@ -232,4 +236,6 @@ BEGIN

/* Versions are identical */
RETURN 0;
END;
END //

DELIMITER ;

0 comments on commit 5887c3e

Please sign in to comment.