Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
M
MariaDB
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Analytics
Analytics
CI / CD
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
nexedi
MariaDB
Commits
ca242117
Commit
ca242117
authored
Aug 24, 2016
by
Alexander Barkov
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
MDEV-10411 Providing compatibility for basic PL/SQL constructs
Part 19: CONTINUE statement
parent
442ea81e
Changes
7
Hide whitespace changes
Inline
Side-by-side
Showing
7 changed files
with
298 additions
and
0 deletions
+298
-0
mysql-test/suite/compat/oracle/r/sp-code.result
mysql-test/suite/compat/oracle/r/sp-code.result
+30
-0
mysql-test/suite/compat/oracle/r/sp.result
mysql-test/suite/compat/oracle/r/sp.result
+81
-0
mysql-test/suite/compat/oracle/t/sp-code.test
mysql-test/suite/compat/oracle/t/sp-code.test
+22
-0
mysql-test/suite/compat/oracle/t/sp.test
mysql-test/suite/compat/oracle/t/sp.test
+90
-0
sql/sql_lex.cc
sql/sql_lex.cc
+53
-0
sql/sql_lex.h
sql/sql_lex.h
+6
-0
sql/sql_yacc_ora.yy
sql/sql_yacc_ora.yy
+16
-0
No files found.
mysql-test/suite/compat/oracle/r/sp-code.result
View file @
ca242117
...
...
@@ -797,3 +797,33 @@ SELECT f1(3), f1(4), f1(5), f1(6) FROM DUAL;
f1(3) f1(4) f1(5) f1(6)
6006 8008 10008 12010
DROP FUNCTION f1;
# Testing CONTINUE statement
CREATE FUNCTION f1(a INT) RETURN INT
AS
total INT:= 0;
BEGIN
FOR i IN 1 .. a
LOOP
CONTINUE WHEN i=5;
total:= total + 1;
END LOOP;
RETURN total;
END;
/
SHOW FUNCTION CODE f1;
Pos Instruction
0 set total@1 0
1 set i@2 1
2 set [upper_bound]@3 a@0
3 jump_if_not 10(10) (i@2 <= [upper_bound]@3)
4 jump_if_not 7(0) (i@2 = 5)
5 set i@2 (i@2 + 1)
6 jump 3
7 set total@1 (total@1 + 1)
8 set i@2 (i@2 + 1)
9 jump 3
10 freturn 3 total@1
SELECT f1(3), f1(4), f1(5), f1(6) FROM DUAL;
f1(3) f1(4) f1(5) f1(6)
3 4 4 5
DROP FUNCTION f1;
mysql-test/suite/compat/oracle/r/sp.result
View file @
ca242117
...
...
@@ -946,3 +946,84 @@ SELECT f1(3,3,0), f1(3,3,1), f1(3,3,2), f1(3,3,3), f1(3,3,4) FROM DUAL;
f1(3,3,0) f1(3,3,1) f1(3,3,2) f1(3,3,3) f1(3,3,4)
3000 3003 3006 3009 3009
DROP FUNCTION f1;
# Testing CONTINUE statement
CREATE FUNCTION f1(a INT) RETURN INT
AS
total INT:= 0;
BEGIN
FOR i IN 1 .. a
LOOP
IF i=5 THEN
CONTINUE;
END IF;
total:= total + 1;
END LOOP;
RETURN total;
END;
/
SELECT f1(3), f1(4), f1(5), f1(6) FROM DUAL;
f1(3) f1(4) f1(5) f1(6)
3 4 4 5
DROP FUNCTION f1;
CREATE FUNCTION f1(a INT) RETURN INT
AS
total INT:= 0;
BEGIN
<<lj>>
FOR j IN 1 .. 2
LOOP
FOR i IN 1 .. a
LOOP
IF i=5 THEN
CONTINUE lj;
END IF;
total:= total + 1;
END LOOP;
END LOOP;
RETURN total;
END;
/
SELECT f1(3), f1(4), f1(5) FROM DUAL;
f1(3) f1(4) f1(5)
6 8 8
DROP FUNCTION f1;
CREATE FUNCTION f1(a INT) RETURN INT
AS
total INT:= 0;
BEGIN
<<lj>>
FOR j IN 1 .. 2
LOOP
FOR i IN 1 .. a
LOOP
CONTINUE lj WHEN i=5;
total:= total + 1;
END LOOP;
END LOOP;
RETURN total;
END;
/
SELECT f1(3), f1(4), f1(5) FROM DUAL;
f1(3) f1(4) f1(5)
6 8 8
DROP FUNCTION f1;
CREATE FUNCTION f1(a INT) RETURN INT
AS
total INT:= 0;
i INT:= 1;
BEGIN
WHILE i <= a
LOOP
i:= i + 1;
IF i=6 THEN
CONTINUE;
END IF;
total:= total + 1;
END LOOP;
RETURN total;
END;
/
SELECT f1(3), f1(4), f1(5), f1(6) FROM DUAL;
f1(3) f1(4) f1(5) f1(6)
3 4 4 5
DROP FUNCTION f1;
mysql-test/suite/compat/oracle/t/sp-code.test
View file @
ca242117
...
...
@@ -593,3 +593,25 @@ DELIMITER ;/
SHOW
FUNCTION
CODE
f1
;
SELECT
f1
(
3
),
f1
(
4
),
f1
(
5
),
f1
(
6
)
FROM
DUAL
;
DROP
FUNCTION
f1
;
--
echo
# Testing CONTINUE statement
DELIMITER
/
;
CREATE
FUNCTION
f1
(
a
INT
)
RETURN
INT
AS
total
INT
:=
0
;
BEGIN
FOR
i
IN
1
..
a
LOOP
CONTINUE
WHEN
i
=
5
;
total
:=
total
+
1
;
END
LOOP
;
RETURN
total
;
END
;
/
DELIMITER
;
/
SHOW
FUNCTION
CODE
f1
;
SELECT
f1
(
3
),
f1
(
4
),
f1
(
5
),
f1
(
6
)
FROM
DUAL
;
DROP
FUNCTION
f1
;
mysql-test/suite/compat/oracle/t/sp.test
View file @
ca242117
...
...
@@ -996,3 +996,93 @@ DELIMITER ;/
SHOW
FUNCTION
CODE
f1
;
SELECT
f1
(
3
,
3
,
0
),
f1
(
3
,
3
,
1
),
f1
(
3
,
3
,
2
),
f1
(
3
,
3
,
3
),
f1
(
3
,
3
,
4
)
FROM
DUAL
;
DROP
FUNCTION
f1
;
--
echo
# Testing CONTINUE statement
DELIMITER
/
;
CREATE
FUNCTION
f1
(
a
INT
)
RETURN
INT
AS
total
INT
:=
0
;
BEGIN
FOR
i
IN
1
..
a
LOOP
IF
i
=
5
THEN
CONTINUE
;
END
IF
;
total
:=
total
+
1
;
END
LOOP
;
RETURN
total
;
END
;
/
DELIMITER
;
/
SELECT
f1
(
3
),
f1
(
4
),
f1
(
5
),
f1
(
6
)
FROM
DUAL
;
DROP
FUNCTION
f1
;
DELIMITER
/
;
CREATE
FUNCTION
f1
(
a
INT
)
RETURN
INT
AS
total
INT
:=
0
;
BEGIN
<<
lj
>>
FOR
j
IN
1
..
2
LOOP
FOR
i
IN
1
..
a
LOOP
IF
i
=
5
THEN
CONTINUE
lj
;
END
IF
;
total
:=
total
+
1
;
END
LOOP
;
END
LOOP
;
RETURN
total
;
END
;
/
DELIMITER
;
/
SELECT
f1
(
3
),
f1
(
4
),
f1
(
5
)
FROM
DUAL
;
DROP
FUNCTION
f1
;
DELIMITER
/
;
CREATE
FUNCTION
f1
(
a
INT
)
RETURN
INT
AS
total
INT
:=
0
;
BEGIN
<<
lj
>>
FOR
j
IN
1
..
2
LOOP
FOR
i
IN
1
..
a
LOOP
CONTINUE
lj
WHEN
i
=
5
;
total
:=
total
+
1
;
END
LOOP
;
END
LOOP
;
RETURN
total
;
END
;
/
DELIMITER
;
/
SELECT
f1
(
3
),
f1
(
4
),
f1
(
5
)
FROM
DUAL
;
DROP
FUNCTION
f1
;
DELIMITER
/
;
CREATE
FUNCTION
f1
(
a
INT
)
RETURN
INT
AS
total
INT
:=
0
;
i
INT
:=
1
;
BEGIN
WHILE
i
<=
a
LOOP
i
:=
i
+
1
;
IF
i
=
6
THEN
CONTINUE
;
END
IF
;
total
:=
total
+
1
;
END
LOOP
;
RETURN
total
;
END
;
/
DELIMITER
;
/
SELECT
f1
(
3
),
f1
(
4
),
f1
(
5
),
f1
(
6
)
FROM
DUAL
;
DROP
FUNCTION
f1
;
sql/sql_lex.cc
View file @
ca242117
...
...
@@ -5675,6 +5675,12 @@ bool LEX::sp_iterate_statement(THD *thd, const LEX_STRING label_name)
my_error
(
ER_SP_LILABEL_MISMATCH
,
MYF
(
0
),
"ITERATE"
,
label_name
.
str
);
return
true
;
}
return
sp_continue_loop
(
thd
,
lab
);
}
bool
LEX
::
sp_continue_loop
(
THD
*
thd
,
sp_label
*
lab
)
{
if
(
lab
->
ctx
->
for_loop
().
m_index
)
{
// We're in a FOR loop, increment the index variable before backward jump
...
...
@@ -5689,6 +5695,53 @@ bool LEX::sp_iterate_statement(THD *thd, const LEX_STRING label_name)
}
bool
LEX
::
sp_continue_loop
(
THD
*
thd
,
sp_label
*
lab
,
Item
*
when
)
{
if
(
!
when
)
return
sp_continue_loop
(
thd
,
lab
);
sphead
->
reset_lex
(
thd
);
// This changes thd->lex
DBUG_ASSERT
(
sphead
==
thd
->
lex
->
sphead
);
DBUG_ASSERT
(
spcont
==
thd
->
lex
->
spcont
);
sp_instr_jump_if_not
*
i
=
new
(
thd
->
mem_root
)
sp_instr_jump_if_not
(
sphead
->
instructions
(),
spcont
,
when
,
thd
->
lex
);
if
(
i
==
NULL
||
sphead
->
add_instr
(
i
)
||
sphead
->
restore_lex
(
thd
)
||
sp_continue_loop
(
thd
,
lab
))
return
true
;
i
->
backpatch
(
sphead
->
instructions
(),
spcont
);
return
false
;
}
bool
LEX
::
sp_continue_statement
(
THD
*
thd
,
Item
*
when
)
{
sp_label
*
lab
=
spcont
->
find_label_current_loop_start
();
if
(
!
lab
)
{
my_error
(
ER_SP_LILABEL_MISMATCH
,
MYF
(
0
),
"CONTINUE"
,
""
);
return
true
;
}
DBUG_ASSERT
(
lab
->
type
==
sp_label
::
ITERATION
);
return
sp_continue_loop
(
thd
,
lab
,
when
);
}
bool
LEX
::
sp_continue_statement
(
THD
*
thd
,
const
LEX_STRING
label_name
,
Item
*
when
)
{
sp_label
*
lab
=
spcont
->
find_label
(
label_name
);
if
(
!
lab
||
lab
->
type
!=
sp_label
::
ITERATION
)
{
my_error
(
ER_SP_LILABEL_MISMATCH
,
MYF
(
0
),
"CONTINUE"
,
label_name
);
return
true
;
}
return
sp_continue_loop
(
thd
,
lab
,
when
);
}
bool
LEX
::
maybe_start_compound_statement
(
THD
*
thd
)
{
if
(
!
sphead
)
...
...
sql/sql_lex.h
View file @
ca242117
...
...
@@ -2634,6 +2634,9 @@ struct LEX: public Query_tables_list
bool
sp_exit_block
(
THD
*
thd
,
sp_label
*
lab
);
bool
sp_exit_block
(
THD
*
thd
,
sp_label
*
lab
,
Item
*
when
);
bool
sp_continue_loop
(
THD
*
thd
,
sp_label
*
lab
);
bool
sp_continue_loop
(
THD
*
thd
,
sp_label
*
lab
,
Item
*
when
);
bool
sp_for_loop_condition
(
THD
*
thd
,
const
Lex_for_loop_st
&
loop
);
bool
sp_for_loop_increment
(
THD
*
thd
,
const
Lex_for_loop_st
&
loop
);
...
...
@@ -3161,6 +3164,9 @@ struct LEX: public Query_tables_list
bool
sp_exit_statement
(
THD
*
thd
,
Item
*
when
);
bool
sp_exit_statement
(
THD
*
thd
,
const
LEX_STRING
label_name
,
Item
*
item
);
bool
sp_leave_statement
(
THD
*
thd
,
const
LEX_STRING
label_name
);
bool
sp_continue_statement
(
THD
*
thd
,
Item
*
when
);
bool
sp_continue_statement
(
THD
*
thd
,
const
LEX_STRING
label_name
,
Item
*
when
);
bool
sp_iterate_statement
(
THD
*
thd
,
const
LEX_STRING
label_name
);
bool
maybe_start_compound_statement
(
THD
*
thd
);
...
...
sql/sql_yacc_ora.yy
View file @
ca242117
...
...
@@ -1264,6 +1264,7 @@ END_OF_INPUT
%type <NONE> sp_proc_stmt_if
%type <NONE> sp_labeled_control sp_unlabeled_control
%type <NONE> sp_labeled_block sp_unlabeled_block sp_unlabeled_block_not_atomic
%type <NONE> sp_proc_stmt_continue
%type <NONE> sp_proc_stmt_exit
%type <NONE> sp_proc_stmt_leave
%type <NONE> sp_proc_stmt_iterate
...
...
@@ -2866,6 +2867,7 @@ sp_proc_stmt_in_returns_clause:
sp_proc_stmt:
sp_proc_stmt_in_returns_clause
| sp_proc_stmt_statement
| sp_proc_stmt_continue
| sp_proc_stmt_exit
| sp_proc_stmt_leave
| sp_proc_stmt_iterate
...
...
@@ -3004,6 +3006,20 @@ sp_proc_stmt_exit:
}
;
sp_proc_stmt_continue:
CONTINUE_SYM opt_sp_proc_stmt_exit_when_clause
{
if (Lex->sp_continue_statement(thd, $2))
MYSQL_YYABORT;
}
| CONTINUE_SYM label_ident opt_sp_proc_stmt_exit_when_clause
{
if (Lex->sp_continue_statement(thd, $2, $3))
MYSQL_YYABORT;
}
;
sp_proc_stmt_leave:
LEAVE_SYM label_ident
{
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment