Commit 28f28591 authored by Alexander Barkov's avatar Alexander Barkov

MDEV-10411 Providing compatibility for basic PL/SQL constructs

Part 18: WHILE syntax
parent 4212039d
......@@ -98,12 +98,12 @@ DROP FUNCTION f1;
CREATE FUNCTION f1 (a INT) RETURN INT AS
BEGIN
<<label1>>
WHILE a>0 DO
WHILE a>0 LOOP
IF a = 2 THEN
LEAVE label1;
END IF;
SET a= a-1;
END WHILE label1;
END LOOP label1;
RETURN a;
END;
/
......@@ -427,10 +427,10 @@ i INT DEFAULT 5;
x INT DEFAULT 10;
BEGIN
<<label>>
WHILE i > 3 DO
WHILE i > 3 LOOP
i:= i - 1;
SELECT i;
END WHILE label;
END LOOP label;
END;
END
/
......@@ -736,3 +736,41 @@ SELECT @v;
@v
100
DROP PROCEDURE p1;
# Testing WHILE loop
CREATE PROCEDURE p1 (a IN OUT INT)
AS
i INT:= 1;
j INT:= 3;
BEGIN
WHILE i<=j
LOOP
a:= a + i;
i:= i + 1;
END LOOP;
END;
/
SET @v=0;
CALL p1(@v);
SELECT @v;
@v
6
DROP PROCEDURE p1;
CREATE PROCEDURE p1 (a IN OUT INT)
AS
i INT:= 1;
j INT:= 3;
BEGIN
<<label>>
WHILE i<=j
LOOP
a:= a + i;
i:= i + 1;
END LOOP label;
END;
/
SET @v=0;
CALL p1(@v);
SELECT @v;
@v
6
DROP PROCEDURE p1;
......@@ -91,12 +91,12 @@ DELIMITER /;
CREATE FUNCTION f1 (a INT) RETURN INT AS
BEGIN
<<label1>>
WHILE a>0 DO
WHILE a>0 LOOP
IF a = 2 THEN
LEAVE label1;
END IF;
SET a= a-1;
END WHILE label1;
END LOOP label1;
RETURN a;
END;
/
......@@ -454,10 +454,10 @@ BEGIN NOT ATOMIC
x INT DEFAULT 10;
BEGIN
<<label>>
WHILE i > 3 DO
WHILE i > 3 LOOP
i:= i - 1;
SELECT i;
END WHILE label;
END LOOP label;
END;
END
/
......@@ -801,3 +801,45 @@ SET @v=10;
CALL p1(@v);
SELECT @v;
DROP PROCEDURE p1;
--echo # Testing WHILE loop
DELIMITER /;
CREATE PROCEDURE p1 (a IN OUT INT)
AS
i INT:= 1;
j INT:= 3;
BEGIN
WHILE i<=j
LOOP
a:= a + i;
i:= i + 1;
END LOOP;
END;
/
DELIMITER ;/
SET @v=0;
CALL p1(@v);
SELECT @v;
DROP PROCEDURE p1;
DELIMITER /;
CREATE PROCEDURE p1 (a IN OUT INT)
AS
i INT:= 1;
j INT:= 3;
BEGIN
<<label>>
WHILE i<=j
LOOP
a:= a + i;
i:= i + 1;
END LOOP label;
END;
/
DELIMITER ;/
SET @v=0;
CALL p1(@v);
SELECT @v;
DROP PROCEDURE p1;
......@@ -3485,7 +3485,7 @@ loop_body:
;
while_body:
expr DO_SYM
expr LOOP_SYM
{
LEX *lex= Lex;
sp_head *sp= lex->sphead;
......@@ -3501,7 +3501,7 @@ while_body:
if (sp->restore_lex(thd))
MYSQL_YYABORT;
}
sp_proc_stmts1 END WHILE_SYM
sp_proc_stmts1 END LOOP_SYM
{
LEX *lex= Lex;
uint ip= lex->sphead->instructions();
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment