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
d5099814
Commit
d5099814
authored
Mar 15, 2018
by
Alexander Barkov
Browse files
Options
Browse Files
Download
Plain Diff
Merge remote-tracking branch 'origin/bb-10.2-ext' into 10.3
parents
1a0b573b
42433a2d
Changes
3
Hide 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 @
d5099814
#
# 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;
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)
...
...
@@ -22,19 +26,52 @@ SUBSTR('abc',2,null) SUBSTR('abc',1,null) SUBSTR('abc',0,null)
NULL NULL NULL
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)
create table t1 (c1 varchar(10),start integer, length integer);
NULL NULL NULL
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', 0, 1);
INSERT INTO t1 VALUES (null, 1, 1);
INSERT INTO t1 VALUES (null, 0, 1);
select substr(c1,start,length) from t1;
substr(c1,start,length)
INSERT INTO t1 VALUES ('abc', 1, 0);
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
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) ;
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
...
...
mysql-test/suite/compat/oracle/t/func_substr.test
View file @
d5099814
#
# MDEV-14012 - sql_mode=Oracle: substr(): treat position 0 as position 1
#
--
echo
#
--
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
;
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'
,
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
,
-
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'
,
0
,
1
);
INSERT
INTO
t1
VALUES
(
null
,
1
,
1
);
INSERT
INTO
t1
VALUES
(
null
,
0
,
1
);
select
substr
(
c1
,
start
,
length
)
from
t1
;
drop
table
t1
;
INSERT
INTO
t1
VALUES
(
'abc'
,
1
,
0
);
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
)
;
...
...
sql/item_strfunc.h
View file @
d5099814
...
...
@@ -35,7 +35,7 @@ class Item_str_func :public Item_func
character set. No memory is allocated.
@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
...
...
@@ -500,11 +500,18 @@ class Item_func_substr_oracle :public Item_func_substr
protected:
longlong
get_position
()
{
longlong
pos
=
args
[
1
]
->
val_int
();
return
pos
==
0
?
1
:
pos
;
}
String
*
make_empty_result
()
{
null_value
=
1
;
return
NULL
;
}
public:
Item_func_substr_oracle
(
THD
*
thd
,
Item
*
a
,
Item
*
b
)
:
Item_func_substr
(
thd
,
a
,
b
)
{}
Item_func_substr_oracle
(
THD
*
thd
,
Item
*
a
,
Item
*
b
,
Item
*
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"
;
}
Item
*
get_copy
(
THD
*
thd
)
{
return
get_item_copy
<
Item_func_substr_oracle
>
(
thd
,
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