Skip to content
项目
群组
代码片段
帮助
正在加载...
帮助
为 GitLab 提交贡献
登录/注册
切换导航
H
h2database
项目
项目
详情
活动
周期分析
仓库
仓库
文件
提交
分支
标签
贡献者
分枝图
比较
统计图
议题
0
议题
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
CI / CD
CI / CD
流水线
作业
计划
统计图
Wiki
Wiki
代码片段
代码片段
成员
成员
折叠边栏
关闭边栏
活动
分枝图
统计图
创建新议题
作业
提交
议题看板
打开侧边栏
Administrator
h2database
Commits
3582f26f
Unverified
提交
3582f26f
authored
1月 08, 2018
作者:
Noel Grandin
提交者:
GitHub
1月 08, 2018
浏览文件
操作
浏览文件
下载
差异文件
Merge pull request #719 from katzyn/regexp_replace
Issue #638: Oracle mode: incompatible regexp back-reference syntax
上级
b5341bb5
18b43461
隐藏空白字符变更
内嵌
并排
正在显示
5 个修改的文件
包含
91 行增加
和
29 行删除
+91
-29
Mode.java
h2/src/main/org/h2/engine/Mode.java
+6
-0
Function.java
h2/src/main/org/h2/expression/Function.java
+16
-0
regex-replace.sql
...st/org/h2/test/scripts/functions/string/regex-replace.sql
+55
-0
regexp-like.sql
...test/org/h2/test/scripts/functions/string/regexp-like.sql
+14
-0
testScript.sql
h2/src/test/org/h2/test/scripts/testScript.sql
+0
-29
没有找到文件。
h2/src/main/org/h2/engine/Mode.java
浏览文件 @
3582f26f
...
...
@@ -119,6 +119,11 @@ public class Mode {
*/
public
boolean
logIsLogBase10
;
/**
* The function REGEXP_REPLACE() uses \ for back-references.
*/
public
boolean
regexpReplaceBackslashReferences
;
/**
* SERIAL and BIGSERIAL columns are not automatically primary keys.
*/
...
...
@@ -255,6 +260,7 @@ public class Mode {
mode
.
convertOnlyToSmallerScale
=
true
;
mode
.
uniqueIndexSingleNullExceptAllColumnsAreNull
=
true
;
mode
.
treatEmptyStringsAsNull
=
true
;
mode
.
regexpReplaceBackslashReferences
=
true
;
mode
.
supportPoundSymbolForColumnNames
=
true
;
// Oracle accepts keys of the form <namespace>.*. See
// https://docs.oracle.com/database/121/JJDBC/jdbcvers.htm#JJDBC29006
...
...
h2/src/main/org/h2/expression/Function.java
浏览文件 @
3582f26f
...
...
@@ -1414,6 +1414,22 @@ public class Function extends Expression implements FunctionCall {
case
REGEXP_REPLACE:
{
String
regexp
=
v1
.
getString
();
String
replacement
=
v2
.
getString
();
if
(
database
.
getMode
().
regexpReplaceBackslashReferences
)
{
if
((
replacement
.
indexOf
(
'\\'
)
>=
0
)
||
(
replacement
.
indexOf
(
'$'
)
>=
0
))
{
StringBuilder
sb
=
new
StringBuilder
();
for
(
int
i
=
0
;
i
<
replacement
.
length
();
i
++)
{
char
c
=
replacement
.
charAt
(
i
);
if
(
c
==
'$'
)
{
sb
.
append
(
'\\'
);
}
else
if
(
c
==
'\\'
&&
++
i
<
replacement
.
length
())
{
c
=
replacement
.
charAt
(
i
);
sb
.
append
(
c
>=
'0'
&&
c
<=
'9'
?
'$'
:
'\\'
);
}
sb
.
append
(
c
);
}
replacement
=
sb
.
toString
();
}
}
String
regexpMode
=
v3
==
null
||
v3
.
getString
()
==
null
?
""
:
v3
.
getString
();
int
flags
=
makeRegexpFlags
(
regexpMode
);
...
...
h2/src/test/org/h2/test/scripts/functions/string/regex-replace.sql
浏览文件 @
3582f26f
...
...
@@ -2,3 +2,58 @@
-- and the EPL 1.0 (http://h2database.com/html/license.html).
-- Initial Developer: H2 Group
--
call
regexp_replace
(
'x'
,
'x'
,
'
\'
);
> exception
CALL REGEXP_REPLACE('
abckaboooom
', '
o
+
', '
o
');
> '
abckabom
'
> ----------
> abckabom
> rows: 1
select regexp_replace('
Sylvain
', '
S
..
', '
TOTO
', '
mni
') as X;
> X
> --------
> TOTOvain
> rows: 1
set mode oracle;
select regexp_replace('
first
last
', '
(
\
w
+
)
(
\
w
+
)
', '
\
2
\
1
') as X from dual;
> X
> ----------
> last first
> rows: 1
select regexp_replace('
first
last
', '
(
\
w
+
)
(
\
w
+
)
', '
\\
2
\
1
') as X from dual;
> X
> --------
>
\2
first
> rows: 1
select regexp_replace('
first
last
', '
(
\
w
+
)
(
\
w
+
)
', '
\$
2
\
1
') as X from dual;
> X
> --------
> $2 first
> rows: 1
select regexp_replace('
first
last
', '
(
\
w
+
)
(
\
w
+
)
', '
$
2
$
1
') as X from dual;
> X
> -----
> $2 $1
> rows: 1
set mode regular;
select regexp_replace('
first
last
', '
(
\
w
+
)
(
\
w
+
)
', '
\
2
\
1
') as X from dual;
> X
> ---
> 2 1
> rows: 1
select regexp_replace('
first
last
', '
(
\
w
+
)
(
\
w
+
)
', '
$
2
$
1
') as X from dual;
> X
> ----------
> last first
> rows: 1
h2/src/test/org/h2/test/scripts/functions/string/regexp-like.sql
浏览文件 @
3582f26f
...
...
@@ -2,3 +2,17 @@
-- and the EPL 1.0 (http://h2database.com/html/license.html).
-- Initial Developer: H2 Group
--
call
select
1
from
dual
where
regexp_like
(
'x'
,
'x'
,
'
\'
);
> exception
select x from dual where REGEXP_LIKE('
A
', '
[
a
-
z
]
', '
i
');
> X
> -
> 1
> rows: 1
select x from dual where REGEXP_LIKE('
A
', '
[
a
-
z
]
', '
c
');
> X
> -
> rows: 0
h2/src/test/org/h2/test/scripts/testScript.sql
浏览文件 @
3582f26f
...
...
@@ -164,12 +164,6 @@ select 1 from test group by x;
drop
table
test
;
>
ok
call
regexp_replace
(
'x'
,
'x'
,
'
\'
);
> exception
call select 1 from dual where regexp_like('
x
', '
x
', '
\
');
> exception
select
*
from
dual
where
x
=
x
+
1
or
x
in
(
2
,
0
);
>
X
>
-
...
...
@@ -2109,29 +2103,6 @@ drop table test;
set autocommit true;
> ok
CALL REGEXP_REPLACE('
abckaboooom
', '
o
+
', '
o
');
> '
abckabom
'
> ----------
> abckabom
> rows: 1
select x from dual where REGEXP_LIKE('
A
', '
[
a
-
z
]
', '
i
');
> X
> -
> 1
> rows: 1
select x from dual where REGEXP_LIKE('
A
', '
[
a
-
z
]
', '
c
');
> X
> -
> rows: 0
select regexp_replace('
Sylvain
', '
S
..
', '
TOTO
', '
mni
') as X;
> X
> --------
> TOTOvain
> rows: 1
SELECT '
Hello
' ~ '
He
.
*
' T1, '
HELLO
' ~ '
He
.
*
' F2, CAST('
HELLO
' AS VARCHAR_IGNORECASE) ~ '
He
.
*
' T3;
> T1 F2 T3
> ---- ----- ----
...
...
编写
预览
Markdown
格式
0%
重试
或
添加新文件
添加附件
取消
您添加了
0
人
到此讨论。请谨慎行事。
请先完成此评论的编辑!
取消
请
注册
或者
登录
后发表评论