Skip to content
项目
群组
代码片段
帮助
正在加载...
帮助
为 GitLab 提交贡献
登录/注册
切换导航
H
h2database
项目
项目
详情
活动
周期分析
仓库
仓库
文件
提交
分支
标签
贡献者
分枝图
比较
统计图
议题
0
议题
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
CI / CD
CI / CD
流水线
作业
计划
统计图
Wiki
Wiki
代码片段
代码片段
成员
成员
折叠边栏
关闭边栏
活动
分枝图
统计图
创建新议题
作业
提交
议题看板
打开侧边栏
Administrator
h2database
Commits
8cdf96f4
提交
8cdf96f4
authored
10月 20, 2015
作者:
Ivo Smid
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
ISSUE-115 - to_char fails with pattern FM0D099
上级
b2a70c1c
隐藏空白字符变更
内嵌
并排
正在显示
3 个修改的文件
包含
43 行增加
和
2 行删除
+43
-2
changelog.html
h2/src/docsrc/html/changelog.html
+3
-1
ToChar.java
h2/src/main/org/h2/util/ToChar.java
+22
-1
TestFunctions.java
h2/src/test/org/h2/test/db/TestFunctions.java
+18
-0
没有找到文件。
h2/src/docsrc/html/changelog.html
浏览文件 @
8cdf96f4
...
...
@@ -27,13 +27,15 @@ Change Log
</li>
<li>
Issue #186: The "script" command did not include sequences of temporary tables.
</li>
<li>
Issue #115: to_char fails with pattern FM0D099
</li>
</ul>
<h2>
Version 1.4.190 Beta (2015-10-11)
</h2>
<ul>
<li>
Pull request #183: optimizer hints (so far without special SQL syntax).
</li>
<li>
Issue #180: In MVCC mode, executing UPDATE and SELECT ... FOR UPDATE
<li>
Issue #180: In MVCC mode, executing UPDATE and SELECT ... FOR UPDATE
simultaneously silently can drop rows.
</li>
<li>
PageStore storage: the cooperative file locking mechanism
...
...
h2/src/main/org/h2/util/ToChar.java
浏览文件 @
8cdf96f4
...
...
@@ -11,6 +11,7 @@ import java.sql.Timestamp;
import
java.text.DecimalFormat
;
import
java.text.DecimalFormatSymbols
;
import
java.text.SimpleDateFormat
;
import
java.util.Arrays
;
import
java.util.Calendar
;
import
java.util.Currency
;
import
java.util.GregorianCalendar
;
...
...
@@ -219,7 +220,7 @@ public class ToChar {
}
StringBuilder
output
=
new
StringBuilder
();
String
unscaled
=
number
.
unscaledValue
().
abs
().
toString
();
String
unscaled
=
(
number
.
abs
().
compareTo
(
BigDecimal
.
ONE
)
<
0
?
zeroesAfterDecimalSeparator
(
number
)
:
""
)
+
number
.
unscaledValue
().
abs
().
toString
();
// start at the decimal point and fill in the numbers to the left,
// working our way from right to left
...
...
@@ -328,6 +329,26 @@ public class ToChar {
return
output
.
toString
();
}
private
static
String
zeroesAfterDecimalSeparator
(
BigDecimal
number
)
{
final
String
numberStr
=
number
.
toString
();
final
int
idx
=
numberStr
.
indexOf
(
'.'
);
if
(
idx
>=
0
)
{
int
i
=
idx
+
1
;
boolean
allZeroes
=
true
;
for
(;
i
<
numberStr
.
length
();
i
++)
{
if
(
numberStr
.
charAt
(
i
)
!=
'0'
)
{
allZeroes
=
false
;
break
;
}
}
final
char
[]
zeroes
=
new
char
[
allZeroes
?
numberStr
.
length
()
-
idx
-
1
:
i
-
1
-
idx
];
Arrays
.
fill
(
zeroes
,
'0'
);
return
String
.
valueOf
(
zeroes
);
}
else
{
return
""
;
}
}
private
static
void
addSign
(
StringBuilder
output
,
int
signum
,
boolean
leadingSign
,
boolean
trailingSign
,
boolean
trailingMinus
,
boolean
angleBrackets
,
boolean
fillMode
)
{
...
...
h2/src/test/org/h2/test/db/TestFunctions.java
浏览文件 @
8cdf96f4
...
...
@@ -1699,6 +1699,24 @@ public class TestFunctions extends TestBase implements AggregateFunction {
assertThrows
(
ErrorCode
.
INVALID_TO_CHAR_FORMAT
,
stat
,
"SELECT TO_CHAR(123.45, 'q999.99') FROM DUAL"
);
// ISSUE-115
assertResult
(
"0.123"
,
stat
,
"select to_char(0.123, 'FM0.099') from dual;"
);
assertResult
(
"1.123"
,
stat
,
"select to_char(1.1234, 'FM0.099') from dual;"
);
assertResult
(
"1.1234"
,
stat
,
"select to_char(1.1234, 'FM0.0999') from dual;"
);
assertResult
(
"1.023"
,
stat
,
"select to_char(1.023, 'FM0.099') from dual;"
);
assertResult
(
"0.012"
,
stat
,
"select to_char(0.012, 'FM0.099') from dual;"
);
assertResult
(
"0.123"
,
stat
,
"select to_char(0.123, 'FM0.099') from dual;"
);
assertResult
(
"0.001"
,
stat
,
"select to_char(0.001, 'FM0.099') from dual;"
);
assertResult
(
"0.001"
,
stat
,
"select to_char(0.0012, 'FM0.099') from dual;"
);
assertResult
(
"0.002"
,
stat
,
"select to_char(0.0019, 'FM0.099') from dual;"
);
assertResult
(
"0.0"
,
stat
,
"select to_char(0, 'FM0D099') from dual;"
);
assertResult
(
"0.00"
,
stat
,
"select to_char(0., 'FM0D009') from dual;"
);
assertResult
(
"0."
,
stat
,
"select to_char(0, 'FM0D9') from dual;"
);
assertResult
(
"0.0"
,
stat
,
"select to_char(0.0, 'FM0D099') from dual;"
);
assertResult
(
"0.00"
,
stat
,
"select to_char(0.00, 'FM0D009') from dual;"
);
assertResult
(
"0.00"
,
stat
,
"select to_char(0, 'FM0D009') from dual;"
);
assertResult
(
"0.0"
,
stat
,
"select to_char(0, 'FM0D09') from dual;"
);
assertResult
(
"0.0"
,
stat
,
"select to_char(0, 'FM0D0') from dual;"
);
conn
.
close
();
}
...
...
编写
预览
Markdown
格式
0%
重试
或
添加新文件
添加附件
取消
您添加了
0
人
到此讨论。请谨慎行事。
请先完成此评论的编辑!
取消
请
注册
或者
登录
后发表评论