Skip to content
项目
群组
代码片段
帮助
正在加载...
帮助
为 GitLab 提交贡献
登录/注册
切换导航
H
h2database
项目
项目
详情
活动
周期分析
仓库
仓库
文件
提交
分支
标签
贡献者
分枝图
比较
统计图
议题
0
议题
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
CI / CD
CI / CD
流水线
作业
计划
统计图
Wiki
Wiki
代码片段
代码片段
成员
成员
折叠边栏
关闭边栏
活动
分枝图
统计图
创建新议题
作业
提交
议题看板
打开侧边栏
Administrator
h2database
Commits
c75170fd
提交
c75170fd
authored
6月 18, 2017
作者:
httpdigest
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Add correct handling of CHAR = CHAR(1) in PostgreSQL compatibility mode
上级
62ff12af
显示空白字符变更
内嵌
并排
正在显示
2 个修改的文件
包含
38 行增加
和
3 行删除
+38
-3
ValueStringFixed.java
h2/src/main/org/h2/value/ValueStringFixed.java
+18
-3
TestCompatibility.java
h2/src/test/org/h2/test/db/TestCompatibility.java
+20
-0
没有找到文件。
h2/src/main/org/h2/value/ValueStringFixed.java
浏览文件 @
c75170fd
...
...
@@ -35,9 +35,12 @@ public class ValueStringFixed extends ValueString {
}
private
static
String
trimRight
(
String
s
)
{
return
trimRight
(
s
,
0
);
}
private
static
String
trimRight
(
String
s
,
int
minLength
)
{
int
endIndex
=
s
.
length
()
-
1
;
int
i
=
endIndex
;
while
(
i
>=
0
&&
s
.
charAt
(
i
)
==
' '
)
{
while
(
i
>=
minLength
&&
s
.
charAt
(
i
)
==
' '
)
{
i
--;
}
s
=
i
==
endIndex
?
s
:
s
.
substring
(
0
,
i
+
1
);
...
...
@@ -87,9 +90,21 @@ public class ValueStringFixed extends ValueString {
* @return the value
*/
public
static
ValueStringFixed
get
(
String
s
,
int
precision
,
Mode
mode
)
{
if
(
mode
!=
null
&&
mode
.
padFixedLengthStrings
&&
precision
<
Integer
.
MAX_VALUE
)
{
// Should fixed strings be padded?
if
(
mode
!=
null
&&
mode
.
padFixedLengthStrings
)
{
if
(
precision
==
Integer
.
MAX_VALUE
)
{
// CHAR without a length specification is identical to CHAR(1)
precision
=
1
;
}
if
(
s
.
length
()
<
precision
)
{
// We have to pad
s
=
rightPadWithSpaces
(
s
,
precision
);
}
else
{
// We should trim, because inserting 'A ' into a CHAR(1) is possible!
s
=
trimRight
(
s
,
precision
);
}
}
else
if
(
precision
!=
PRECISION_DO_NOT_TRIM
)
{
// Default behaviour of H2
s
=
trimRight
(
s
);
}
if
(
s
.
length
()
==
0
)
{
...
...
h2/src/test/org/h2/test/db/TestCompatibility.java
浏览文件 @
c75170fd
...
...
@@ -253,6 +253,26 @@ public class TestCompatibility extends TestBase {
/* Test that WHERE clauses accept unpadded values and will pad before comparison */
assertResult
(
"Hello "
,
stat
,
"SELECT CH FROM TEST WHERE CH = 'Hello'"
);
/* Test CHAR which is identical to CHAR(1) */
stat
.
execute
(
"DROP TABLE IF EXISTS TEST"
);
stat
.
execute
(
"CREATE TABLE TEST(CH CHAR)"
);
stat
.
execute
(
"INSERT INTO TEST (CH) VALUES ('')"
);
assertResult
(
" "
,
stat
,
"SELECT CH FROM TEST"
);
assertResult
(
" "
,
stat
,
"SELECT CH FROM TEST WHERE CH = ''"
);
/* Test that excessive spaces are trimmed */
stat
.
execute
(
"DELETE FROM TEST"
);
stat
.
execute
(
"INSERT INTO TEST (CH) VALUES ('1 ')"
);
assertResult
(
"1"
,
stat
,
"SELECT CH FROM TEST"
);
assertResult
(
"1"
,
stat
,
"SELECT CH FROM TEST WHERE CH = '1 '"
);
/* Test that we do not trim too far */
stat
.
execute
(
"DROP TABLE IF EXISTS TEST"
);
stat
.
execute
(
"CREATE TABLE TEST(CH CHAR(2))"
);
stat
.
execute
(
"INSERT INTO TEST (CH) VALUES ('1 ')"
);
assertResult
(
"1 "
,
stat
,
"SELECT CH FROM TEST"
);
assertResult
(
"1 "
,
stat
,
"SELECT CH FROM TEST WHERE CH = '1 '"
);
}
private
void
testMySQL
()
throws
SQLException
{
...
...
编写
预览
Markdown
格式
0%
重试
或
添加新文件
添加附件
取消
您添加了
0
人
到此讨论。请谨慎行事。
请先完成此评论的编辑!
取消
请
注册
或者
登录
后发表评论