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
ccb91eb3
Commit
ccb91eb3
authored
Sep 20, 2016
by
Alexander Barkov
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
MDEV-10839 sql_mode=ORACLE: Predefined exceptions: TOO_MANY_ROWS, NO_DATA_FOUND, DUP_VAL_ON_INDEX
parent
c2c45c55
Changes
5
Hide whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
160 additions
and
4 deletions
+160
-4
mysql-test/suite/compat/oracle/r/exception.result
mysql-test/suite/compat/oracle/r/exception.result
+53
-0
mysql-test/suite/compat/oracle/t/exception.test
mysql-test/suite/compat/oracle/t/exception.test
+54
-0
sql/sp_pcontext.cc
sql/sp_pcontext.cc
+27
-3
sql/sp_pcontext.h
sql/sp_pcontext.h
+25
-0
sql/sql_yacc_ora.yy
sql/sql_yacc_ora.yy
+1
-1
No files found.
mysql-test/suite/compat/oracle/r/exception.result
0 → 100644
View file @
ccb91eb3
SET sql_mode=ORACLE;
#
# sql_mode=ORACLE: Predefined exceptions: TOO_MANY_ROWS, NO_DATA_FOUND, DUP_VAL_ON_INDEX
#
#
# Testing NO_DATA_FOUND and TOO_MANY_ROWS
#
CREATE TABLE t1 (a INT);
INSERT INTO t1 VALUES (10),(20);
CREATE PROCEDURE p1(lim INT, res OUT VARCHAR)
AS
a INT;
BEGIN
SELECT a INTO a FROM t1 LIMIT lim;
EXCEPTION
WHEN TOO_MANY_ROWS THEN res:='--- too_many_rows cought ---';
WHEN NO_DATA_FOUND THEN res:='--- no_data_found cought ---';
END;
$$
SET @res='';
CALL p1(0, @res);
SELECT @res;
@res
--- no_data_found cought ---
CALL p1(2, @res);
SELECT @res;
@res
--- too_many_rows cought ---
DROP PROCEDURE p1;
DROP TABLE t1;
#
# Testing DUP_VAL_ON_INDEX
#
CREATE TABLE t1 (a INT PRIMARY KEY);
CREATE PROCEDURE p1(res OUT VARCHAR)
AS
BEGIN
INSERT INTO t1 VALUES (10);
INSERT INTO t1 VALUES (10);
EXCEPTION
WHEN DUP_VAL_ON_INDEX THEN res:='--- dup_val_on_index cought ---';
END;
$$
SET @res='';
CALL p1(@res);
SELECT @res;
@res
--- dup_val_on_index cought ---
SELECT * FROM t1;
a
10
DROP PROCEDURE p1;
DROP TABLE t1;
mysql-test/suite/compat/oracle/t/exception.test
0 → 100644
View file @
ccb91eb3
SET
sql_mode
=
ORACLE
;
--
echo
#
--
echo
# sql_mode=ORACLE: Predefined exceptions: TOO_MANY_ROWS, NO_DATA_FOUND, DUP_VAL_ON_INDEX
--
echo
#
--
echo
#
--
echo
# Testing NO_DATA_FOUND and TOO_MANY_ROWS
--
echo
#
CREATE
TABLE
t1
(
a
INT
);
INSERT
INTO
t1
VALUES
(
10
),(
20
);
DELIMITER
$$
;
CREATE
PROCEDURE
p1
(
lim
INT
,
res
OUT
VARCHAR
)
AS
a
INT
;
BEGIN
SELECT
a
INTO
a
FROM
t1
LIMIT
lim
;
EXCEPTION
WHEN
TOO_MANY_ROWS
THEN
res
:=
'--- too_many_rows cought ---'
;
WHEN
NO_DATA_FOUND
THEN
res
:=
'--- no_data_found cought ---'
;
END
;
$$
DELIMITER
;
$$
SET
@
res
=
''
;
CALL
p1
(
0
,
@
res
);
SELECT
@
res
;
CALL
p1
(
2
,
@
res
);
SELECT
@
res
;
DROP
PROCEDURE
p1
;
DROP
TABLE
t1
;
--
echo
#
--
echo
# Testing DUP_VAL_ON_INDEX
--
echo
#
CREATE
TABLE
t1
(
a
INT
PRIMARY
KEY
);
DELIMITER
$$
;
CREATE
PROCEDURE
p1
(
res
OUT
VARCHAR
)
AS
BEGIN
INSERT
INTO
t1
VALUES
(
10
);
INSERT
INTO
t1
VALUES
(
10
);
EXCEPTION
WHEN
DUP_VAL_ON_INDEX
THEN
res
:=
'--- dup_val_on_index cought ---'
;
END
;
$$
DELIMITER
;
$$
SET
@
res
=
''
;
CALL
p1
(
@
res
);
SELECT
@
res
;
SELECT
*
FROM
t1
;
DROP
PROCEDURE
p1
;
DROP
TABLE
t1
;
sql/sp_pcontext.cc
View file @
ccb91eb3
...
@@ -276,9 +276,7 @@ sp_condition_value *sp_pcontext::find_condition(const LEX_STRING name,
...
@@ -276,9 +276,7 @@ sp_condition_value *sp_pcontext::find_condition(const LEX_STRING name,
{
{
sp_condition
*
p
=
m_conditions
.
at
(
i
);
sp_condition
*
p
=
m_conditions
.
at
(
i
);
if
(
my_strnncoll
(
system_charset_info
,
if
(
p
->
eq_name
(
name
))
(
const
uchar
*
)
name
.
str
,
name
.
length
,
(
const
uchar
*
)
p
->
name
.
str
,
p
->
name
.
length
)
==
0
)
{
{
return
p
->
value
;
return
p
->
value
;
}
}
...
@@ -290,6 +288,32 @@ sp_condition_value *sp_pcontext::find_condition(const LEX_STRING name,
...
@@ -290,6 +288,32 @@ sp_condition_value *sp_pcontext::find_condition(const LEX_STRING name,
}
}
static
sp_condition_value
cond_no_data_found
(
ER_SP_FETCH_NO_DATA
),
cond_dup_val_on_index
(
ER_DUP_ENTRY
),
cond_too_many_rows
(
ER_TOO_MANY_ROWS
);
static
sp_condition
sp_predefined_conditions
[
3
]
=
{
sp_condition
(
C_STRING_WITH_LEN
(
"NO_DATA_FOUND"
),
&
cond_no_data_found
),
sp_condition
(
C_STRING_WITH_LEN
(
"DUP_VAL_ON_INDEX"
),
&
cond_dup_val_on_index
),
sp_condition
(
C_STRING_WITH_LEN
(
"TOO_MANY_ROWS"
),
&
cond_too_many_rows
)
};
sp_condition_value
*
sp_pcontext
::
find_predefined_condition
(
const
LEX_STRING
name
)
const
{
for
(
uint
i
=
0
;
i
<
array_elements
(
sp_predefined_conditions
)
;
i
++
)
{
if
(
sp_predefined_conditions
[
i
].
eq_name
(
name
))
return
sp_predefined_conditions
[
i
].
value
;
}
return
NULL
;
}
sp_handler
*
sp_pcontext
::
add_handler
(
THD
*
thd
,
sp_handler
*
sp_pcontext
::
add_handler
(
THD
*
thd
,
sp_handler
::
enum_type
type
)
sp_handler
::
enum_type
type
)
{
{
...
...
sql/sp_pcontext.h
View file @
ccb91eb3
...
@@ -198,6 +198,19 @@ class sp_condition : public Sql_alloc
...
@@ -198,6 +198,19 @@ class sp_condition : public Sql_alloc
name
(
_name
),
name
(
_name
),
value
(
_value
)
value
(
_value
)
{
}
{
}
sp_condition
(
const
char
*
name_arg
,
size_t
name_length_arg
,
sp_condition_value
*
value_arg
)
:
value
(
value_arg
)
{
name
.
str
=
(
char
*
)
name_arg
;
name
.
length
=
name_length_arg
;
}
bool
eq_name
(
const
LEX_STRING
str
)
const
{
return
my_strnncoll
(
system_charset_info
,
(
const
uchar
*
)
name
.
str
,
name
.
length
,
(
const
uchar
*
)
str
.
str
,
str
.
length
)
==
0
;
}
};
};
///////////////////////////////////////////////////////////////////////////
///////////////////////////////////////////////////////////////////////////
...
@@ -454,6 +467,16 @@ class sp_pcontext : public Sql_alloc
...
@@ -454,6 +467,16 @@ class sp_pcontext : public Sql_alloc
/// See comment for find_variable() above.
/// See comment for find_variable() above.
sp_condition_value
*
find_condition
(
const
LEX_STRING
name
,
sp_condition_value
*
find_condition
(
const
LEX_STRING
name
,
bool
current_scope_only
)
const
;
bool
current_scope_only
)
const
;
sp_condition_value
*
find_declared_or_predefined_condition
(
const
LEX_STRING
name
)
const
{
sp_condition_value
*
p
=
find_condition
(
name
,
false
);
if
(
p
)
return
p
;
return
find_predefined_condition
(
name
);
}
bool
declare_condition
(
THD
*
thd
,
const
LEX_STRING
name
,
bool
declare_condition
(
THD
*
thd
,
const
LEX_STRING
name
,
sp_condition_value
*
val
)
sp_condition_value
*
val
)
{
{
...
@@ -540,6 +563,8 @@ class sp_pcontext : public Sql_alloc
...
@@ -540,6 +563,8 @@ class sp_pcontext : public Sql_alloc
sp_pcontext
(
const
sp_pcontext
&
);
sp_pcontext
(
const
sp_pcontext
&
);
void
operator
=
(
sp_pcontext
&
);
void
operator
=
(
sp_pcontext
&
);
sp_condition_value
*
find_predefined_condition
(
const
LEX_STRING
name
)
const
;
private:
private:
/// m_max_var_index -- number of variables (including all types of arguments)
/// m_max_var_index -- number of variables (including all types of arguments)
/// in this context including all children contexts.
/// in this context including all children contexts.
...
...
sql/sql_yacc_ora.yy
View file @
ccb91eb3
...
@@ -2515,7 +2515,7 @@ sp_hcond:
...
@@ -2515,7 +2515,7 @@ sp_hcond:
}
}
| ident /* CONDITION name */
| ident /* CONDITION name */
{
{
$$= Lex->spcont->find_
condition($1, false
);
$$= Lex->spcont->find_
declared_or_predefined_condition($1
);
if ($$ == NULL)
if ($$ == NULL)
my_yyabort_error((ER_SP_COND_MISMATCH, MYF(0), $1.str));
my_yyabort_error((ER_SP_COND_MISMATCH, MYF(0), $1.str));
}
}
...
...
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