Skip to content
项目
群组
代码片段
帮助
正在加载...
帮助
为 GitLab 提交贡献
登录/注册
切换导航
H
h2database
项目
项目
详情
活动
周期分析
仓库
仓库
文件
提交
分支
标签
贡献者
分枝图
比较
统计图
议题
0
议题
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
CI / CD
CI / CD
流水线
作业
计划
统计图
Wiki
Wiki
代码片段
代码片段
成员
成员
折叠边栏
关闭边栏
活动
分枝图
统计图
创建新议题
作业
提交
议题看板
打开侧边栏
Administrator
h2database
Commits
7747fff1
提交
7747fff1
authored
2月 21, 2019
作者:
Evgenij Ryazanov
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Add tests
上级
0923d5bb
显示空白字符变更
内嵌
并排
正在显示
2 个修改的文件
包含
61 行增加
和
5 行删除
+61
-5
TestCompatibility.java
h2/src/test/org/h2/test/db/TestCompatibility.java
+58
-0
TestKeywords.java
h2/src/test/org/h2/test/unit/TestKeywords.java
+3
-5
没有找到文件。
h2/src/test/org/h2/test/db/TestCompatibility.java
浏览文件 @
7747fff1
...
...
@@ -14,6 +14,7 @@ import java.sql.ResultSet;
import
java.sql.ResultSetMetaData
;
import
java.sql.SQLException
;
import
java.sql.Statement
;
import
java.util.Locale
;
import
org.h2.api.ErrorCode
;
import
org.h2.test.TestBase
;
import
org.h2.test.TestDb
;
...
...
@@ -57,6 +58,7 @@ public class TestCompatibility extends TestDb {
testUnknownSet
();
conn
.
close
();
testIdentifiers
();
deleteDb
(
"compatibility"
);
testUnknownURL
();
...
...
@@ -682,6 +684,62 @@ public class TestCompatibility extends TestDb {
assertThrows
(
ErrorCode
.
UNKNOWN_MODE_1
,
stat
).
execute
(
"SET MODE Unknown"
);
}
private
void
testIdentifiers
()
throws
SQLException
{
deleteDb
(
"compatibility"
);
testIdentifiers
(
false
,
false
,
false
);
testIdentifiers
(
false
,
false
,
true
);
testIdentifiers
(
true
,
false
,
false
);
testIdentifiers
(
true
,
false
,
true
);
testIdentifiers
(
false
,
true
,
false
);
testIdentifiers
(
false
,
true
,
true
);
}
private
void
testIdentifiers
(
boolean
upper
,
boolean
lower
,
boolean
caseInsensitiveIdentifiers
)
throws
SQLException
{
try
(
Connection
conn
=
getConnection
(
"compatibility;DATABASE_TO_UPPER="
+
upper
+
";DATABASE_TO_LOWER="
+
lower
+
";CASE_INSENSITIVE_IDENTIFIERS="
+
caseInsensitiveIdentifiers
))
{
Statement
stat
=
conn
.
createStatement
();
stat
.
execute
(
"CREATE TABLE Test(Id INT) AS VALUES 2"
);
String
schema
=
"PUBLIC"
,
table
=
"Test"
,
column
=
"Id"
;
if
(
upper
)
{
table
=
table
.
toUpperCase
(
Locale
.
ROOT
);
column
=
column
.
toUpperCase
(
Locale
.
ROOT
);
}
else
if
(
lower
)
{
schema
=
schema
.
toLowerCase
(
Locale
.
ROOT
);
table
=
table
.
toLowerCase
(
Locale
.
ROOT
);
column
=
column
.
toLowerCase
(
Locale
.
ROOT
);
}
try
(
ResultSet
rs
=
stat
.
executeQuery
(
"SELECT TABLE_SCHEMA, TABLE_NAME, COLUMN_NAME"
+
" FROM INFORMATION_SCHEMA.COLUMNS WHERE TABLE_NAME ILIKE 'Test'"
))
{
assertTrue
(
rs
.
next
());
assertEquals
(
schema
,
rs
.
getString
(
1
));
assertEquals
(
table
,
rs
.
getString
(
2
));
assertEquals
(
column
,
rs
.
getString
(
3
));
}
testIdentifiers
(
stat
,
"Test"
,
"Id"
,
true
);
boolean
ok
=
upper
||
lower
||
caseInsensitiveIdentifiers
;
testIdentifiers
(
stat
,
"TEST"
,
"ID"
,
ok
);
testIdentifiers
(
stat
,
"test"
,
"id"
,
ok
);
testIdentifiers
(
stat
,
'"'
+
table
+
'"'
,
'"'
+
column
+
'"'
,
true
);
testIdentifiers
(
stat
,
"\"TeSt\""
,
"\"iD\""
,
caseInsensitiveIdentifiers
);
}
finally
{
deleteDb
(
"compatibility"
);
}
}
private
void
testIdentifiers
(
Statement
stat
,
String
table
,
String
column
,
boolean
ok
)
throws
SQLException
{
String
query
=
"SELECT _ROWID_, "
+
column
+
" FROM "
+
table
;
if
(
ok
)
{
try
(
ResultSet
rs
=
stat
.
executeQuery
(
query
))
{
assertTrue
(
rs
.
next
());
assertEquals
(
1L
,
rs
.
getLong
(
1
));
assertEquals
(
2
,
rs
.
getInt
(
2
));
}
}
else
{
assertThrows
(
ErrorCode
.
TABLE_OR_VIEW_NOT_FOUND_1
,
stat
).
executeQuery
(
query
);
}
}
private
void
testUnknownURL
()
throws
SQLException
{
try
{
getConnection
(
"compatibility;MODE=Unknown"
).
close
();
...
...
h2/src/test/org/h2/test/unit/TestKeywords.java
浏览文件 @
7747fff1
...
...
@@ -79,12 +79,10 @@ public class TestKeywords extends TestBase {
try
(
Connection
conn
=
DriverManager
.
getConnection
(
"jdbc:h2:mem:keywords"
))
{
Statement
stat
=
conn
.
createStatement
();
for
(
String
s
:
set
)
{
// _ROWID_ is a special virtual column
String
column
=
s
.
equals
(
"_ROWID_"
)
?
"C"
:
s
;
try
{
stat
.
execute
(
"CREATE TABLE "
+
s
+
'('
+
column
+
" INT)"
);
stat
.
execute
(
"INSERT INTO "
+
s
+
'('
+
column
+
") VALUES (10)"
);
try
(
ResultSet
rs
=
stat
.
executeQuery
(
"SELECT "
+
column
+
" FROM "
+
s
))
{
stat
.
execute
(
"CREATE TABLE "
+
s
+
'('
+
s
+
" INT)"
);
stat
.
execute
(
"INSERT INTO "
+
s
+
'('
+
s
+
") VALUES (10)"
);
try
(
ResultSet
rs
=
stat
.
executeQuery
(
"SELECT "
+
s
+
" FROM "
+
s
))
{
assertTrue
(
rs
.
next
());
assertEquals
(
10
,
rs
.
getInt
(
1
));
assertFalse
(
rs
.
next
());
...
...
编写
预览
Markdown
格式
0%
重试
或
添加新文件
添加附件
取消
您添加了
0
人
到此讨论。请谨慎行事。
请先完成此评论的编辑!
取消
请
注册
或者
登录
后发表评论