Skip to content
项目
群组
代码片段
帮助
正在加载...
帮助
为 GitLab 提交贡献
登录/注册
切换导航
H
h2database
项目
项目
详情
活动
周期分析
仓库
仓库
文件
提交
分支
标签
贡献者
分枝图
比较
统计图
议题
0
议题
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
CI / CD
CI / CD
流水线
作业
计划
统计图
Wiki
Wiki
代码片段
代码片段
成员
成员
折叠边栏
关闭边栏
活动
分枝图
统计图
创建新议题
作业
提交
议题看板
打开侧边栏
Administrator
h2database
Commits
9dfec247
提交
9dfec247
authored
6月 10, 2015
作者:
Thomas Mueller
浏览文件
操作
浏览文件
下载
差异文件
Merge
上级
7352ba5d
be58ad0d
隐藏空白字符变更
内嵌
并排
正在显示
3 个修改的文件
包含
40 行增加
和
2 行删除
+40
-2
changelog.html
h2/src/docsrc/html/changelog.html
+2
-0
Function.java
h2/src/main/org/h2/expression/Function.java
+25
-1
TestFunctions.java
h2/src/test/org/h2/test/db/TestFunctions.java
+13
-1
没有找到文件。
h2/src/docsrc/html/changelog.html
浏览文件 @
9dfec247
...
@@ -24,6 +24,8 @@ Change Log
...
@@ -24,6 +24,8 @@ Change Log
<li>
The in-memory file systems (memFS: and memLZF:) did not support files larger than 2 GB
<li>
The in-memory file systems (memFS: and memLZF:) did not support files larger than 2 GB
due to an integer overflow.
due to an integer overflow.
</li>
</li>
<li>
Pull request #138: Added the simple Oracle function: ORA_HASH (+ tests) #138
</li>
<li>
Timestamps in the trace log follow the format (yyyy-MM-dd HH:mm:ss) instead
<li>
Timestamps in the trace log follow the format (yyyy-MM-dd HH:mm:ss) instead
of the old format (MM-dd HH:mm:ss). Patch by Richard Bull.
of the old format (MM-dd HH:mm:ss). Patch by Richard Bull.
</li>
</li>
...
...
h2/src/main/org/h2/expression/Function.java
浏览文件 @
9dfec247
...
@@ -92,7 +92,7 @@ public class Function extends Expression implements FunctionCall {
...
@@ -92,7 +92,7 @@ public class Function extends Expression implements FunctionCall {
STRINGDECODE
=
80
,
STRINGTOUTF8
=
81
,
UTF8TOSTRING
=
82
,
STRINGDECODE
=
80
,
STRINGTOUTF8
=
81
,
UTF8TOSTRING
=
82
,
XMLATTR
=
83
,
XMLNODE
=
84
,
XMLCOMMENT
=
85
,
XMLCDATA
=
86
,
XMLATTR
=
83
,
XMLNODE
=
84
,
XMLCOMMENT
=
85
,
XMLCDATA
=
86
,
XMLSTARTDOC
=
87
,
XMLTEXT
=
88
,
REGEXP_REPLACE
=
89
,
RPAD
=
90
,
XMLSTARTDOC
=
87
,
XMLTEXT
=
88
,
REGEXP_REPLACE
=
89
,
RPAD
=
90
,
LPAD
=
91
,
CONCAT_WS
=
92
,
TO_CHAR
=
93
,
TRANSLATE
=
94
;
LPAD
=
91
,
CONCAT_WS
=
92
,
TO_CHAR
=
93
,
TRANSLATE
=
94
,
ORA_HASH
=
95
;
public
static
final
int
CURDATE
=
100
,
CURTIME
=
101
,
DATE_ADD
=
102
,
public
static
final
int
CURDATE
=
100
,
CURTIME
=
101
,
DATE_ADD
=
102
,
DATE_DIFF
=
103
,
DAY_NAME
=
104
,
DAY_OF_MONTH
=
105
,
DATE_DIFF
=
103
,
DAY_NAME
=
104
,
DAY_OF_MONTH
=
105
,
...
@@ -297,6 +297,7 @@ public class Function extends Expression implements FunctionCall {
...
@@ -297,6 +297,7 @@ public class Function extends Expression implements FunctionCall {
addFunction
(
"RPAD"
,
RPAD
,
VAR_ARGS
,
Value
.
STRING
);
addFunction
(
"RPAD"
,
RPAD
,
VAR_ARGS
,
Value
.
STRING
);
addFunction
(
"LPAD"
,
LPAD
,
VAR_ARGS
,
Value
.
STRING
);
addFunction
(
"LPAD"
,
LPAD
,
VAR_ARGS
,
Value
.
STRING
);
addFunction
(
"TO_CHAR"
,
TO_CHAR
,
VAR_ARGS
,
Value
.
STRING
);
addFunction
(
"TO_CHAR"
,
TO_CHAR
,
VAR_ARGS
,
Value
.
STRING
);
addFunction
(
"ORA_HASH"
,
ORA_HASH
,
VAR_ARGS
,
Value
.
INT
);
addFunction
(
"TRANSLATE"
,
TRANSLATE
,
3
,
Value
.
STRING
);
addFunction
(
"TRANSLATE"
,
TRANSLATE
,
3
,
Value
.
STRING
);
// date
// date
...
@@ -1394,6 +1395,11 @@ public class Function extends Expression implements FunctionCall {
...
@@ -1394,6 +1395,11 @@ public class Function extends Expression implements FunctionCall {
v1
.
getInt
(),
v2
==
null
?
null
:
v2
.
getString
(),
false
),
v1
.
getInt
(),
v2
==
null
?
null
:
v2
.
getString
(),
false
),
database
.
getMode
().
treatEmptyStringsAsNull
);
database
.
getMode
().
treatEmptyStringsAsNull
);
break
;
break
;
case
ORA_HASH:
result
=
ValueLong
.
get
(
oraHash
(
v0
.
getString
(),
v1
==
null
?
null
:
v1
.
getInt
(),
v2
==
null
?
null
:
v2
.
getInt
()));
break
;
case
TO_CHAR:
case
TO_CHAR:
switch
(
v0
.
getType
()){
switch
(
v0
.
getType
()){
case
Value
.
TIME
:
case
Value
.
TIME
:
...
@@ -2039,6 +2045,20 @@ public class Function extends Expression implements FunctionCall {
...
@@ -2039,6 +2045,20 @@ public class Function extends Expression implements FunctionCall {
return
new
String
(
chars
);
return
new
String
(
chars
);
}
}
private
static
Integer
oraHash
(
String
s
,
Integer
bucket
,
Integer
seed
)
{
int
hc
=
s
.
hashCode
();
if
(
seed
!=
null
&&
seed
.
intValue
()
!=
0
)
{
hc
*=
seed
.
intValue
()
*
17
;
}
if
(
bucket
==
null
||
bucket
.
intValue
()
<=
0
)
{
// do nothing
}
else
{
hc
%=
bucket
.
intValue
();
}
return
hc
;
}
@Override
@Override
public
int
getType
()
{
public
int
getType
()
{
return
dataType
;
return
dataType
;
...
@@ -2088,6 +2108,10 @@ public class Function extends Expression implements FunctionCall {
...
@@ -2088,6 +2108,10 @@ public class Function extends Expression implements FunctionCall {
min
=
1
;
min
=
1
;
max
=
3
;
max
=
3
;
break
;
break
;
case
ORA_HASH:
min
=
1
;
max
=
3
;
break
;
case
REPLACE:
case
REPLACE:
case
LOCATE:
case
LOCATE:
case
INSTR:
case
INSTR:
...
...
h2/src/test/org/h2/test/db/TestFunctions.java
浏览文件 @
9dfec247
...
@@ -90,6 +90,7 @@ public class TestFunctions extends TestBase implements AggregateFunction {
...
@@ -90,6 +90,7 @@ public class TestFunctions extends TestBase implements AggregateFunction {
testNvl2
();
testNvl2
();
testConcatWs
();
testConcatWs
();
testTruncate
();
testTruncate
();
testOraHash
();
testToCharFromDateTime
();
testToCharFromDateTime
();
testToCharFromNumber
();
testToCharFromNumber
();
testToCharFromText
();
testToCharFromText
();
...
@@ -1221,6 +1222,18 @@ public class TestFunctions extends TestBase implements AggregateFunction {
...
@@ -1221,6 +1222,18 @@ public class TestFunctions extends TestBase implements AggregateFunction {
conn
.
close
();
conn
.
close
();
}
}
private
void
testOraHash
()
throws
SQLException
{
deleteDb
(
"functions"
);
Connection
conn
=
getConnection
(
"functions"
);
Statement
stat
=
conn
.
createStatement
();
String
testStr
=
"foo"
;
assertResult
(
String
.
valueOf
(
"foo"
.
hashCode
()),
stat
,
String
.
format
(
"SELECT ORA_HASH('%s') FROM DUAL"
,
testStr
));
assertResult
(
String
.
valueOf
(
"foo"
.
hashCode
()),
stat
,
String
.
format
(
"SELECT ORA_HASH('%s', 0) FROM DUAL"
,
testStr
));
assertResult
(
String
.
valueOf
(
"foo"
.
hashCode
()),
stat
,
String
.
format
(
"SELECT ORA_HASH('%s', 0, 0) FROM DUAL"
,
testStr
));
}
private
void
testToCharFromDateTime
()
throws
SQLException
{
private
void
testToCharFromDateTime
()
throws
SQLException
{
deleteDb
(
"functions"
);
deleteDb
(
"functions"
);
Connection
conn
=
getConnection
(
"functions"
);
Connection
conn
=
getConnection
(
"functions"
);
...
@@ -1658,7 +1671,6 @@ public class TestFunctions extends TestBase implements AggregateFunction {
...
@@ -1658,7 +1671,6 @@ public class TestFunctions extends TestBase implements AggregateFunction {
conn
.
close
();
conn
.
close
();
}
}
private
void
testGenerateSeries
()
throws
SQLException
{
private
void
testGenerateSeries
()
throws
SQLException
{
Connection
conn
=
getConnection
(
"functions"
);
Connection
conn
=
getConnection
(
"functions"
);
Statement
stat
=
conn
.
createStatement
();
Statement
stat
=
conn
.
createStatement
();
...
...
编写
预览
Markdown
格式
0%
重试
或
添加新文件
添加附件
取消
您添加了
0
人
到此讨论。请谨慎行事。
请先完成此评论的编辑!
取消
请
注册
或者
登录
后发表评论