Skip to content
项目
群组
代码片段
帮助
正在加载...
帮助
为 GitLab 提交贡献
登录/注册
切换导航
H
h2database
项目
项目
详情
活动
周期分析
仓库
仓库
文件
提交
分支
标签
贡献者
分枝图
比较
统计图
议题
0
议题
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
CI / CD
CI / CD
流水线
作业
计划
统计图
Wiki
Wiki
代码片段
代码片段
成员
成员
折叠边栏
关闭边栏
活动
分枝图
统计图
创建新议题
作业
提交
议题看板
打开侧边栏
Administrator
h2database
Commits
25e44117
提交
25e44117
authored
7月 12, 2017
作者:
httpdigest
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Check for unsupported column types in PostgreSQL mode
上级
5831e75e
隐藏空白字符变更
内嵌
并排
正在显示
3 个修改的文件
包含
42 行增加
和
6 行删除
+42
-6
Parser.java
h2/src/main/org/h2/command/Parser.java
+9
-3
Mode.java
h2/src/main/org/h2/engine/Mode.java
+18
-3
TestCompatibility.java
h2/src/test/org/h2/test/db/TestCompatibility.java
+15
-0
没有找到文件。
h2/src/main/org/h2/command/Parser.java
浏览文件 @
25e44117
...
...
@@ -4002,8 +4002,14 @@ public class Parser {
private
Column
parseColumnForTable
(
String
columnName
,
boolean
defaultNullable
)
{
Column
column
;
boolean
isIdentity
=
false
;
if
(
readIf
(
"IDENTITY"
)
||
readIf
(
"BIGSERIAL"
))
{
boolean
isIdentity
=
readIf
(
"IDENTITY"
);
if
(
isIdentity
||
readIf
(
"BIGSERIAL"
))
{
// Check if any of them are disallowed in the current Mode
if
(
isIdentity
&&
session
.
getDatabase
().
getMode
().
disallowedTypes
.
contains
(
"IDENTITY"
))
{
throw
DbException
.
get
(
ErrorCode
.
UNKNOWN_DATA_TYPE_1
,
currentToken
);
}
column
=
new
Column
(
columnName
,
Value
.
LONG
);
column
.
setOriginalSQL
(
"IDENTITY"
);
parseAutoIncrement
(
column
);
...
...
@@ -4176,7 +4182,7 @@ public class Parser {
enumerators
=
templateColumn
.
getEnumerators
();
}
else
{
dataType
=
DataType
.
getTypeByName
(
original
);
if
(
dataType
==
null
)
{
if
(
dataType
==
null
||
session
.
getDatabase
().
getMode
().
disallowedTypes
.
contains
(
original
)
)
{
throw
DbException
.
get
(
ErrorCode
.
UNKNOWN_DATA_TYPE_1
,
currentToken
);
}
...
...
h2/src/main/org/h2/engine/Mode.java
浏览文件 @
25e44117
...
...
@@ -5,12 +5,14 @@
*/
package
org
.
h2
.
engine
;
import
org.h2.util.New
;
import
org.h2.util.StringUtils
;
import
java.util.Collections
;
import
java.util.HashMap
;
import
java.util.Set
;
import
java.util.regex.Pattern
;
import
org.h2.util.New
;
import
org.h2.util.StringUtils
;
/**
* The compatibility modes. There is a fixed set of modes (for example
* PostgreSQL, MySQL). Each mode has different settings.
...
...
@@ -170,6 +172,13 @@ public class Mode {
*/
public
boolean
allowDB2TimestampFormat
;
/**
* An optional Set of hidden/disallowed column types.
* Certain DBMSs don't support all column types provided by H2, such as
* "NUMBER" when using PostgreSQL mode.
*/
public
Set
<
String
>
disallowedTypes
=
Collections
.
emptySet
();
private
final
String
name
;
static
{
...
...
@@ -268,6 +277,12 @@ public class Mode {
Pattern
.
compile
(
"ApplicationName"
);
mode
.
prohibitEmptyInPredicate
=
true
;
mode
.
padFixedLengthStrings
=
true
;
// Enumerate all H2 types NOT supported by PostgreSQL:
Set
<
String
>
disallowedTypes
=
new
java
.
util
.
HashSet
<
String
>();
disallowedTypes
.
add
(
"NUMBER"
);
disallowedTypes
.
add
(
"IDENTITY"
);
disallowedTypes
.
add
(
"TINYINT"
);
mode
.
disallowedTypes
=
disallowedTypes
;
add
(
mode
);
mode
=
new
Mode
(
"Ignite"
);
...
...
h2/src/test/org/h2/test/db/TestCompatibility.java
浏览文件 @
25e44117
...
...
@@ -246,6 +246,8 @@ public class TestCompatibility extends TestBase {
assertResult
(
"ABC"
,
stat
,
"SELECT SUBSTRING('ABCDEF' FOR 3)"
);
assertResult
(
"ABCD"
,
stat
,
"SELECT SUBSTRING('0ABCDEF' FROM 2 FOR 4)"
);
/* --------- Behaviour of CHAR(N) --------- */
/* Test right-padding of CHAR(N) at INSERT */
stat
.
execute
(
"CREATE TABLE TEST(CH CHAR(10))"
);
stat
.
execute
(
"INSERT INTO TEST (CH) VALUES ('Hello')"
);
...
...
@@ -273,6 +275,19 @@ public class TestCompatibility extends TestBase {
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 '"
);
/* --------- Disallowed column types --------- */
String
[]
DISALLOWED_TYPES
=
{
"NUMBER"
,
"IDENTITY"
,
"TINYINT"
};
for
(
String
type
:
DISALLOWED_TYPES
)
{
stat
.
execute
(
"DROP TABLE IF EXISTS TEST"
);
try
{
stat
.
execute
(
"CREATE TABLE TEST(COL "
+
type
+
")"
);
fail
(
"Expect type "
+
type
+
" to not exist in PostgreSQL mode"
);
}
catch
(
org
.
h2
.
jdbc
.
JdbcSQLException
e
)
{
/* Expected! */
}
}
}
private
void
testMySQL
()
throws
SQLException
{
...
...
编写
预览
Markdown
格式
0%
重试
或
添加新文件
添加附件
取消
您添加了
0
人
到此讨论。请谨慎行事。
请先完成此评论的编辑!
取消
请
注册
或者
登录
后发表评论