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; ...@@ -98,12 +98,12 @@ DROP FUNCTION f1;
CREATE FUNCTION f1 (a INT) RETURN INT AS CREATE FUNCTION f1 (a INT) RETURN INT AS
BEGIN BEGIN
<<label1>> <<label1>>
WHILE a>0 DO WHILE a>0 LOOP
IF a = 2 THEN IF a = 2 THEN
LEAVE label1; LEAVE label1;
END IF; END IF;
SET a= a-1; SET a= a-1;
END WHILE label1; END LOOP label1;
RETURN a; RETURN a;
END; END;
/ /
...@@ -427,10 +427,10 @@ i INT DEFAULT 5; ...@@ -427,10 +427,10 @@ i INT DEFAULT 5;
x INT DEFAULT 10; x INT DEFAULT 10;
BEGIN BEGIN
<<label>> <<label>>
WHILE i > 3 DO WHILE i > 3 LOOP
i:= i - 1; i:= i - 1;
SELECT i; SELECT i;
END WHILE label; END LOOP label;
END; END;
END END
/ /
...@@ -736,3 +736,41 @@ SELECT @v; ...@@ -736,3 +736,41 @@ SELECT @v;
@v @v
100 100
DROP PROCEDURE p1; 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 /; ...@@ -91,12 +91,12 @@ DELIMITER /;
CREATE FUNCTION f1 (a INT) RETURN INT AS CREATE FUNCTION f1 (a INT) RETURN INT AS
BEGIN BEGIN
<<label1>> <<label1>>
WHILE a>0 DO WHILE a>0 LOOP
IF a = 2 THEN IF a = 2 THEN
LEAVE label1; LEAVE label1;
END IF; END IF;
SET a= a-1; SET a= a-1;
END WHILE label1; END LOOP label1;
RETURN a; RETURN a;
END; END;
/ /
...@@ -454,10 +454,10 @@ BEGIN NOT ATOMIC ...@@ -454,10 +454,10 @@ BEGIN NOT ATOMIC
x INT DEFAULT 10; x INT DEFAULT 10;
BEGIN BEGIN
<<label>> <<label>>
WHILE i > 3 DO WHILE i > 3 LOOP
i:= i - 1; i:= i - 1;
SELECT i; SELECT i;
END WHILE label; END LOOP label;
END; END;
END END
/ /
...@@ -801,3 +801,45 @@ SET @v=10; ...@@ -801,3 +801,45 @@ SET @v=10;
CALL p1(@v); CALL p1(@v);
SELECT @v; SELECT @v;
DROP PROCEDURE p1; 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: ...@@ -3485,7 +3485,7 @@ loop_body:
; ;
while_body: while_body:
expr DO_SYM expr LOOP_SYM
{ {
LEX *lex= Lex; LEX *lex= Lex;
sp_head *sp= lex->sphead; sp_head *sp= lex->sphead;
...@@ -3501,7 +3501,7 @@ while_body: ...@@ -3501,7 +3501,7 @@ while_body:
if (sp->restore_lex(thd)) if (sp->restore_lex(thd))
MYSQL_YYABORT; MYSQL_YYABORT;
} }
sp_proc_stmts1 END WHILE_SYM sp_proc_stmts1 END LOOP_SYM
{ {
LEX *lex= Lex; LEX *lex= Lex;
uint ip= lex->sphead->instructions(); 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