Skip to content
项目
群组
代码片段
帮助
正在加载...
帮助
为 GitLab 提交贡献
登录/注册
切换导航
H
h2database
项目
项目
详情
活动
周期分析
仓库
仓库
文件
提交
分支
标签
贡献者
分枝图
比较
统计图
议题
0
议题
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
CI / CD
CI / CD
流水线
作业
计划
统计图
Wiki
Wiki
代码片段
代码片段
成员
成员
折叠边栏
关闭边栏
活动
分枝图
统计图
创建新议题
作业
提交
议题看板
打开侧边栏
Administrator
h2database
Commits
cf06d6ec
提交
cf06d6ec
authored
8 年前
作者:
Max Englander
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
enum-support: add more test cases
上级
06c8cb75
隐藏空白字符变更
内嵌
并排
正在显示
4 个修改的文件
包含
54 行增加
和
10 行删除
+54
-10
ErrorCode.java
h2/src/main/org/h2/api/ErrorCode.java
+2
-2
Parser.java
h2/src/main/org/h2/command/Parser.java
+16
-5
ValueEnum.java
h2/src/main/org/h2/value/ValueEnum.java
+5
-1
testScript.sql
h2/src/test/org/h2/test/testScript.sql
+31
-2
没有找到文件。
h2/src/main/org/h2/api/ErrorCode.java
浏览文件 @
cf06d6ec
...
...
@@ -197,11 +197,11 @@ public class ErrorCode {
/**
* The error with code <code>22032</code> is thrown when an
* attempt is made to add or modify an ENUM-typed column so
* that
it would not have any enumerated values
.
* that
one or more of its enumerators would be empty
.
*
* Example:
* <pre>
* CREATE TABLE TEST(CASE ENUM());
* CREATE TABLE TEST(CASE ENUM(
' '
));
* </pre>
*/
public
static
final
int
ENUM_EMPTY
=
22032
;
...
...
This diff is collapsed.
Click to expand it.
h2/src/main/org/h2/command/Parser.java
浏览文件 @
cf06d6ec
...
...
@@ -146,6 +146,7 @@ import org.h2.value.ValueBoolean;
import
org.h2.value.ValueBytes
;
import
org.h2.value.ValueDate
;
import
org.h2.value.ValueDecimal
;
import
org.h2.value.ValueEnum
;
import
org.h2.value.ValueInt
;
import
org.h2.value.ValueLong
;
import
org.h2.value.ValueNull
;
...
...
@@ -4127,7 +4128,8 @@ public class Parser {
}
long
precision
=
-
1
;
int
displaySize
=
-
1
;
java
.
util
.
List
<
String
>
enumerators
=
null
;
java
.
util
.
List
<
String
>
enumeratorList
=
null
;
String
[]
enumerators
=
null
;
int
scale
=
-
1
;
String
comment
=
null
;
Column
templateColumn
=
null
;
...
...
@@ -4203,20 +4205,27 @@ public class Parser {
}
}
else
if
(
dataType
.
enumerated
)
{
if
(
readIf
(
"("
))
{
enumerator
s
=
new
ArrayList
<
String
>();
enumerator
List
=
new
ArrayList
<
String
>();
original
+=
'('
;
String
enumerator0
=
readString
();
enumerator
s
.
add
(
enumerator0
.
toLowerCase
().
trim
());
enumerator
List
.
add
(
enumerator0
.
toLowerCase
().
trim
());
original
+=
"'"
+
enumerator0
+
"'"
;
while
(
readIf
(
","
))
{
original
+=
','
;
String
enumeratorN
=
readString
();
original
+=
"'"
+
enumeratorN
+
"'"
;
enumerator
s
.
add
(
enumeratorN
.
toLowerCase
().
trim
());
enumerator
List
.
add
(
enumeratorN
.
toLowerCase
().
trim
());
}
read
(
")"
);
original
+=
')'
;
}
enumerators
=
enumeratorList
.
toArray
(
new
String
[
enumeratorList
.
size
()]);
try
{
ValueEnum
.
check
(
enumerators
);
}
catch
(
DbException
e
)
{
throw
e
.
addSQL
(
original
);
}
}
else
if
(
readIf
(
"("
))
{
// Support for MySQL: INT(11), MEDIUMINT(8) and so on.
// Just ignore the precision.
...
...
@@ -4237,8 +4246,10 @@ public class Parser {
throw
DbException
.
get
(
ErrorCode
.
INVALID_VALUE_SCALE_PRECISION
,
Integer
.
toString
(
scale
),
Long
.
toString
(
precision
));
}
Column
column
=
new
Column
(
columnName
,
type
,
precision
,
scale
,
displaySize
,
enumerators
==
null
?
null
:
enumerators
.
toArray
(
new
String
[
enumerators
.
size
()])
);
displaySize
,
enumerators
==
null
?
null
:
enumerators
);
if
(
templateColumn
!=
null
)
{
column
.
setNullable
(
templateColumn
.
isNullable
());
column
.
setDefaultExpression
(
session
,
...
...
This diff is collapsed.
Click to expand it.
h2/src/main/org/h2/value/ValueEnum.java
浏览文件 @
cf06d6ec
...
...
@@ -35,7 +35,7 @@ public class ValueEnum extends Value {
return
convertTo
(
Value
.
INT
).
add
(
iv
);
}
p
rivate
static
final
void
check
(
final
String
[]
enumerators
)
{
p
ublic
static
final
void
check
(
final
String
[]
enumerators
)
{
switch
(
validate
(
enumerators
))
{
case
VALID:
return
;
...
...
@@ -251,6 +251,10 @@ public class ValueEnum extends Value {
}
private
static
Validation
validate
(
final
String
[]
enumerators
)
{
if
(
enumerators
==
null
||
enumerators
.
length
==
0
)
{
return
Validation
.
EMPTY
;
}
for
(
int
i
=
0
;
i
<
enumerators
.
length
;
i
++)
{
if
(
enumerators
[
i
]
==
null
||
enumerators
[
i
].
trim
().
equals
(
""
))
{
return
Validation
.
EMPTY
;
...
...
This diff is collapsed.
Click to expand it.
h2/src/test/org/h2/test/testScript.sql
浏览文件 @
cf06d6ec
...
...
@@ -10590,13 +10590,21 @@ create table z.z (id int);
drop
schema
z
;
>
ok
--- enum support
create
table
card
(
rank
int
,
suit
enum
(
'hearts'
,
'clubs'
,
'spades'
,
'diamonds'
));
----------------
--- ENUM support
----------------
--- ENUM basic operations
create
table
card
(
rank
int
,
suit
enum
(
'hearts'
,
'clubs'
,
'spades'
));
>
ok
insert
into
card
(
rank
,
suit
)
values
(
0
,
'clubs'
),
(
3
,
'hearts'
);
>
update
count
:
2
alter
table
card
alter
column
suit
enum
(
'hearts'
,
'clubs'
,
'spades'
,
'diamonds'
);
>
ok
select
*
from
card
;
>
RANK
SUIT
>
---- ------
...
...
@@ -10624,11 +10632,32 @@ select rank from card where suit = 'diamonds';
>
----
>
8
--- ENUM integer-based operations
select
rank
from
card
where
suit
=
1
;
>
RANK
>
----
>
0
>
10
insert
into
card
(
rank
,
suit
)
values
(
5
,
2
);
>
update
count
:
1
select
*
from
card
where
rank
=
5
;
>
RANK
SUIT
>
---- ------
>
5
spades
--- ENUM edge cases
insert
into
card
(
rank
,
suit
)
values
(
6
,
' '
);
>
exception
alter
table
card
alter
column
suit
enum
(
'hearts'
,
'clubs'
,
'spades'
,
'diamonds'
,
'clubs'
);
>
exception
alter
table
card
alter
column
suit
enum
(
'hearts'
,
'clubs'
,
'spades'
,
'diamonds'
,
''
);
>
exception
drop
table
card
;
>
ok
This diff is collapsed.
Click to expand it.
编写
预览
Markdown
格式
0%
重试
或
添加新文件
添加附件
取消
您添加了
0
人
到此讨论。请谨慎行事。
请先完成此评论的编辑!
取消
请
注册
或者
登录
后发表评论