Skip to content
项目
群组
代码片段
帮助
正在加载...
帮助
为 GitLab 提交贡献
登录/注册
切换导航
H
h2database
项目
项目
详情
活动
周期分析
仓库
仓库
文件
提交
分支
标签
贡献者
分枝图
比较
统计图
议题
0
议题
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
CI / CD
CI / CD
流水线
作业
计划
统计图
Wiki
Wiki
代码片段
代码片段
成员
成员
折叠边栏
关闭边栏
活动
分枝图
统计图
创建新议题
作业
提交
议题看板
打开侧边栏
Administrator
h2database
Commits
4e06655a
提交
4e06655a
authored
8 年前
作者:
Max Englander
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
restrict permitted values for enum columns
上级
2b755214
显示空白字符变更
内嵌
并排
正在显示
7 个修改的文件
包含
48 行增加
和
1 行删除
+48
-1
_messages_en.prop
h2/src/docsrc/textbase/_messages_en.prop
+1
-0
ErrorCode.java
h2/src/main/org/h2/api/ErrorCode.java
+13
-0
Parser.java
h2/src/main/org/h2/command/Parser.java
+1
-1
_messages_en.prop
h2/src/main/org/h2/res/_messages_en.prop
+1
-0
_messages_es.prop
h2/src/main/org/h2/res/_messages_es.prop
+1
-0
Column.java
h2/src/main/org/h2/table/Column.java
+20
-0
Value.java
h2/src/main/org/h2/value/Value.java
+11
-0
没有找到文件。
h2/src/docsrc/textbase/_messages_en.prop
浏览文件 @
4e06655a
...
@@ -9,6 +9,7 @@
...
@@ -9,6 +9,7 @@
22012=Division by zero: {0}
22012=Division by zero: {0}
22018=Data conversion error converting {0}
22018=Data conversion error converting {0}
22025=Error in LIKE ESCAPE: {0}
22025=Error in LIKE ESCAPE: {0}
22030=Value not permitted for column {0}: {1}
23502=NULL not allowed for column {0}
23502=NULL not allowed for column {0}
23503=Referential integrity constraint violation: {0}
23503=Referential integrity constraint violation: {0}
23505=Unique index or primary key violation: {0}
23505=Unique index or primary key violation: {0}
...
...
This diff is collapsed.
Click to expand it.
h2/src/main/org/h2/api/ErrorCode.java
浏览文件 @
4e06655a
...
@@ -159,6 +159,19 @@ public class ErrorCode {
...
@@ -159,6 +159,19 @@ public class ErrorCode {
*/
*/
public
static
final
int
LIKE_ESCAPE_ERROR_1
=
22025
;
public
static
final
int
LIKE_ESCAPE_ERROR_1
=
22025
;
/**
* The error with code <code>22030</code> is thrown when
* an attempt is made to insert or update an ENUM value,
* but the target value is not one of the values permitted
* by the column.
* Example:
* <pre>
* CREATE TABLE TEST(ID INT, CASE ENUM('sensitive','insensitive'));
* INSERT INTO TEST VALUES(1, 'Hello');
* </pre>
*/
public
static
final
int
VALUE_NOT_PERMITTED
=
22030
;
// 23: constraint violation
// 23: constraint violation
/**
/**
...
...
This diff is collapsed.
Click to expand it.
h2/src/main/org/h2/command/Parser.java
浏览文件 @
4e06655a
...
@@ -4136,7 +4136,7 @@ public class Parser {
...
@@ -4136,7 +4136,7 @@ public class Parser {
if
(
readIf
(
"("
))
{
if
(
readIf
(
"("
))
{
permittedValues
.
add
(
readString
());
permittedValues
.
add
(
readString
());
while
(
readIf
(
","
))
while
(
readIf
(
","
))
readString
(
);
permittedValues
.
add
(
readString
()
);
read
(
")"
);
read
(
")"
);
}
}
}
else
if
(
readIf
(
"("
))
{
}
else
if
(
readIf
(
"("
))
{
...
...
This diff is collapsed.
Click to expand it.
h2/src/main/org/h2/res/_messages_en.prop
浏览文件 @
4e06655a
...
@@ -9,6 +9,7 @@
...
@@ -9,6 +9,7 @@
22012=Division by zero: {0}
22012=Division by zero: {0}
22018=Data conversion error converting {0}
22018=Data conversion error converting {0}
22025=Error in LIKE ESCAPE: {0}
22025=Error in LIKE ESCAPE: {0}
22030=Value not permitted for column {0}: {1}
23502=NULL not allowed for column {0}
23502=NULL not allowed for column {0}
23503=Referential integrity constraint violation: {0}
23503=Referential integrity constraint violation: {0}
23505=Unique index or primary key violation: {0}
23505=Unique index or primary key violation: {0}
...
...
This diff is collapsed.
Click to expand it.
h2/src/main/org/h2/res/_messages_es.prop
浏览文件 @
4e06655a
...
@@ -9,6 +9,7 @@
...
@@ -9,6 +9,7 @@
22012=División por cero: {0}
22012=División por cero: {0}
22018=Conversión de datos fallida, convirtiendo {0}
22018=Conversión de datos fallida, convirtiendo {0}
22025=Error en LIKE ESCAPE: {0}
22025=Error en LIKE ESCAPE: {0}
22030=Valor no permitido para la columna {0}: {1}
23502=La columna {0} no permite valores nulos (NULL)
23502=La columna {0} no permite valores nulos (NULL)
23503=Violación de una restricción de Integridad Referencial: {0}
23503=Violación de una restricción de Integridad Referencial: {0}
23505=Violación de indice de Unicidad ó Clave primaria: {0}
23505=Violación de indice de Unicidad ó Clave primaria: {0}
...
...
This diff is collapsed.
Click to expand it.
h2/src/main/org/h2/table/Column.java
浏览文件 @
4e06655a
...
@@ -6,6 +6,7 @@
...
@@ -6,6 +6,7 @@
package
org
.
h2
.
table
;
package
org
.
h2
.
table
;
import
java.sql.ResultSetMetaData
;
import
java.sql.ResultSetMetaData
;
import
java.util.Iterator
;
import
java.util.Set
;
import
java.util.Set
;
import
org.h2.api.ErrorCode
;
import
org.h2.api.ErrorCode
;
import
org.h2.command.Parser
;
import
org.h2.command.Parser
;
...
@@ -356,6 +357,16 @@ public class Column {
...
@@ -356,6 +357,16 @@ public class Column {
getCreateSQL
(),
s
+
" ("
+
value
.
getPrecision
()
+
")"
);
getCreateSQL
(),
s
+
" ("
+
value
.
getPrecision
()
+
")"
);
}
}
}
}
if
(
permittedValues
!=
null
)
{
if
(!
value
.
checkPermitted
(
permittedValues
))
{
String
s
=
value
.
getTraceSQL
();
if
(
s
.
length
()
>
127
)
{
s
=
s
.
substring
(
0
,
128
)
+
"..."
;
}
throw
DbException
.
get
(
ErrorCode
.
VALUE_NOT_PERMITTED
,
getCreateSQL
(),
s
+
" ("
+
value
.
getString
()
+
")"
);
}
}
updateSequenceIfRequired
(
session
,
value
);
updateSequenceIfRequired
(
session
,
value
);
return
value
;
return
value
;
}
}
...
@@ -444,6 +455,15 @@ public class Column {
...
@@ -444,6 +455,15 @@ public class Column {
case
Value
.
DECIMAL
:
case
Value
.
DECIMAL
:
buff
.
append
(
'('
).
append
(
precision
).
append
(
", "
).
append
(
scale
).
append
(
')'
);
buff
.
append
(
'('
).
append
(
precision
).
append
(
", "
).
append
(
scale
).
append
(
')'
);
break
;
break
;
case
Value
.
ENUM
:
buff
.
append
(
'('
);
Iterator
<
String
>
it
=
permittedValues
.
iterator
();
while
(
it
.
hasNext
())
{
buff
.
append
(
'\''
).
append
(
it
.
next
()).
append
(
'\''
);
if
(
it
.
hasNext
())
{
buff
.
append
(
','
);
}
}
case
Value
.
BYTES
:
case
Value
.
BYTES
:
case
Value
.
STRING
:
case
Value
.
STRING
:
case
Value
.
STRING_IGNORECASE
:
case
Value
.
STRING_IGNORECASE
:
...
...
This diff is collapsed.
Click to expand it.
h2/src/main/org/h2/value/Value.java
浏览文件 @
4e06655a
...
@@ -18,6 +18,7 @@ import java.sql.SQLException;
...
@@ -18,6 +18,7 @@ import java.sql.SQLException;
import
java.sql.Time
;
import
java.sql.Time
;
import
java.sql.Timestamp
;
import
java.sql.Timestamp
;
import
java.sql.Types
;
import
java.sql.Types
;
import
java.util.Set
;
import
org.h2.api.ErrorCode
;
import
org.h2.api.ErrorCode
;
import
org.h2.engine.Constants
;
import
org.h2.engine.Constants
;
import
org.h2.engine.SysProperties
;
import
org.h2.engine.SysProperties
;
...
@@ -1129,6 +1130,16 @@ public abstract class Value {
...
@@ -1129,6 +1130,16 @@ public abstract class Value {
// nothing to do
// nothing to do
}
}
/**
* Check to see if this value is one of the given permitted values.
*
* @param permittedValues the permitted values
* @return true if this value is one of the permitted values
*/
public
boolean
checkPermitted
(
Set
<
String
>
permittedValues
)
{
return
permittedValues
.
contains
(
getString
());
}
/**
/**
* Check if the precision is smaller or equal than the given precision.
* Check if the precision is smaller or equal than the given precision.
*
*
...
...
This diff is collapsed.
Click to expand it.
编写
预览
Markdown
格式
0%
重试
或
添加新文件
添加附件
取消
您添加了
0
人
到此讨论。请谨慎行事。
请先完成此评论的编辑!
取消
请
注册
或者
登录
后发表评论