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
3e6893e2
Commit
3e6893e2
authored
Mar 13, 2018
by
halfspawn
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
MDEV-10574 / SUBSTR - sql_mode=Oracle: return null instead of empty string
parent
1c4b6afb
Changes
3
Show whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
75 additions
and
12 deletions
+75
-12
mysql-test/suite/compat/oracle/r/func_substr.result
mysql-test/suite/compat/oracle/r/func_substr.result
+42
-5
mysql-test/suite/compat/oracle/t/func_substr.test
mysql-test/suite/compat/oracle/t/func_substr.test
+25
-6
sql/item_strfunc.h
sql/item_strfunc.h
+8
-1
No files found.
mysql-test/suite/compat/oracle/r/func_substr.result
View file @
3e6893e2
#
# MDEV-14012 - sql_mode=Oracle: substr(): treat position 0 as position 1
# MDEV-10574 - sql_mode=Oracle: return null instead of empty string
#
SET sql_mode=ORACLE;
SET sql_mode=ORACLE;
SELECT SUBSTR('abc',2,1),SUBSTR('abc',1,1), SUBSTR('abc',0,1) FROM dual;
SELECT SUBSTR('abc',2,1),SUBSTR('abc',1,1), SUBSTR('abc',0,1) FROM dual;
SUBSTR('abc',2,1) SUBSTR('abc',1,1) SUBSTR('abc',0,1)
SUBSTR('abc',2,1) SUBSTR('abc',1,1) SUBSTR('abc',0,1)
...
@@ -22,19 +26,52 @@ SUBSTR('abc',2,null) SUBSTR('abc',1,null) SUBSTR('abc',0,null)
...
@@ -22,19 +26,52 @@ SUBSTR('abc',2,null) SUBSTR('abc',1,null) SUBSTR('abc',0,null)
NULL NULL NULL
NULL NULL NULL
SELECT SUBSTR('abc',2,0),SUBSTR('abc',1,0), SUBSTR('abc',0,0) FROM dual;
SELECT SUBSTR('abc',2,0),SUBSTR('abc',1,0), SUBSTR('abc',0,0) FROM dual;
SUBSTR('abc',2,0) SUBSTR('abc',1,0) SUBSTR('abc',0,0)
SUBSTR('abc',2,0) SUBSTR('abc',1,0) SUBSTR('abc',0,0)
NULL NULL NULL
create table t1 (c1 varchar(10),start integer, length integer);
SELECT SUBSTR('abc',2,-1),SUBSTR('abc',1,-1), SUBSTR('abc',0,-1) FROM dual;
SUBSTR('abc',2,-1) SUBSTR('abc',1,-1) SUBSTR('abc',0,-1)
NULL NULL NULL
SELECT SUBSTR(SPACE(0),1) FROM DUAL;
SUBSTR(SPACE(0),1)
NULL
CREATE TABLE t1 (c1 VARCHAR(10),start INTEGER, length INTEGER);
INSERT INTO t1 VALUES ('abc', 1, 1);
INSERT INTO t1 VALUES ('abc', 1, 1);
INSERT INTO t1 VALUES ('abc', 0, 1);
INSERT INTO t1 VALUES ('abc', 0, 1);
INSERT INTO t1 VALUES (null, 1, 1);
INSERT INTO t1 VALUES (null, 1, 1);
INSERT INTO t1 VALUES (null, 0, 1);
INSERT INTO t1 VALUES (null, 0, 1);
select substr(c1,start,length) from t1;
INSERT INTO t1 VALUES ('abc', 1, 0);
substr(c1,start,length)
INSERT INTO t1 VALUES ('abc', 0, 0);
INSERT INTO t1 VALUES (null, 1, 0);
INSERT INTO t1 VALUES (null, 0, 0);
INSERT INTO t1 VALUES ('abc', 1, -1);
INSERT INTO t1 VALUES ('abc', 0, -1);
INSERT INTO t1 VALUES (null, 1, -1);
INSERT INTO t1 VALUES (null, 0, -1);
INSERT INTO t1 VALUES (SPACE(0), 0, 1);
SELECT SUBSTR(c1,start,length) FROM t1;
SUBSTR(c1,start,length)
a
a
a
a
NULL
NULL
NULL
NULL
drop table t1;
NULL
NULL
NULL
NULL
NULL
NULL
NULL
NULL
NULL
DROP TABLE t1;
CREATE TABLE t1 (c1 VARCHAR(10) NOT NULL);
CREATE TABLE t2 AS SELECT SUBSTR(C1,1,1) AS C1 from t1;
SHOW CREATE TABLE t2;
Table Create Table
t2 CREATE TABLE "t2" (
"C1" varchar(1) DEFAULT NULL
)
DROP TABLE t2;
DROP TABLE t1;
EXPLAIN EXTENDED SELECT SUBSTR('abc',2,1) ;
EXPLAIN EXTENDED SELECT SUBSTR('abc',2,1) ;
id select_type table type possible_keys key key_len ref rows filtered Extra
id select_type table type possible_keys key key_len ref rows filtered Extra
1 SIMPLE NULL NULL NULL NULL NULL NULL NULL NULL No tables used
1 SIMPLE NULL NULL NULL NULL NULL NULL NULL NULL No tables used
...
...
mysql-test/suite/compat/oracle/t/func_substr.test
View file @
3e6893e2
#
--
echo
#
# MDEV-14012 - sql_mode=Oracle: substr(): treat position 0 as position 1
--
echo
# MDEV-14012 - sql_mode=Oracle: substr(): treat position 0 as position 1
#
--
echo
# MDEV-10574 - sql_mode=Oracle: return null instead of empty string
--
echo
#
SET
sql_mode
=
ORACLE
;
SET
sql_mode
=
ORACLE
;
SELECT
SUBSTR
(
'abc'
,
2
,
1
),
SUBSTR
(
'abc'
,
1
,
1
),
SUBSTR
(
'abc'
,
0
,
1
)
FROM
dual
;
SELECT
SUBSTR
(
'abc'
,
2
,
1
),
SUBSTR
(
'abc'
,
1
,
1
),
SUBSTR
(
'abc'
,
0
,
1
)
FROM
dual
;
...
@@ -11,14 +12,32 @@ SELECT SUBSTR('abc',-2,1),SUBSTR('abc',-1,1), SUBSTR('abc',-0,1) FROM dual;
...
@@ -11,14 +12,32 @@ SELECT SUBSTR('abc',-2,1),SUBSTR('abc',-1,1), SUBSTR('abc',-0,1) FROM dual;
SELECT
SUBSTR
(
'abc'
,
null
)
FROM
dual
;
SELECT
SUBSTR
(
'abc'
,
null
)
FROM
dual
;
SELECT
SUBSTR
(
'abc'
,
2
,
null
),
SUBSTR
(
'abc'
,
1
,
null
),
SUBSTR
(
'abc'
,
0
,
null
)
FROM
dual
;
SELECT
SUBSTR
(
'abc'
,
2
,
null
),
SUBSTR
(
'abc'
,
1
,
null
),
SUBSTR
(
'abc'
,
0
,
null
)
FROM
dual
;
SELECT
SUBSTR
(
'abc'
,
2
,
0
),
SUBSTR
(
'abc'
,
1
,
0
),
SUBSTR
(
'abc'
,
0
,
0
)
FROM
dual
;
SELECT
SUBSTR
(
'abc'
,
2
,
0
),
SUBSTR
(
'abc'
,
1
,
0
),
SUBSTR
(
'abc'
,
0
,
0
)
FROM
dual
;
SELECT
SUBSTR
(
'abc'
,
2
,
-
1
),
SUBSTR
(
'abc'
,
1
,
-
1
),
SUBSTR
(
'abc'
,
0
,
-
1
)
FROM
dual
;
SELECT
SUBSTR
(
SPACE
(
0
),
1
)
FROM
DUAL
;
create
table
t1
(
c1
varchar
(
10
),
start
integer
,
length
integer
);
CREATE
TABLE
t1
(
c1
VARCHAR
(
10
),
start
INTEGER
,
length
INTEGER
);
INSERT
INTO
t1
VALUES
(
'abc'
,
1
,
1
);
INSERT
INTO
t1
VALUES
(
'abc'
,
1
,
1
);
INSERT
INTO
t1
VALUES
(
'abc'
,
0
,
1
);
INSERT
INTO
t1
VALUES
(
'abc'
,
0
,
1
);
INSERT
INTO
t1
VALUES
(
null
,
1
,
1
);
INSERT
INTO
t1
VALUES
(
null
,
1
,
1
);
INSERT
INTO
t1
VALUES
(
null
,
0
,
1
);
INSERT
INTO
t1
VALUES
(
null
,
0
,
1
);
select
substr
(
c1
,
start
,
length
)
from
t1
;
INSERT
INTO
t1
VALUES
(
'abc'
,
1
,
0
);
drop
table
t1
;
INSERT
INTO
t1
VALUES
(
'abc'
,
0
,
0
);
INSERT
INTO
t1
VALUES
(
null
,
1
,
0
);
INSERT
INTO
t1
VALUES
(
null
,
0
,
0
);
INSERT
INTO
t1
VALUES
(
'abc'
,
1
,
-
1
);
INSERT
INTO
t1
VALUES
(
'abc'
,
0
,
-
1
);
INSERT
INTO
t1
VALUES
(
null
,
1
,
-
1
);
INSERT
INTO
t1
VALUES
(
null
,
0
,
-
1
);
INSERT
INTO
t1
VALUES
(
SPACE
(
0
),
0
,
1
);
SELECT
SUBSTR
(
c1
,
start
,
length
)
FROM
t1
;
DROP
TABLE
t1
;
CREATE
TABLE
t1
(
c1
VARCHAR
(
10
)
NOT
NULL
);
CREATE
TABLE
t2
AS
SELECT
SUBSTR
(
C1
,
1
,
1
)
AS
C1
from
t1
;
SHOW
CREATE
TABLE
t2
;
DROP
TABLE
t2
;
DROP
TABLE
t1
;
EXPLAIN
EXTENDED
SELECT
SUBSTR
(
'abc'
,
2
,
1
)
;
EXPLAIN
EXTENDED
SELECT
SUBSTR
(
'abc'
,
2
,
1
)
;
...
...
sql/item_strfunc.h
View file @
3e6893e2
...
@@ -35,7 +35,7 @@ class Item_str_func :public Item_func
...
@@ -35,7 +35,7 @@ class Item_str_func :public Item_func
character set. No memory is allocated.
character set. No memory is allocated.
@retval A pointer to the str_value member.
@retval A pointer to the str_value member.
*/
*/
String
*
make_empty_result
()
virtual
String
*
make_empty_result
()
{
{
/*
/*
Reset string length to an empty string. We don't use str_value.set() as
Reset string length to an empty string. We don't use str_value.set() as
...
@@ -500,11 +500,18 @@ class Item_func_substr_oracle :public Item_func_substr
...
@@ -500,11 +500,18 @@ class Item_func_substr_oracle :public Item_func_substr
protected:
protected:
longlong
get_position
()
longlong
get_position
()
{
longlong
pos
=
args
[
1
]
->
val_int
();
return
pos
==
0
?
1
:
pos
;
}
{
longlong
pos
=
args
[
1
]
->
val_int
();
return
pos
==
0
?
1
:
pos
;
}
String
*
make_empty_result
()
{
null_value
=
1
;
return
NULL
;
}
public:
public:
Item_func_substr_oracle
(
THD
*
thd
,
Item
*
a
,
Item
*
b
)
:
Item_func_substr_oracle
(
THD
*
thd
,
Item
*
a
,
Item
*
b
)
:
Item_func_substr
(
thd
,
a
,
b
)
{}
Item_func_substr
(
thd
,
a
,
b
)
{}
Item_func_substr_oracle
(
THD
*
thd
,
Item
*
a
,
Item
*
b
,
Item
*
c
)
:
Item_func_substr_oracle
(
THD
*
thd
,
Item
*
a
,
Item
*
b
,
Item
*
c
)
:
Item_func_substr
(
thd
,
a
,
b
,
c
)
{}
Item_func_substr
(
thd
,
a
,
b
,
c
)
{}
void
fix_length_and_dec
()
{
Item_func_substr
::
fix_length_and_dec
();
maybe_null
=
true
;
}
const
char
*
func_name
()
const
{
return
"substr_oracle"
;
}
const
char
*
func_name
()
const
{
return
"substr_oracle"
;
}
Item
*
get_copy
(
THD
*
thd
,
MEM_ROOT
*
mem_root
)
Item
*
get_copy
(
THD
*
thd
,
MEM_ROOT
*
mem_root
)
{
return
get_item_copy
<
Item_func_substr_oracle
>
(
thd
,
mem_root
,
this
);
}
{
return
get_item_copy
<
Item_func_substr_oracle
>
(
thd
,
mem_root
,
this
);
}
...
...
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