Skip to content
项目
群组
代码片段
帮助
正在加载...
帮助
为 GitLab 提交贡献
登录/注册
切换导航
H
h2database
项目
项目
详情
活动
周期分析
仓库
仓库
文件
提交
分支
标签
贡献者
分枝图
比较
统计图
议题
0
议题
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
CI / CD
CI / CD
流水线
作业
计划
统计图
Wiki
Wiki
代码片段
代码片段
成员
成员
折叠边栏
关闭边栏
活动
分枝图
统计图
创建新议题
作业
提交
议题看板
打开侧边栏
Administrator
h2database
Commits
179736c2
提交
179736c2
authored
13 年前
作者:
Thomas Mueller
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
PostgreSQL compatibility: LOG(x) is base 10 in the PostgreSQL mode.
上级
a305387a
显示空白字符变更
内嵌
并排
正在显示
6 个修改的文件
包含
54 行增加
和
9 行删除
+54
-9
help.csv
h2/src/docsrc/help/help.csv
+1
-0
changelog.html
h2/src/docsrc/html/changelog.html
+1
-1
features.html
h2/src/docsrc/html/features.html
+1
-0
Mode.java
h2/src/main/org/h2/engine/Mode.java
+6
-0
Function.java
h2/src/main/org/h2/expression/Function.java
+10
-3
TestCompatibility.java
h2/src/test/org/h2/test/db/TestCompatibility.java
+35
-5
没有找到文件。
h2/src/docsrc/help/help.csv
浏览文件 @
179736c2
...
...
@@ -2625,6 +2625,7 @@ FLOOR(A)
{ LOG | LN } (numeric)
","
See also Java ""Math.log"".
In the PostgreSQL mode, LOG(x) is base 10.
This method returns a double.
","
LOG(A)
...
...
This diff is collapsed.
Click to expand it.
h2/src/docsrc/html/changelog.html
浏览文件 @
179736c2
...
...
@@ -18,7 +18,7 @@ Change Log
<h1>
Change Log
</h1>
<h2>
Next Version (unreleased)
</h2>
<ul><li>
-
<ul><li>
PostgreSQL compatibility: LOG(x) is base 10 in the PostgreSQL mode.
</li></ul>
<h2>
Version 1.3.164 (2012-02-03)
</h2>
...
...
This diff is collapsed.
Click to expand it.
h2/src/docsrc/html/features.html
浏览文件 @
179736c2
...
...
@@ -1133,6 +1133,7 @@ or the SQL statement <code>SET MODE PostgreSQL</code>.
digits are not be truncated, but the value is rounded.
</li><li>
The system columns
<code>
CTID
</code>
and
<code>
OID
</code>
are supported.
</li><li>
LOG(x) is base 10 in this mode.
</li></ul>
<h2
id=
"auto_reconnect"
>
Auto-Reconnect
</h2>
...
...
This diff is collapsed.
Click to expand it.
h2/src/main/org/h2/engine/Mode.java
浏览文件 @
179736c2
...
...
@@ -114,6 +114,11 @@ public class Mode {
*/
public
boolean
allowPlusForStringConcat
;
/**
* The function LOG() uses base 10 instead of E.
*/
public
boolean
logIsLogBase10
;
private
String
name
;
static
{
...
...
@@ -167,6 +172,7 @@ public class Mode {
mode
.
roundWhenConvertToLong
=
true
;
mode
.
supportOffsetFetch
=
true
;
mode
.
systemColumns
=
true
;
mode
.
logIsLogBase10
=
true
;
add
(
mode
);
}
...
...
This diff is collapsed.
Click to expand it.
h2/src/main/org/h2/expression/Function.java
浏览文件 @
179736c2
...
...
@@ -74,7 +74,7 @@ public class Function extends Expression implements FunctionCall {
CEILING
=
8
,
COS
=
9
,
COT
=
10
,
DEGREES
=
11
,
EXP
=
12
,
FLOOR
=
13
,
LOG
=
14
,
LOG10
=
15
,
MOD
=
16
,
PI
=
17
,
POWER
=
18
,
RADIANS
=
19
,
RAND
=
20
,
ROUND
=
21
,
ROUNDMAGIC
=
22
,
SIGN
=
23
,
SIN
=
24
,
SQRT
=
25
,
TAN
=
26
,
TRUNCATE
=
27
,
SECURE_RAND
=
28
,
HASH
=
29
,
ENCRYPT
=
30
,
DECRYPT
=
31
,
COMPRESS
=
32
,
EXPAND
=
33
,
ZERO
=
34
,
RANDOM_UUID
=
35
,
COSH
=
36
,
SINH
=
37
,
TANH
=
38
;
EXPAND
=
33
,
ZERO
=
34
,
RANDOM_UUID
=
35
,
COSH
=
36
,
SINH
=
37
,
TANH
=
38
,
LN
=
39
;
public
static
final
int
ASCII
=
50
,
BIT_LENGTH
=
51
,
CHAR
=
52
,
CHAR_LENGTH
=
53
,
CONCAT
=
54
,
DIFFERENCE
=
55
,
HEXTORAW
=
56
,
INSERT
=
57
,
INSTR
=
58
,
LCASE
=
59
,
LEFT
=
60
,
LENGTH
=
61
,
LOCATE
=
62
,
LTRIM
=
63
,
...
...
@@ -182,7 +182,7 @@ public class Function extends Expression implements FunctionCall {
addFunction
(
"EXP"
,
EXP
,
1
,
Value
.
DOUBLE
);
addFunction
(
"FLOOR"
,
FLOOR
,
1
,
Value
.
DOUBLE
);
addFunction
(
"LOG"
,
LOG
,
1
,
Value
.
DOUBLE
);
addFunction
(
"LN"
,
L
OG
,
1
,
Value
.
DOUBLE
);
addFunction
(
"LN"
,
L
N
,
1
,
Value
.
DOUBLE
);
addFunction
(
"LOG10"
,
LOG10
,
1
,
Value
.
DOUBLE
);
addFunction
(
"MOD"
,
MOD
,
2
,
Value
.
LONG
);
addFunction
(
"PI"
,
PI
,
0
,
Value
.
DOUBLE
);
...
...
@@ -495,8 +495,15 @@ public class Function extends Expression implements FunctionCall {
case
FLOOR:
result
=
ValueDouble
.
get
(
Math
.
floor
(
v0
.
getDouble
()));
break
;
case
LN:
result
=
ValueDouble
.
get
(
Math
.
log
(
v0
.
getDouble
()));
break
;
case
LOG:
if
(
database
.
getMode
().
logIsLogBase10
)
{
result
=
ValueDouble
.
get
(
Math
.
log10
(
v0
.
getDouble
()));
}
else
{
result
=
ValueDouble
.
get
(
Math
.
log
(
v0
.
getDouble
()));
}
break
;
case
LOG10:
result
=
ValueDouble
.
get
(
log10
(
v0
.
getDouble
()));
...
...
This diff is collapsed.
Click to expand it.
h2/src/test/org/h2/test/db/TestCompatibility.java
浏览文件 @
179736c2
...
...
@@ -43,6 +43,7 @@ public class TestCompatibility extends TestBase {
testColumnAlias
();
testUniqueIndexSingleNull
();
testUniqueIndexOracle
();
testPostgreSQL
();
testHsqlDb
();
testMySQL
();
testDB2
();
...
...
@@ -177,6 +178,9 @@ public class TestCompatibility extends TestBase {
private
void
testHsqlDb
()
throws
SQLException
{
Statement
stat
=
conn
.
createStatement
();
stat
.
execute
(
"set mode hsqldb"
);
testLog
(
Math
.
log
(
10
),
stat
);
stat
.
execute
(
"DROP TABLE TEST IF EXISTS; CREATE TABLE TEST(ID INT PRIMARY KEY); "
);
stat
.
execute
(
"CALL CURRENT_TIME"
);
stat
.
execute
(
"CALL CURRENT_TIMESTAMP"
);
...
...
@@ -191,7 +195,24 @@ public class TestCompatibility extends TestBase {
prep
.
setInt
(
1
,
2
);
prep
.
executeQuery
();
stat
.
execute
(
"DROP TABLE TEST IF EXISTS"
);
}
private
void
testLog
(
double
expected
,
Statement
stat
)
throws
SQLException
{
stat
.
execute
(
"create table log(id int)"
);
stat
.
execute
(
"insert into log values(1)"
);
ResultSet
rs
=
stat
.
executeQuery
(
"select log(10) from log"
);
rs
.
next
();
assertEquals
((
int
)
(
expected
*
100
),
(
int
)
(
rs
.
getDouble
(
1
)
*
100
));
rs
=
stat
.
executeQuery
(
"select ln(10) from log"
);
rs
.
next
();
assertEquals
((
int
)
(
Math
.
log
(
10
)
*
100
),
(
int
)
(
rs
.
getDouble
(
1
)
*
100
));
stat
.
execute
(
"drop table log"
);
}
private
void
testPostgreSQL
()
throws
SQLException
{
Statement
stat
=
conn
.
createStatement
();
stat
.
execute
(
"SET MODE PostgreSQL"
);
testLog
(
Math
.
log10
(
10
),
stat
);
}
private
void
testMySQL
()
throws
SQLException
{
...
...
@@ -213,6 +234,9 @@ public class TestCompatibility extends TestBase {
// need to reconnect, because meta data tables may be initialized
conn
.
close
();
conn
=
getConnection
(
"compatibility;MODE=MYSQL"
);
stat
=
conn
.
createStatement
();
testLog
(
Math
.
log
(
10
),
stat
);
stat
=
conn
.
createStatement
(
ResultSet
.
TYPE_SCROLL_INSENSITIVE
,
ResultSet
.
CONCUR_UPDATABLE
);
assertResult
(
"test"
,
stat
,
"SHOW TABLES"
);
ResultSet
rs
=
stat
.
executeQuery
(
"SELECT * FROM TEST"
);
...
...
@@ -271,6 +295,9 @@ public class TestCompatibility extends TestBase {
private
void
testDB2
()
throws
SQLException
{
conn
=
getConnection
(
"compatibility;MODE=DB2"
);
Statement
stat
=
conn
.
createStatement
();
testLog
(
Math
.
log
(
10
),
stat
);
ResultSet
res
=
conn
.
createStatement
().
executeQuery
(
"SELECT 1 FROM sysibm.sysdummy1"
);
res
.
next
();
assertEquals
(
"1"
,
res
.
getString
(
1
));
...
...
@@ -280,11 +307,11 @@ public class TestCompatibility extends TestBase {
executeQuery
(
"SELECT 1 FROM sysibm.sysdummy1"
);
conn
.
close
();
conn
=
getConnection
(
"compatibility;MODE=DB2"
);
Statement
stm
t
=
conn
.
createStatement
();
st
m
t
.
execute
(
"drop table test"
);
st
m
t
.
execute
(
"create table test(id varchar)"
);
st
m
t
.
execute
(
"insert into test values ('3'),('1'),('2')"
);
res
=
st
m
t
.
executeQuery
(
"select id from test order by id fetch next 2 rows only"
);
sta
t
=
conn
.
createStatement
();
st
a
t
.
execute
(
"drop table test"
);
st
a
t
.
execute
(
"create table test(id varchar)"
);
st
a
t
.
execute
(
"insert into test values ('3'),('1'),('2')"
);
res
=
st
a
t
.
executeQuery
(
"select id from test order by id fetch next 2 rows only"
);
conn
=
getConnection
(
"compatibility"
);
res
.
next
();
assertEquals
(
"1"
,
res
.
getString
(
1
));
...
...
@@ -295,6 +322,9 @@ public class TestCompatibility extends TestBase {
private
void
testDerby
()
throws
SQLException
{
conn
=
getConnection
(
"compatibility;MODE=Derby"
);
Statement
stat
=
conn
.
createStatement
();
testLog
(
Math
.
log
(
10
),
stat
);
ResultSet
res
=
conn
.
createStatement
().
executeQuery
(
"SELECT 1 FROM sysibm.sysdummy1 fetch next 1 row only"
);
res
.
next
();
assertEquals
(
"1"
,
res
.
getString
(
1
));
...
...
This diff is collapsed.
Click to expand it.
编写
预览
Markdown
格式
0%
重试
或
添加新文件
添加附件
取消
您添加了
0
人
到此讨论。请谨慎行事。
请先完成此评论的编辑!
取消
请
注册
或者
登录
后发表评论