Skip to content
项目
群组
代码片段
帮助
正在加载...
帮助
为 GitLab 提交贡献
登录/注册
切换导航
H
h2database
项目
项目
详情
活动
周期分析
仓库
仓库
文件
提交
分支
标签
贡献者
分枝图
比较
统计图
议题
0
议题
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
CI / CD
CI / CD
流水线
作业
计划
统计图
Wiki
Wiki
代码片段
代码片段
成员
成员
折叠边栏
关闭边栏
活动
分枝图
统计图
创建新议题
作业
提交
议题看板
打开侧边栏
Administrator
h2database
Commits
bf23f856
提交
bf23f856
authored
6 年前
作者:
Evgenij Ryazanov
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Fix ON DUPLICATE KEY UPDATE with ENUM
上级
542100a4
隐藏空白字符变更
内嵌
并排
正在显示
4 个修改的文件
包含
41 行增加
和
13 行删除
+41
-13
Comparison.java
h2/src/main/org/h2/expression/Comparison.java
+1
-11
Table.java
h2/src/main/org/h2/table/Table.java
+9
-2
ValueEnum.java
h2/src/main/org/h2/value/ValueEnum.java
+20
-0
TestDuplicateKeyUpdate.java
h2/src/test/org/h2/test/db/TestDuplicateKeyUpdate.java
+11
-0
没有找到文件。
h2/src/main/org/h2/expression/Comparison.java
浏览文件 @
bf23f856
...
...
@@ -272,7 +272,7 @@ public class Comparison extends Condition {
}
int
dataType
=
Value
.
getHigherOrder
(
left
.
getType
(),
right
.
getType
());
if
(
dataType
==
Value
.
ENUM
)
{
String
[]
enumerators
=
getEnumerators
(
l
,
r
);
String
[]
enumerators
=
ValueEnum
.
getEnumeratorsForBinaryOperation
(
l
,
r
);
l
=
l
.
convertToEnum
(
enumerators
);
r
=
r
.
convertToEnum
(
enumerators
);
}
else
{
...
...
@@ -283,16 +283,6 @@ public class Comparison extends Condition {
return
ValueBoolean
.
get
(
result
);
}
private
static
String
[]
getEnumerators
(
Value
left
,
Value
right
)
{
if
(
left
.
getType
()
==
Value
.
ENUM
)
{
return
((
ValueEnum
)
left
).
getEnumerators
();
}
else
if
(
right
.
getType
()
==
Value
.
ENUM
)
{
return
((
ValueEnum
)
right
).
getEnumerators
();
}
else
{
return
new
String
[
0
];
}
}
/**
* Compare two values, given the values are not NULL.
*
...
...
This diff is collapsed.
Click to expand it.
h2/src/main/org/h2/table/Table.java
浏览文件 @
bf23f856
...
...
@@ -40,6 +40,7 @@ import org.h2.schema.TriggerObject;
import
org.h2.util.Utils
;
import
org.h2.value.CompareMode
;
import
org.h2.value.Value
;
import
org.h2.value.ValueEnum
;
import
org.h2.value.ValueNull
;
/**
...
...
@@ -1192,8 +1193,14 @@ public abstract class Table extends SchemaObjectBase {
return
0
;
}
int
dataType
=
Value
.
getHigherOrder
(
a
.
getType
(),
b
.
getType
());
a
=
a
.
convertTo
(
dataType
);
b
=
b
.
convertTo
(
dataType
);
if
(
dataType
==
Value
.
ENUM
)
{
String
[]
enumerators
=
ValueEnum
.
getEnumeratorsForBinaryOperation
(
a
,
b
);
a
=
a
.
convertToEnum
(
enumerators
);
b
=
b
.
convertToEnum
(
enumerators
);
}
else
{
a
=
a
.
convertTo
(
dataType
);
b
=
b
.
convertTo
(
dataType
);
}
return
a
.
compareTypeSafe
(
b
,
compareMode
);
}
...
...
This diff is collapsed.
Click to expand it.
h2/src/main/org/h2/value/ValueEnum.java
浏览文件 @
bf23f856
...
...
@@ -81,6 +81,26 @@ public class ValueEnum extends ValueEnumBase {
throw
DbException
.
get
(
ErrorCode
.
GENERAL_ERROR_1
,
"Unexpected error"
);
}
/**
* Returns enumerators for the two specified values for a binary operation.
*
* @param left
* left (first) operand
* @param right
* right (second) operand
* @return enumerators from the left or the right value, or an empty array if
* both values do not have enumerators
*/
public
static
String
[]
getEnumeratorsForBinaryOperation
(
Value
left
,
Value
right
)
{
if
(
left
.
getType
()
==
Value
.
ENUM
)
{
return
((
ValueEnum
)
left
).
getEnumerators
();
}
else
if
(
right
.
getType
()
==
Value
.
ENUM
)
{
return
((
ValueEnum
)
right
).
getEnumerators
();
}
else
{
return
new
String
[
0
];
}
}
public
String
[]
getEnumerators
()
{
return
enumerators
;
}
...
...
This diff is collapsed.
Click to expand it.
h2/src/test/org/h2/test/db/TestDuplicateKeyUpdate.java
浏览文件 @
bf23f856
...
...
@@ -40,6 +40,7 @@ public class TestDuplicateKeyUpdate extends TestBase {
testOnDuplicateKeyInsertMultiValue
(
conn
);
testPrimaryKeyAndUniqueKey
(
conn
);
testUpdateCountAndQualifiedNames
(
conn
);
testEnum
(
conn
);
conn
.
close
();
deleteDb
(
"duplicateKeyUpdate"
);
}
...
...
@@ -300,4 +301,14 @@ public class TestDuplicateKeyUpdate extends TestBase {
stat
.
execute
(
"drop schema s2 cascade"
);
}
private
void
testEnum
(
Connection
conn
)
throws
SQLException
{
Statement
stat
=
conn
.
createStatement
();
stat
.
execute
(
"create table test(e enum('a', 'b') unique)"
);
PreparedStatement
ps
=
conn
.
prepareStatement
(
"insert into test(e) values (?) on duplicate key update e = e"
);
ps
.
setString
(
1
,
"a"
);
assertEquals
(
1
,
ps
.
executeUpdate
());
assertEquals
(
0
,
ps
.
executeUpdate
());
stat
.
execute
(
"drop table test"
);
}
}
This diff is collapsed.
Click to expand it.
编写
预览
Markdown
格式
0%
重试
或
添加新文件
添加附件
取消
您添加了
0
人
到此讨论。请谨慎行事。
请先完成此评论的编辑!
取消
请
注册
或者
登录
后发表评论