Skip to content
项目
群组
代码片段
帮助
正在加载...
帮助
为 GitLab 提交贡献
登录/注册
切换导航
H
h2database
项目
项目
详情
活动
周期分析
仓库
仓库
文件
提交
分支
标签
贡献者
分枝图
比较
统计图
议题
0
议题
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
CI / CD
CI / CD
流水线
作业
计划
统计图
Wiki
Wiki
代码片段
代码片段
成员
成员
折叠边栏
关闭边栏
活动
分枝图
统计图
创建新议题
作业
提交
议题看板
打开侧边栏
Administrator
h2database
Commits
e0ffeed0
提交
e0ffeed0
authored
3月 06, 2019
作者:
Evgenij Ryazanov
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Do not convert standard TRIM function to non-standard functions
上级
5fe7ec4c
显示空白字符变更
内嵌
并排
正在显示
4 个修改的文件
包含
86 行增加
和
25 行删除
+86
-25
help.csv
h2/src/docsrc/help/help.csv
+1
-1
Parser.java
h2/src/main/org/h2/command/Parser.java
+24
-16
Function.java
h2/src/main/org/h2/expression/function/Function.java
+45
-1
trim.sql
h2/src/test/org/h2/test/scripts/functions/string/trim.sql
+16
-7
没有找到文件。
h2/src/docsrc/help/help.csv
浏览文件 @
e0ffeed0
...
@@ -4509,7 +4509,7 @@ RTRIM(NAME)
...
@@ -4509,7 +4509,7 @@ RTRIM(NAME)
"
"
"Functions (String)","TRIM","
"Functions (String)","TRIM","
TRIM ( [
{ LEADING | TRAILING | BOTH }
[ string ] FROM ] string )
TRIM ( [
[ LEADING | TRAILING | BOTH ]
[ string ] FROM ] string )
","
","
Removes all leading spaces, trailing spaces, or spaces at both ends, from a string.
Removes all leading spaces, trailing spaces, or spaces at both ends, from a string.
Other characters can be removed as well.
Other characters can be removed as well.
...
...
h2/src/main/org/h2/command/Parser.java
浏览文件 @
e0ffeed0
...
@@ -3582,32 +3582,40 @@ public class Parser {
...
@@ -3582,32 +3582,40 @@ public class Parser {
break
;
break
;
}
}
case
Function
.
TRIM
:
{
case
Function
.
TRIM
:
{
Expression
space
=
null
;
int
flags
;
boolean
needFrom
=
false
;
if
(
readIf
(
"LEADING"
))
{
if
(
readIf
(
"LEADING"
))
{
function
=
Function
.
getFunction
(
database
,
"LTRIM"
);
flags
=
Function
.
TRIM_LEADING
;
if
(!
readIf
(
FROM
))
{
needFrom
=
true
;
space
=
readExpression
();
read
(
FROM
);
}
}
else
if
(
readIf
(
"TRAILING"
))
{
}
else
if
(
readIf
(
"TRAILING"
))
{
function
=
Function
.
getFunction
(
database
,
"RTRIM"
);
flags
=
Function
.
TRIM_TRAILING
;
if
(!
readIf
(
FROM
))
{
needFrom
=
true
;
space
=
readExpression
();
}
else
{
read
(
FROM
);
needFrom
=
readIf
(
"BOTH"
);
flags
=
Function
.
TRIM_LEADING
|
Function
.
TRIM_TRAILING
;
}
}
}
else
if
(
readIf
(
"BOTH"
))
{
Expression
p0
,
space
=
null
;
function
.
setFlags
(
flags
);
if
(
needFrom
)
{
if
(!
readIf
(
FROM
))
{
if
(!
readIf
(
FROM
))
{
space
=
readExpression
();
space
=
readExpression
();
read
(
FROM
);
read
(
FROM
);
}
}
}
p0
=
readExpression
();
Expression
p0
=
readExpression
();
}
else
{
if
(
readIf
(
COMMA
))
{
if
(
readIf
(
FROM
))
{
space
=
readExpression
();
p0
=
readExpression
();
}
else
if
(
readIf
(
FROM
))
{
}
else
{
p0
=
readExpression
();
if
(
readIf
(
FROM
))
{
space
=
p0
;
space
=
p0
;
p0
=
readExpression
();
p0
=
readExpression
();
}
}
}
}
if
(!
needFrom
&&
space
==
null
&&
readIf
(
COMMA
))
{
space
=
readExpression
();
}
function
.
setParameter
(
0
,
p0
);
function
.
setParameter
(
0
,
p0
);
if
(
space
!=
null
)
{
if
(
space
!=
null
)
{
function
.
setParameter
(
1
,
space
);
function
.
setParameter
(
1
,
space
);
...
...
h2/src/main/org/h2/expression/function/Function.java
浏览文件 @
e0ffeed0
...
@@ -153,6 +153,16 @@ public class Function extends Expression implements FunctionCall {
...
@@ -153,6 +153,16 @@ public class Function extends Expression implements FunctionCall {
*/
*/
public
static
final
int
H2VERSION
=
231
;
public
static
final
int
H2VERSION
=
231
;
/**
* The flags for TRIM(LEADING ...) function.
*/
public
static
final
int
TRIM_LEADING
=
1
;
/**
* The flags for TRIM(TRAILING ...) function.
*/
public
static
final
int
TRIM_TRAILING
=
2
;
protected
static
final
int
VAR_ARGS
=
-
1
;
protected
static
final
int
VAR_ARGS
=
-
1
;
private
static
final
HashMap
<
String
,
FunctionInfo
>
FUNCTIONS
=
new
HashMap
<>(
256
);
private
static
final
HashMap
<
String
,
FunctionInfo
>
FUNCTIONS
=
new
HashMap
<>(
256
);
...
@@ -162,6 +172,7 @@ public class Function extends Expression implements FunctionCall {
...
@@ -162,6 +172,7 @@ public class Function extends Expression implements FunctionCall {
protected
final
FunctionInfo
info
;
protected
final
FunctionInfo
info
;
private
ArrayList
<
Expression
>
varArgs
;
private
ArrayList
<
Expression
>
varArgs
;
private
int
flags
;
protected
TypeInfo
type
;
protected
TypeInfo
type
;
private
final
Database
database
;
private
final
Database
database
;
...
@@ -573,6 +584,24 @@ public class Function extends Expression implements FunctionCall {
...
@@ -573,6 +584,24 @@ public class Function extends Expression implements FunctionCall {
}
}
}
}
/**
* Set the flags for this function.
*
* @param flags the flags to set
*/
public
void
setFlags
(
int
flags
)
{
this
.
flags
=
flags
;
}
/**
* Returns the flags.
*
* @return the flags
*/
public
int
getFlags
()
{
return
flags
;
}
@Override
@Override
public
Value
getValue
(
Session
session
)
{
public
Value
getValue
(
Session
session
)
{
return
getValueWithArgs
(
session
,
args
);
return
getValueWithArgs
(
session
,
args
);
...
@@ -1343,7 +1372,7 @@ public class Function extends Expression implements FunctionCall {
...
@@ -1343,7 +1372,7 @@ public class Function extends Expression implements FunctionCall {
break
;
break
;
case
TRIM:
case
TRIM:
result
=
ValueString
.
get
(
StringUtils
.
trim
(
v0
.
getString
(),
result
=
ValueString
.
get
(
StringUtils
.
trim
(
v0
.
getString
(),
true
,
true
,
v1
==
null
?
" "
:
v1
.
getString
()),
(
flags
&
TRIM_LEADING
)
!=
0
,
(
flags
&
TRIM_TRAILING
)
!=
0
,
v1
==
null
?
" "
:
v1
.
getString
()),
database
.
getMode
().
treatEmptyStringsAsNull
);
database
.
getMode
().
treatEmptyStringsAsNull
);
break
;
break
;
case
RTRIM:
case
RTRIM:
...
@@ -2602,6 +2631,21 @@ public class Function extends Expression implements FunctionCall {
...
@@ -2602,6 +2631,21 @@ public class Function extends Expression implements FunctionCall {
builder
.
append
(
'('
);
builder
.
append
(
'('
);
}
}
switch
(
info
.
type
)
{
switch
(
info
.
type
)
{
case
TRIM:
{
switch
(
flags
)
{
case
TRIM_LEADING:
builder
.
append
(
"LEADING "
);
break
;
case
TRIM_TRAILING:
builder
.
append
(
"TRAILING "
);
break
;
}
if
(
args
.
length
>
1
)
{
args
[
1
].
getSQL
(
builder
,
alwaysQuote
).
append
(
" FROM "
);
}
args
[
0
].
getSQL
(
builder
,
alwaysQuote
);
break
;
}
case
CAST:
{
case
CAST:
{
args
[
0
].
getSQL
(
builder
,
alwaysQuote
).
append
(
" AS "
).
append
(
new
Column
(
null
,
type
).
getCreateSQL
());
args
[
0
].
getSQL
(
builder
,
alwaysQuote
).
append
(
" AS "
).
append
(
new
Column
(
null
,
type
).
getCreateSQL
());
break
;
break
;
...
...
h2/src/test/org/h2/test/scripts/functions/string/trim.sql
浏览文件 @
e0ffeed0
...
@@ -3,14 +3,23 @@
...
@@ -3,14 +3,23 @@
-- Initial Developer: H2 Group
-- Initial Developer: H2 Group
--
--
create
memory
table
test
(
id
int
primary
key
,
name
varchar
(
255
)
);
CREATE
TABLE
TEST
(
ID
INT
PRIMARY
KEY
,
A
VARCHAR
,
B
VARCHAR
,
C
VARCHAR
)
AS
VALUES
(
1
,
'__A__'
,
' B '
,
'xAx'
);
>
ok
>
ok
insert
into
test
values
(
1
,
'Hello'
);
SELECT
TRIM
(
BOTH
'_'
FROM
A
),
'|'
||
TRIM
(
LEADING
FROM
B
)
||
'|'
,
TRIM
(
TRAILING
'x'
FROM
C
)
FROM
TEST
;
>
update
count
:
1
>
TRIM
(
'_'
FROM
A
)
(
'|'
||
TRIM
(
LEADING
B
))
||
'|'
TRIM
(
TRAILING
'x'
FROM
C
)
>
---------------- ------------------------------- -------------------------
>
A
|
B
|
xA
>
rows
:
1
select
TRIM
(
BOTH
'_'
FROM
'__A__'
)
A
,
TRIM
(
LEADING
FROM
' B '
)
BS
,
TRIM
(
TRAILING
'x'
FROM
'xAx'
)
XA
from
test
;
SELECT
LENGTH
(
TRIM
(
B
)),
LENGTH
(
TRIM
(
FROM
B
))
FROM
TEST
;
>
A
BS
XA
>
LENGTH
(
TRIM
(
B
))
LENGTH
(
TRIM
(
B
))
>
-
--
--
>
-
-------------- -------------
--
>
A
B
xA
>
1
1
>
rows
:
1
>
rows
:
1
SELECT
TRIM
(
BOTH
B
)
FROM
TEST
;
>
exception
SYNTAX_ERROR_2
DROP
TABLE
TEST
;
>
ok
编写
预览
Markdown
格式
0%
重试
或
添加新文件
添加附件
取消
您添加了
0
人
到此讨论。请谨慎行事。
请先完成此评论的编辑!
取消
请
注册
或者
登录
后发表评论