Skip to content
项目
群组
代码片段
帮助
正在加载...
帮助
为 GitLab 提交贡献
登录/注册
切换导航
H
h2database
项目
项目
详情
活动
周期分析
仓库
仓库
文件
提交
分支
标签
贡献者
分枝图
比较
统计图
议题
0
议题
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
CI / CD
CI / CD
流水线
作业
计划
统计图
Wiki
Wiki
代码片段
代码片段
成员
成员
折叠边栏
关闭边栏
活动
分枝图
统计图
创建新议题
作业
提交
议题看板
打开侧边栏
Administrator
h2database
Commits
36dfb831
Unverified
提交
36dfb831
authored
7 年前
作者:
Noel Grandin
提交者:
GitHub
7 年前
浏览文件
操作
浏览文件
下载
差异文件
Merge pull request #970 from ravd/master
Added support for ENUM in prepared statement where clause
上级
02c1775b
722d3753
master
version-1.4.198
version-1.4.197
无相关合并请求
显示空白字符变更
内嵌
并排
正在显示
3 个修改的文件
包含
51 行增加
和
6 行删除
+51
-6
Comparison.java
h2/src/main/org/h2/expression/Comparison.java
+19
-6
Value.java
h2/src/main/org/h2/value/Value.java
+11
-0
TestPreparedStatement.java
h2/src/test/org/h2/test/jdbc/TestPreparedStatement.java
+21
-0
没有找到文件。
h2/src/main/org/h2/expression/Comparison.java
浏览文件 @
36dfb831
...
@@ -16,10 +16,7 @@ import org.h2.table.Column;
...
@@ -16,10 +16,7 @@ import org.h2.table.Column;
import
org.h2.table.ColumnResolver
;
import
org.h2.table.ColumnResolver
;
import
org.h2.table.TableFilter
;
import
org.h2.table.TableFilter
;
import
org.h2.util.MathUtils
;
import
org.h2.util.MathUtils
;
import
org.h2.value.Value
;
import
org.h2.value.*
;
import
org.h2.value.ValueBoolean
;
import
org.h2.value.ValueGeometry
;
import
org.h2.value.ValueNull
;
/**
/**
* Example comparison expressions are ID=1, NAME=NAME, NAME IS NULL.
* Example comparison expressions are ID=1, NAME=NAME, NAME IS NULL.
...
@@ -266,12 +263,28 @@ public class Comparison extends Condition {
...
@@ -266,12 +263,28 @@ public class Comparison extends Condition {
}
}
}
}
int
dataType
=
Value
.
getHigherOrder
(
left
.
getType
(),
right
.
getType
());
int
dataType
=
Value
.
getHigherOrder
(
left
.
getType
(),
right
.
getType
());
if
(
dataType
==
Value
.
ENUM
)
{
String
[]
enumerators
=
getEnumerators
(
l
,
r
);
l
=
l
.
convertToEnum
(
enumerators
);
r
=
r
.
convertToEnum
(
enumerators
);
}
else
{
l
=
l
.
convertTo
(
dataType
);
l
=
l
.
convertTo
(
dataType
);
r
=
r
.
convertTo
(
dataType
);
r
=
r
.
convertTo
(
dataType
);
}
boolean
result
=
compareNotNull
(
database
,
l
,
r
,
compareType
);
boolean
result
=
compareNotNull
(
database
,
l
,
r
,
compareType
);
return
ValueBoolean
.
get
(
result
);
return
ValueBoolean
.
get
(
result
);
}
}
private
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.
* Compare two values, given the values are not NULL.
*
*
...
...
This diff is collapsed.
Click to expand it.
h2/src/main/org/h2/value/Value.java
浏览文件 @
36dfb831
...
@@ -592,6 +592,17 @@ public abstract class Value {
...
@@ -592,6 +592,17 @@ public abstract class Value {
return
convertTo
(
targetType
,
-
1
,
null
);
return
convertTo
(
targetType
,
-
1
,
null
);
}
}
/**
* Convert value to ENUM value
* @param enumerators allowed values for the ENUM to which the value is converted
* @return value represented as ENUM
*/
public
Value
convertToEnum
(
String
[]
enumerators
)
{
// Use -1 to indicate "default behaviour" where value conversion should not
// depend on any datatype precision.
return
convertTo
(
ENUM
,
-
1
,
null
,
null
,
enumerators
);
}
/**
/**
* Compare a value to the specified type.
* Compare a value to the specified type.
*
*
...
...
This diff is collapsed.
Click to expand it.
h2/src/test/org/h2/test/jdbc/TestPreparedStatement.java
浏览文件 @
36dfb831
...
@@ -479,6 +479,27 @@ public class TestPreparedStatement extends TestBase {
...
@@ -479,6 +479,27 @@ public class TestPreparedStatement extends TestBase {
assertEquals
(
Integer
.
class
,
o
.
getClass
());
assertEquals
(
Integer
.
class
,
o
.
getClass
());
}
}
for
(
int
i
=
0
;
i
<
goodSizes
.
length
;
i
++)
{
PreparedStatement
prep
=
conn
.
prepareStatement
(
"SELECT * FROM test_enum WHERE size = ?"
);
prep
.
setObject
(
1
,
goodSizes
[
i
]);
ResultSet
rs
=
prep
.
executeQuery
();
rs
.
next
();
String
s
=
rs
.
getString
(
1
);
assertTrue
(
s
.
equals
(
goodSizes
[
i
]));
assertFalse
(
rs
.
next
());
}
for
(
int
i
=
0
;
i
<
badSizes
.
length
;
i
++)
{
PreparedStatement
prep
=
conn
.
prepareStatement
(
"SELECT * FROM test_enum WHERE size = ?"
);
prep
.
setObject
(
1
,
badSizes
[
i
]);
if
(
config
.
lazy
)
{
ResultSet
resultSet
=
prep
.
executeQuery
();
assertThrows
(
ErrorCode
.
ENUM_VALUE_NOT_PERMITTED
,
resultSet
).
next
();
}
else
{
assertThrows
(
ErrorCode
.
ENUM_VALUE_NOT_PERMITTED
,
prep
).
executeQuery
();
}
}
stat
.
execute
(
"DROP TABLE test_enum"
);
stat
.
execute
(
"DROP TABLE test_enum"
);
}
}
...
...
This diff is collapsed.
Click to expand it.
编写
预览
Markdown
格式
0%
重试
或
添加新文件
添加附件
取消
您添加了
0
人
到此讨论。请谨慎行事。
请先完成此评论的编辑!
取消
请
注册
或者
登录
后发表评论