Skip to content
项目
群组
代码片段
帮助
正在加载...
帮助
为 GitLab 提交贡献
登录/注册
切换导航
H
h2database
项目
项目
详情
活动
周期分析
仓库
仓库
文件
提交
分支
标签
贡献者
分枝图
比较
统计图
议题
0
议题
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
CI / CD
CI / CD
流水线
作业
计划
统计图
Wiki
Wiki
代码片段
代码片段
成员
成员
折叠边栏
关闭边栏
活动
分枝图
统计图
创建新议题
作业
提交
议题看板
打开侧边栏
Administrator
h2database
Commits
b0d2049a
提交
b0d2049a
authored
13 年前
作者:
Thomas Mueller
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
assertThrows (use it where possible; interfaces only so far)
上级
330ce52c
显示空白字符变更
内嵌
并排
正在显示
57 个修改的文件
包含
457 行增加
和
1079 行删除
+457
-1079
TestAll.java
h2/src/test/org/h2/test/TestAll.java
+1
-2
TestBase.java
h2/src/test/org/h2/test/TestBase.java
+29
-5
TestAlter.java
h2/src/test/org/h2/test/db/TestAlter.java
+14
-24
TestAlterSchemaRename.java
h2/src/test/org/h2/test/db/TestAlterSchemaRename.java
+6
-18
TestAutoRecompile.java
h2/src/test/org/h2/test/db/TestAutoRecompile.java
+3
-12
TestCases.java
h2/src/test/org/h2/test/db/TestCases.java
+20
-59
TestCluster.java
h2/src/test/org/h2/test/db/TestCluster.java
+4
-7
TestCompatibility.java
h2/src/test/org/h2/test/db/TestCompatibility.java
+11
-30
TestCsv.java
h2/src/test/org/h2/test/db/TestCsv.java
+1
-1
TestEncryptedDb.java
h2/src/test/org/h2/test/db/TestEncryptedDb.java
+2
-5
TestExclusive.java
h2/src/test/org/h2/test/db/TestExclusive.java
+1
-2
TestFunctionOverload.java
h2/src/test/org/h2/test/db/TestFunctionOverload.java
+5
-15
TestFunctions.java
h2/src/test/org/h2/test/db/TestFunctions.java
+4
-13
TestLinkedTable.java
h2/src/test/org/h2/test/db/TestLinkedTable.java
+9
-24
TestLob.java
h2/src/test/org/h2/test/db/TestLob.java
+9
-18
TestOpenClose.java
h2/src/test/org/h2/test/db/TestOpenClose.java
+5
-2
TestOptimizations.java
h2/src/test/org/h2/test/db/TestOptimizations.java
+2
-6
TestOutOfMemory.java
h2/src/test/org/h2/test/db/TestOutOfMemory.java
+2
-7
TestReadOnly.java
h2/src/test/org/h2/test/db/TestReadOnly.java
+9
-24
TestRights.java
h2/src/test/org/h2/test/db/TestRights.java
+31
-48
TestRunscript.java
h2/src/test/org/h2/test/db/TestRunscript.java
+2
-6
TestSQLInjection.java
h2/src/test/org/h2/test/db/TestSQLInjection.java
+6
-15
TestTempTables.java
h2/src/test/org/h2/test/db/TestTempTables.java
+6
-12
TestTransaction.java
h2/src/test/org/h2/test/db/TestTransaction.java
+14
-38
TestTriggersConstraints.java
h2/src/test/org/h2/test/db/TestTriggersConstraints.java
+10
-35
TestView.java
h2/src/test/org/h2/test/db/TestView.java
+3
-6
TestViewAlterTable.java
h2/src/test/org/h2/test/db/TestViewAlterTable.java
+10
-20
TestViewDropView.java
h2/src/test/org/h2/test/db/TestViewDropView.java
+25
-73
TestCallableStatement.java
h2/src/test/org/h2/test/jdbc/TestCallableStatement.java
+6
-15
TestCancel.java
h2/src/test/org/h2/test/jdbc/TestCancel.java
+12
-32
TestDatabaseEventListener.java
h2/src/test/org/h2/test/jdbc/TestDatabaseEventListener.java
+2
-5
TestLobApi.java
h2/src/test/org/h2/test/jdbc/TestLobApi.java
+32
-35
TestNativeSQL.java
h2/src/test/org/h2/test/jdbc/TestNativeSQL.java
+3
-6
TestPreparedStatement.java
h2/src/test/org/h2/test/jdbc/TestPreparedStatement.java
+11
-52
TestResultSet.java
h2/src/test/org/h2/test/jdbc/TestResultSet.java
+4
-18
TestStatement.java
h2/src/test/org/h2/test/jdbc/TestStatement.java
+32
-82
TestTransactionIsolation.java
h2/src/test/org/h2/test/jdbc/TestTransactionIsolation.java
+5
-12
TestUpdatableResultSet.java
h2/src/test/org/h2/test/jdbc/TestUpdatableResultSet.java
+4
-15
TestZloty.java
h2/src/test/org/h2/test/jdbc/TestZloty.java
+13
-22
TestConnectionPool.java
h2/src/test/org/h2/test/jdbcx/TestConnectionPool.java
+6
-12
TestMvcc1.java
h2/src/test/org/h2/test/mvcc/TestMvcc1.java
+15
-39
TestMvcc2.java
h2/src/test/org/h2/test/mvcc/TestMvcc2.java
+10
-30
TestMvccMultiThreaded.java
h2/src/test/org/h2/test/mvcc/TestMvccMultiThreaded.java
+2
-7
TestRowLocks.java
h2/src/test/org/h2/test/rowlock/TestRowLocks.java
+3
-6
TestNestedLoop.java
h2/src/test/org/h2/test/server/TestNestedLoop.java
+3
-12
TestNestedJoins.java
h2/src/test/org/h2/test/synth/TestNestedJoins.java
+7
-12
TestAutoReconnect.java
h2/src/test/org/h2/test/unit/TestAutoReconnect.java
+2
-6
TestCollation.java
h2/src/test/org/h2/test/unit/TestCollation.java
+4
-12
TestFileLockSerialized.java
h2/src/test/org/h2/test/unit/TestFileLockSerialized.java
+4
-11
TestFileSystem.java
h2/src/test/org/h2/test/unit/TestFileSystem.java
+4
-24
TestOldVersion.java
h2/src/test/org/h2/test/unit/TestOldVersion.java
+2
-5
TestPageStore.java
h2/src/test/org/h2/test/unit/TestPageStore.java
+8
-29
TestPageStoreCoverage.java
h2/src/test/org/h2/test/unit/TestPageStoreCoverage.java
+3
-12
TestPgServer.java
h2/src/test/org/h2/test/unit/TestPgServer.java
+2
-6
TestServlet.java
h2/src/test/org/h2/test/unit/TestServlet.java
+5
-13
TestTools.java
h2/src/test/org/h2/test/unit/TestTools.java
+8
-22
TestValue.java
h2/src/test/org/h2/test/unit/TestValue.java
+1
-0
没有找到文件。
h2/src/test/org/h2/test/TestAll.java
浏览文件 @
b0d2049a
...
...
@@ -339,8 +339,7 @@ java org.h2.test.TestAll timer
System
.
setProperty
(
"h2.delayWrongPasswordMin"
,
"0"
);
System
.
setProperty
(
"h2.delayWrongPasswordMax"
,
"0"
);
int
todoTestBoth
;
System
.
setProperty
(
"h2.storeLocalTime"
,
"true"
);
// System.setProperty("h2.storeLocalTime", "true");
// speedup
// System.setProperty("h2.syncMethod", "");
...
...
This diff is collapsed.
Click to expand it.
h2/src/test/org/h2/test/TestBase.java
浏览文件 @
b0d2049a
...
...
@@ -1277,9 +1277,33 @@ public abstract class TestBase {
memory
.
clear
();
}
protected
<
T
>
T
assertThrows
(
final
Class
<?>
exceptionClass
,
final
T
obj
)
{
return
assertThrows
(
new
Thread
.
UncaughtExceptionHandler
()
{
public
void
uncaughtException
(
Thread
t
,
Throwable
e
)
{
if
(!
exceptionClass
.
isAssignableFrom
(
e
.
getClass
()))
{
e
.
printStackTrace
();
fail
(
"Expected: "
+
exceptionClass
+
", got: "
+
e
);
}
}
},
exceptionClass
.
toString
(),
obj
);
}
protected
<
T
>
T
assertThrows
(
final
int
errorCode
,
final
T
obj
)
{
return
assertThrows
(
new
Thread
.
UncaughtExceptionHandler
()
{
public
void
uncaughtException
(
Thread
t
,
Throwable
e
)
{
if
(!(
e
instanceof
SQLException
))
{
e
.
printStackTrace
();
fail
(
"Expected: SQLException, got: "
+
e
);
}
SQLException
s
=
(
SQLException
)
e
;
assertEquals
(
errorCode
,
s
.
getErrorCode
());
}
},
"SQLException with error code "
+
errorCode
,
obj
);
}
@SuppressWarnings
(
"unchecked"
)
protected
<
T
>
T
assertThrows
(
final
int
errorCode
,
final
T
obj
)
{
<
T
>
T
assertThrows
(
final
Thread
.
UncaughtExceptionHandler
handler
,
final
String
expected
,
final
T
obj
)
{
Class
<?>
c
=
obj
.
getClass
();
return
(
T
)
Proxy
.
newProxyInstance
(
c
.
getClassLoader
(),
c
.
getInterfaces
(),
new
InvocationHandler
()
{
...
...
@@ -1293,12 +1317,12 @@ public abstract class TestBase {
try
{
called
=
null
;
Object
ret
=
method
.
invoke
(
obj
,
args
);
fail
(
"The method "
+
method
.
getName
()
+
" did not throw the exception with error code "
+
errorCode
+
", but returned "
+
ret
+
" instead"
);
fail
(
method
.
getDeclaringClass
().
getName
()
+
"."
+
method
.
getName
()
+
" did not throw an exception of type "
+
expected
+
", but returned "
+
ret
);
return
ret
;
}
catch
(
InvocationTargetException
e
)
{
SQLException
s
=
(
SQLException
)
e
.
getTargetException
();
assertEquals
(
errorCode
,
s
.
getErrorCode
());
handler
.
uncaughtException
(
null
,
e
.
getTargetException
());
Class
<?>
retClass
=
method
.
getReturnType
();
if
(!
retClass
.
isPrimitive
())
{
return
null
;
...
...
This diff is collapsed.
Click to expand it.
h2/src/test/org/h2/test/db/TestAlter.java
浏览文件 @
b0d2049a
...
...
@@ -54,24 +54,20 @@ public class TestAlter extends TestBase {
stat
.
execute
(
"create table test(id int, name varchar(255))"
);
stat
.
execute
(
"alter table test add constraint x check (id > name)"
);
try
{
// the constraint references multiple columns
stat
.
execute
(
"alter table test drop column id"
);
fail
();
}
catch
(
SQLException
e
)
{
assertEquals
(
ErrorCode
.
COLUMN_IS_REFERENCED_1
,
e
.
getErrorCode
());
}
assertThrows
(
ErrorCode
.
COLUMN_IS_REFERENCED_1
,
stat
).
execute
(
"alter table test drop column id"
);
stat
.
execute
(
"drop table test"
);
stat
.
execute
(
"create table test(id int, name varchar(255))"
);
stat
.
execute
(
"alter table test add constraint x unique(id, name)"
);
try
{
// the constraint references multiple columns
stat
.
execute
(
"alter table test drop column id"
);
fail
();
}
catch
(
SQLException
e
)
{
assertEquals
(
ErrorCode
.
COLUMN_IS_REFERENCED_1
,
e
.
getErrorCode
());
}
assertThrows
(
ErrorCode
.
COLUMN_IS_REFERENCED_1
,
stat
).
execute
(
"alter table test drop column id"
);
stat
.
execute
(
"drop table test"
);
stat
.
execute
(
"create table test(id int, name varchar(255))"
);
...
...
@@ -109,18 +105,12 @@ public class TestAlter extends TestBase {
private
void
testAlterTableAlterColumn
()
throws
SQLException
{
stat
.
execute
(
"create table t(x varchar) as select 'x'"
);
try
{
stat
.
execute
(
"alter table t alter column x int"
);
}
catch
(
SQLException
e
)
{
assertEquals
(
ErrorCode
.
DATA_CONVERSION_ERROR_1
,
e
.
getErrorCode
());
}
assertThrows
(
ErrorCode
.
DATA_CONVERSION_ERROR_1
,
stat
).
execute
(
"alter table t alter column x int"
);
stat
.
execute
(
"drop table t"
);
stat
.
execute
(
"create table t(id identity, x varchar) as select null, 'x'"
);
try
{
stat
.
execute
(
"alter table t alter column x int"
);
}
catch
(
SQLException
e
)
{
assertEquals
(
ErrorCode
.
DATA_CONVERSION_ERROR_1
,
e
.
getErrorCode
());
}
assertThrows
(
ErrorCode
.
DATA_CONVERSION_ERROR_1
,
stat
).
execute
(
"alter table t alter column x int"
);
stat
.
execute
(
"drop table t"
);
}
...
...
This diff is collapsed.
Click to expand it.
h2/src/test/org/h2/test/db/TestAlterSchemaRename.java
浏览文件 @
b0d2049a
...
...
@@ -45,19 +45,11 @@ public class TestAlterSchemaRename extends TestBase {
}
private
void
testTryToRenameSystemSchemas
()
throws
SQLException
{
try
{
stat
.
execute
(
"alter schema information_schema rename to test_info"
);
fail
();
}
catch
(
SQLException
e
)
{
assertEquals
(
ErrorCode
.
SCHEMA_CAN_NOT_BE_DROPPED_1
,
e
.
getErrorCode
());
}
assertThrows
(
ErrorCode
.
SCHEMA_CAN_NOT_BE_DROPPED_1
,
stat
).
execute
(
"alter schema information_schema rename to test_info"
);
stat
.
execute
(
"create sequence test_sequence"
);
try
{
stat
.
execute
(
"alter schema public rename to test_schema"
);
fail
();
}
catch
(
SQLException
e
)
{
assertEquals
(
ErrorCode
.
SCHEMA_CAN_NOT_BE_DROPPED_1
,
e
.
getErrorCode
());
}
assertThrows
(
ErrorCode
.
SCHEMA_CAN_NOT_BE_DROPPED_1
,
stat
).
execute
(
"alter schema public rename to test_schema"
);
}
private
void
testSimpleRename
()
throws
SQLException
{
...
...
@@ -78,12 +70,8 @@ public class TestAlterSchemaRename extends TestBase {
private
void
testRenameToExistingSchema
()
throws
SQLException
{
stat
.
execute
(
"create schema s1"
);
stat
.
execute
(
"create schema s2"
);
try
{
stat
.
execute
(
"alter schema s1 rename to s2"
);
fail
(
"Exception should be thrown"
);
}
catch
(
SQLException
e
)
{
assertEquals
(
ErrorCode
.
SCHEMA_ALREADY_EXISTS_1
,
e
.
getErrorCode
());
}
assertThrows
(
ErrorCode
.
SCHEMA_ALREADY_EXISTS_1
,
stat
).
execute
(
"alter schema s1 rename to s2"
);
stat
.
execute
(
"drop schema s1"
);
stat
.
execute
(
"drop schema s2"
);
}
...
...
This diff is collapsed.
Click to expand it.
h2/src/test/org/h2/test/db/TestAutoRecompile.java
浏览文件 @
b0d2049a
...
...
@@ -11,6 +11,7 @@ import java.sql.PreparedStatement;
import
java.sql.SQLException
;
import
java.sql.Statement
;
import
org.h2.constant.ErrorCode
;
import
org.h2.test.TestBase
;
/**
...
...
@@ -43,18 +44,8 @@ public class TestAutoRecompile extends TestBase {
prep
=
conn
.
prepareStatement
(
"INSERT INTO TEST VALUES(1, 2, 3)"
);
stat
.
execute
(
"ALTER TABLE TEST ADD COLUMN Z INT"
);
try
{
prep
.
execute
();
fail
();
}
catch
(
SQLException
e
)
{
assertKnownException
(
e
);
}
try
{
prep
.
execute
();
fail
();
}
catch
(
SQLException
e
)
{
assertKnownException
(
e
);
}
assertThrows
(
ErrorCode
.
COLUMN_COUNT_DOES_NOT_MATCH
,
prep
).
execute
();
assertThrows
(
ErrorCode
.
COLUMN_COUNT_DOES_NOT_MATCH
,
prep
).
execute
();
conn
.
close
();
deleteDb
(
"autoRecompile"
);
}
...
...
This diff is collapsed.
Click to expand it.
h2/src/test/org/h2/test/db/TestCases.java
浏览文件 @
b0d2049a
...
...
@@ -120,24 +120,16 @@ public class TestCases extends TestBase {
// ensure the dependency is detected
stat
.
execute
(
"create alias is_positive as 'boolean isPositive(int x) { return x > 0; }'"
);
stat
.
execute
(
"create table a(a integer, constraint test check is_positive(a))"
);
try
{
stat
.
execute
(
"drop alias is_positive"
);
fail
();
}
catch
(
SQLException
e
)
{
assertEquals
(
ErrorCode
.
CANNOT_DROP_2
,
e
.
getErrorCode
());
}
assertThrows
(
ErrorCode
.
CANNOT_DROP_2
,
stat
).
execute
(
"drop alias is_positive"
);
stat
.
execute
(
"drop table a"
);
stat
.
execute
(
"drop alias is_positive"
);
// ensure trying to reference the table fails
// (otherwise re-opening the database is not possible)
stat
.
execute
(
"create table test(id int primary key)"
);
try
{
stat
.
execute
(
"alter table test alter column id set default ifnull((select max(id) from test for update)+1, 0)"
);
fail
();
}
catch
(
SQLException
e
)
{
assertEquals
(
ErrorCode
.
COLUMN_IS_REFERENCED_1
,
e
.
getErrorCode
());
}
assertThrows
(
ErrorCode
.
COLUMN_IS_REFERENCED_1
,
stat
).
execute
(
"alter table test alter column id set default ifnull((select max(id) from test for update)+1, 0)"
);
stat
.
execute
(
"drop table test"
);
conn
.
close
();
}
...
...
@@ -253,28 +245,16 @@ public class TestCases extends TestBase {
Statement
stat
=
conn
.
createStatement
();
stat
.
execute
(
"create table parent(id identity) as select 0"
);
stat
.
execute
(
"create table child(id identity, parent int references parent(id)) as select 0, 0"
);
try
{
stat
.
execute
(
"truncate table parent"
);
fail
();
}
catch
(
SQLException
e
)
{
// expected
}
try
{
stat
.
execute
(
"delete from parent"
);
fail
();
}
catch
(
SQLException
e
)
{
// expected
}
assertThrows
(
ErrorCode
.
CANNOT_TRUNCATE_1
,
stat
).
execute
(
"truncate table parent"
);
assertThrows
(
ErrorCode
.
REFERENTIAL_INTEGRITY_VIOLATED_CHILD_EXISTS_1
,
stat
).
execute
(
"delete from parent"
);
stat
.
execute
(
"alter table parent set referential_integrity false"
);
stat
.
execute
(
"delete from parent"
);
stat
.
execute
(
"truncate table parent"
);
stat
.
execute
(
"alter table parent set referential_integrity true"
);
try
{
stat
.
execute
(
"truncate table parent"
);
fail
();
}
catch
(
SQLException
e
)
{
// expected
}
assertThrows
(
ErrorCode
.
CANNOT_TRUNCATE_1
,
stat
).
execute
(
"truncate table parent"
);
stat
.
execute
(
"set referential_integrity false"
);
stat
.
execute
(
"truncate table parent"
);
conn
.
close
();
...
...
@@ -577,11 +557,8 @@ public class TestCases extends TestBase {
deleteDb
(
"cases"
);
Connection
conn
=
getConnection
(
"cases"
);
Statement
stat
=
conn
.
createStatement
();
try
{
stat
.
execute
(
"create table address(id identity, name varchar check? instr(value, '@') > 1)"
);
}
catch
(
SQLException
e
)
{
assertKnownException
(
e
);
}
assertThrows
(
ErrorCode
.
SYNTAX_ERROR_2
,
stat
).
execute
(
"create table address(id identity, name varchar check? instr(value, '@') > 1)"
);
stat
.
execute
(
"SET AUTOCOMMIT OFF; \n//create sequence if not exists object_id;\n"
);
stat
.
execute
(
"SET AUTOCOMMIT OFF;\n//create sequence if not exists object_id;\n"
);
stat
.
execute
(
"SET AUTOCOMMIT OFF; //create sequence if not exists object_id;"
);
...
...
@@ -736,12 +713,8 @@ public class TestCases extends TestBase {
Statement
stat
=
conn
.
createStatement
();
stat
.
execute
(
"create table test(id identity);"
);
stat
.
execute
(
"insert into test values(1);"
);
try
{
stat
.
execute
(
"alter table test add column name varchar not null;"
);
fail
();
}
catch
(
SQLException
e
)
{
assertKnownException
(
e
);
}
assertThrows
(
ErrorCode
.
NULL_NOT_ALLOWED
,
stat
).
execute
(
"alter table test add column name varchar not null;"
);
conn
.
close
();
conn
=
getConnection
(
"cases"
);
ResultSet
rs
=
conn
.
createStatement
().
executeQuery
(
"SELECT * FROM TEST"
);
...
...
@@ -763,12 +736,8 @@ public class TestCases extends TestBase {
stat
.
execute
(
"drop table test"
);
stat
.
execute
(
"create table test(id identity)"
);
stat
.
execute
(
"insert into test values(1)"
);
try
{
stat
.
execute
(
"alter table test alter column id date"
);
fail
();
}
catch
(
SQLException
e
)
{
assertKnownException
(
e
);
}
assertThrows
(
ErrorCode
.
INVALID_DATETIME_CONSTANT_2
,
stat
).
execute
(
"alter table test alter column id date"
);
conn
.
close
();
conn
=
getConnection
(
"cases"
);
rs
=
conn
.
createStatement
().
executeQuery
(
"SELECT * FROM TEST"
);
...
...
@@ -864,12 +833,8 @@ public class TestCases extends TestBase {
conn
.
close
();
conn
=
getConnection
(
"cases"
);
stat
=
conn
.
createStatement
();
try
{
stat
.
execute
(
"select * from abc"
);
fail
();
}
catch
(
SQLException
e
)
{
assertKnownException
(
e
);
}
assertThrows
(
ErrorCode
.
TABLE_OR_VIEW_NOT_FOUND_1
,
stat
).
execute
(
"select * from abc"
);
conn
.
close
();
}
...
...
@@ -1070,12 +1035,8 @@ public class TestCases extends TestBase {
stat1
.
execute
(
"SELECT * FROM TEST FOR UPDATE"
);
Connection
conn2
=
getConnection
(
"cases"
);
Statement
stat2
=
conn2
.
createStatement
();
try
{
stat2
.
execute
(
"UPDATE TEST SET ID=2"
);
fail
();
}
catch
(
SQLException
e
)
{
assertKnownException
(
e
);
}
assertThrows
(
ErrorCode
.
LOCK_TIMEOUT_1
,
stat2
).
execute
(
"UPDATE TEST SET ID=2"
);
conn1
.
commit
();
stat2
.
execute
(
"UPDATE TEST SET ID=2"
);
conn1
.
close
();
...
...
This diff is collapsed.
Click to expand it.
h2/src/test/org/h2/test/db/TestCluster.java
浏览文件 @
b0d2049a
...
...
@@ -13,6 +13,7 @@ import java.sql.ResultSet;
import
java.sql.SQLException
;
import
java.sql.Statement
;
import
org.h2.constant.ErrorCode
;
import
org.h2.test.TestBase
;
import
org.h2.tools.CreateCluster
;
import
org.h2.tools.DeleteDbFiles
;
...
...
@@ -231,13 +232,9 @@ public class TestCluster extends TestBase {
serverList
);
// check the original connection is closed
try
{
stat
.
execute
(
"select * from test"
);
fail
();
}
catch
(
SQLException
e
)
{
// expected
assertThrows
(
ErrorCode
.
CONNECTION_BROKEN_1
,
stat
).
execute
(
"select * from test"
);
JdbcUtils
.
closeSilently
(
conn
);
}
// test the cluster connection
Connection
connApp
=
DriverManager
.
getConnection
(
urlCluster
+
";AUTO_RECONNECT=TRUE"
,
user
,
password
);
...
...
This diff is collapsed.
Click to expand it.
h2/src/test/org/h2/test/db/TestCompatibility.java
浏览文件 @
b0d2049a
...
...
@@ -12,6 +12,7 @@ import java.sql.ResultSet;
import
java.sql.ResultSetMetaData
;
import
java.sql.SQLException
;
import
java.sql.Statement
;
import
org.h2.constant.ErrorCode
;
import
org.h2.test.TestBase
;
/**
...
...
@@ -54,12 +55,8 @@ public class TestCompatibility extends TestBase {
}
Statement
stat
=
conn
.
createStatement
();
stat
.
execute
(
"create table test(id int primary key) as select 1"
);
try
{
stat
.
execute
(
"create domain int as varchar"
);
fail
();
}
catch
(
SQLException
e
)
{
assertKnownException
(
e
);
}
assertThrows
(
ErrorCode
.
USER_DATA_TYPE_ALREADY_EXISTS_1
,
stat
).
execute
(
"create domain int as varchar"
);
conn
.
close
();
conn
=
getConnection
(
"compatibility"
);
stat
=
conn
.
createStatement
();
...
...
@@ -114,21 +111,13 @@ public class TestCompatibility extends TestBase {
stat
.
execute
(
"create table t2(c1 int, c2 int)"
);
stat
.
execute
(
"create unique index i2 on t2(c1, c2)"
);
stat
.
execute
(
"insert into t2 values (null, 1)"
);
try
{
stat
.
execute
(
"insert into t2 values (null, 1)"
);
fail
();
}
catch
(
SQLException
e
)
{
assertKnownException
(
e
);
}
assertThrows
(
ErrorCode
.
DUPLICATE_KEY_1
,
stat
).
execute
(
"insert into t2 values (null, 1)"
);
stat
.
execute
(
"insert into t2 values (null, null)"
);
stat
.
execute
(
"insert into t2 values (null, null)"
);
stat
.
execute
(
"insert into t2 values (1, null)"
);
try
{
stat
.
execute
(
"insert into t2 values (1, null)"
);
fail
();
}
catch
(
SQLException
e
)
{
assertKnownException
(
e
);
}
assertThrows
(
ErrorCode
.
DUPLICATE_KEY_1
,
stat
).
execute
(
"insert into t2 values (1, null)"
);
stat
.
execute
(
"DROP TABLE T2"
);
}
...
...
@@ -233,12 +222,8 @@ public class TestCompatibility extends TestBase {
assertEquals
(
"1"
,
res
.
getString
(
1
));
conn
.
close
();
conn
=
getConnection
(
"compatibility;MODE=MySQL"
);
try
{
conn
.
createStatement
().
executeQuery
(
"SELECT 1 FROM sysibm.sysdummy1"
);
fail
();
}
catch
(
SQLException
e
)
{
// can't lookup sysibm.sysdummy1 on mode=MySQL etc.
}
assertThrows
(
ErrorCode
.
SCHEMA_NOT_FOUND_1
,
conn
.
createStatement
()).
executeQuery
(
"SELECT 1 FROM sysibm.sysdummy1"
);
conn
.
close
();
conn
=
getConnection
(
"compatibility"
);
}
...
...
@@ -250,12 +235,8 @@ public class TestCompatibility extends TestBase {
assertEquals
(
"1"
,
res
.
getString
(
1
));
conn
.
close
();
conn
=
getConnection
(
"compatibility;MODE=PostgreSQL"
);
try
{
conn
.
createStatement
().
executeQuery
(
"SELECT 1 FROM sysibm.sysdummy1"
);
fail
();
}
catch
(
SQLException
e
)
{
// can't lookup sysibm.sysdummy1 on mode=MySQL etc.
}
assertThrows
(
ErrorCode
.
SCHEMA_NOT_FOUND_1
,
conn
.
createStatement
()).
executeQuery
(
"SELECT 1 FROM sysibm.sysdummy1"
);
conn
.
close
();
conn
=
getConnection
(
"compatibility"
);
}
...
...
This diff is collapsed.
Click to expand it.
h2/src/test/org/h2/test/db/TestCsv.java
浏览文件 @
b0d2049a
...
...
@@ -166,8 +166,8 @@ public class TestCsv extends TestBase {
fail
();
}
catch
(
DbException
e
)
{
assertEquals
(
ErrorCode
.
UNSUPPORTED_SETTING_1
,
e
.
getErrorCode
());
assertEquals
(
'a'
,
csv
.
getEscapeCharacter
());
}
assertEquals
(
'a'
,
csv
.
getEscapeCharacter
());
}
private
void
testPseudoBom
()
throws
Exception
{
...
...
This diff is collapsed.
Click to expand it.
h2/src/test/org/h2/test/db/TestEncryptedDb.java
浏览文件 @
b0d2049a
...
...
@@ -11,6 +11,7 @@ import java.sql.ResultSet;
import
java.sql.SQLException
;
import
java.sql.Statement
;
import
org.h2.constant.ErrorCode
;
import
org.h2.test.TestBase
;
/**
...
...
@@ -39,11 +40,7 @@ public class TestEncryptedDb extends TestBase {
stat
.
execute
(
"SET WRITE_DELAY 0"
);
stat
.
execute
(
"INSERT INTO TEST VALUES(1)"
);
stat
.
execute
(
"SHUTDOWN IMMEDIATELY"
);
try
{
conn
.
close
();
}
catch
(
SQLException
e
)
{
assertKnownException
(
e
);
}
assertThrows
(
ErrorCode
.
DATABASE_IS_CLOSED
,
conn
).
close
();
try
{
getConnection
(
"encrypted;CIPHER=AES"
,
"sa"
,
"1234 1234"
);
...
...
This diff is collapsed.
Click to expand it.
h2/src/test/org/h2/test/db/TestExclusive.java
浏览文件 @
b0d2049a
...
...
@@ -34,8 +34,7 @@ public class TestExclusive extends TestBase {
Statement
stat
=
conn
.
createStatement
();
stat
.
execute
(
"set exclusive true"
);
try
{
Connection
conn2
=
getConnection
(
"exclusive"
);
conn2
.
close
();
getConnection
(
"exclusive"
);
fail
();
}
catch
(
SQLException
e
)
{
assertKnownException
(
e
);
...
...
This diff is collapsed.
Click to expand it.
h2/src/test/org/h2/test/db/TestFunctionOverload.java
浏览文件 @
b0d2049a
...
...
@@ -12,6 +12,7 @@ import java.sql.ResultSet;
import
java.sql.SQLException
;
import
java.sql.Statement
;
import
org.h2.constant.ErrorCode
;
import
org.h2.test.TestBase
;
/**
...
...
@@ -49,12 +50,8 @@ public class TestFunctionOverload extends TestBase {
private
void
testOverloadError
()
throws
SQLException
{
Statement
stat
=
conn
.
createStatement
();
try
{
stat
.
execute
(
"create alias overloadError for \""
+
ME
+
".overloadError\""
);
fail
();
}
catch
(
SQLException
e
)
{
assertKnownException
(
e
);
}
assertThrows
(
ErrorCode
.
METHODS_MUST_HAVE_DIFFERENT_PARAMETER_COUNTS_2
,
stat
).
execute
(
"create alias overloadError for \""
+
ME
+
".overloadError\""
);
}
private
void
testControl
()
throws
SQLException
{
...
...
@@ -98,15 +95,8 @@ public class TestFunctionOverload extends TestBase {
assertEquals
(
"1 arg"
,
1
,
rs
.
getInt
(
1
));
assertFalse
(
"Second Row"
,
rs
.
next
());
rs
.
close
();
try
{
rs
=
stat
.
executeQuery
(
"select overload1or2Named(1, 2) from dual"
);
rs
.
close
();
fail
();
}
catch
(
SQLException
e
)
{
assertKnownException
(
e
);
}
assertThrows
(
ErrorCode
.
METHOD_NOT_FOUND_1
,
stat
).
executeQuery
(
"select overload1or2Named(1, 2) from dual"
);
stat
.
close
();
}
...
...
This diff is collapsed.
Click to expand it.
h2/src/test/org/h2/test/db/TestFunctions.java
浏览文件 @
b0d2049a
...
...
@@ -132,11 +132,8 @@ public class TestFunctions extends TestBase implements AggregateFunction {
rs
.
next
();
assertEquals
(
rs
.
getMetaData
().
getColumnType
(
2
),
rs
.
getMetaData
().
getColumnType
(
1
));
try
{
rs
=
stat
.
executeQuery
(
"SELECT NVL2(num, num, txt1), num FROM testNvl2 where id = 7 order by id asc"
);
}
catch
(
SQLException
e
)
{
assertEquals
(
ErrorCode
.
DATA_CONVERSION_ERROR_1
,
e
.
getErrorCode
());
}
assertThrows
(
ErrorCode
.
DATA_CONVERSION_ERROR_1
,
stat
).
executeQuery
(
"SELECT NVL2(num, num, txt1), num FROM testNvl2 where id = 7 order by id asc"
);
// nvl2 should return expr2's datatype, if expr2 is character data.
rs
=
stat
.
executeQuery
(
"SELECT NVL2(1, 'test', 123), 'test' FROM dual"
);
...
...
@@ -601,14 +598,8 @@ public class TestFunctions extends TestBase implements AggregateFunction {
rs
.
next
();
assertEquals
(
"((1, Hello), (2, World))"
,
rs
.
getString
(
1
));
assertFalse
(
rs
.
next
());
try
{
stat
.
executeQuery
(
"CALL SELECT_F('ERROR')"
);
fail
();
}
catch
(
SQLException
e
)
{
assertEquals
(
"42001"
,
e
.
getSQLState
());
}
assertThrows
(
ErrorCode
.
SYNTAX_ERROR_2
,
stat
).
executeQuery
(
"CALL SELECT_F('ERROR')"
);
stat
.
execute
(
"CREATE ALIAS SIMPLE FOR \""
+
getClass
().
getName
()
+
".simpleResultSet\""
);
rs
=
stat
.
executeQuery
(
"CALL SIMPLE(2, 1, 1, 1, 1, 1, 1, 1)"
);
assertEquals
(
2
,
rs
.
getMetaData
().
getColumnCount
());
...
...
This diff is collapsed.
Click to expand it.
h2/src/test/org/h2/test/db/TestLinkedTable.java
浏览文件 @
b0d2049a
...
...
@@ -15,6 +15,7 @@ import java.sql.ResultSetMetaData;
import
java.sql.SQLException
;
import
java.sql.Statement
;
import
java.sql.Timestamp
;
import
org.h2.constant.ErrorCode
;
import
org.h2.store.fs.FileSystem
;
import
org.h2.test.TestBase
;
import
org.h2.util.IOUtils
;
...
...
@@ -217,24 +218,16 @@ public class TestLinkedTable extends TestBase {
sa
.
execute
(
"CREATE TABLE P.TEST(X INT)"
);
sa
.
execute
(
"INSERT INTO TEST VALUES(1)"
);
sa
.
execute
(
"INSERT INTO P.TEST VALUES(2)"
);
try
{
sb
.
execute
(
"CREATE LINKED TABLE T(NULL, 'jdbc:h2:mem:one', 'sa', 'sa', 'TEST')"
);
fail
();
}
catch
(
SQLException
e
)
{
assertKnownException
(
e
);
}
assertThrows
(
ErrorCode
.
SCHEMA_NAME_MUST_MATCH
,
sb
).
execute
(
"CREATE LINKED TABLE T(NULL, 'jdbc:h2:mem:one', 'sa', 'sa', 'TEST')"
);
sb
.
execute
(
"CREATE LINKED TABLE T(NULL, 'jdbc:h2:mem:one', 'sa', 'sa', 'PUBLIC', 'TEST')"
);
sb
.
execute
(
"CREATE LINKED TABLE T2(NULL, 'jdbc:h2:mem:one', 'sa', 'sa', 'P', 'TEST')"
);
assertSingleValue
(
sb
,
"SELECT * FROM T"
,
1
);
assertSingleValue
(
sb
,
"SELECT * FROM T2"
,
2
);
sa
.
execute
(
"DROP ALL OBJECTS"
);
sb
.
execute
(
"DROP ALL OBJECTS"
);
try
{
assertSingleValue
(
sa
,
"SELECT * FROM TEST"
,
0
);
fail
();
}
catch
(
SQLException
e
)
{
assertKnownException
(
e
);
}
assertThrows
(
ErrorCode
.
TABLE_OR_VIEW_NOT_FOUND_1
,
sa
).
execute
(
"SELECT * FROM TEST"
);
ca
.
close
();
cb
.
close
();
}
...
...
@@ -361,12 +354,8 @@ public class TestLinkedTable extends TestBase {
stat2
.
execute
(
link
);
stat2
.
executeUpdate
(
"INSERT INTO TEST_LINK_U VALUES(1, 'Hello')"
);
stat2
.
executeUpdate
(
"INSERT INTO TEST_LINK_DI VALUES(2, 'World')"
);
try
{
stat2
.
executeUpdate
(
"UPDATE TEST_LINK_U SET ID=ID+1"
);
fail
();
}
catch
(
SQLException
e
)
{
assertKnownException
(
e
);
}
assertThrows
(
ErrorCode
.
ERROR_ACCESSING_LINKED_TABLE_2
,
stat2
).
executeUpdate
(
"UPDATE TEST_LINK_U SET ID=ID+1"
);
stat2
.
executeUpdate
(
"UPDATE TEST_LINK_DI SET ID=ID+1"
);
stat2
.
executeUpdate
(
"UPDATE TEST_LINK_U SET NAME=NAME || ID"
);
ResultSet
rs
;
...
...
@@ -470,12 +459,8 @@ public class TestLinkedTable extends TestBase {
conn
=
DriverManager
.
getConnection
(
url1
,
"sa1"
,
"abc abc"
);
stat
=
conn
.
createStatement
();
testRow
(
stat
,
"TEST"
);
try
{
stat
.
execute
(
"SELECT * FROM TEST_TEMP"
);
fail
(
"temp table must not be persistent"
);
}
catch
(
SQLException
e
)
{
assertKnownException
(
e
);
}
assertThrows
(
ErrorCode
.
TABLE_OR_VIEW_NOT_FOUND_1
,
stat
).
execute
(
"SELECT * FROM TEST_TEMP"
);
conn
.
close
();
conn
=
DriverManager
.
getConnection
(
url2
,
"sa2"
,
"def def"
);
...
...
This diff is collapsed.
Click to expand it.
h2/src/test/org/h2/test/db/TestLob.java
浏览文件 @
b0d2049a
...
...
@@ -99,19 +99,16 @@ public class TestLob extends TestBase {
}
private
void
testCreateIndexOnLob
()
throws
Exception
{
if
(!
config
.
memory
)
{
return
;
}
deleteDb
(
"lob"
);
Connection
conn
;
conn
=
getConnection
(
"lob"
);
Statement
stat
=
conn
.
createStatement
();
stat
.
execute
(
"create table test(id int, name clob)"
);
try
{
stat
.
execute
(
"create index idx_n on test(name)"
);
if
(!
config
.
memory
)
{
fail
();
}
}
catch
(
SQLException
e
)
{
assertEquals
(
ErrorCode
.
FEATURE_NOT_SUPPORTED_1
,
e
.
getErrorCode
());
}
assertThrows
(
ErrorCode
.
FEATURE_NOT_SUPPORTED_1
,
stat
).
execute
(
"create index idx_n on test(name)"
);
stat
.
execute
(
"drop table test"
);
conn
.
close
();
}
...
...
@@ -295,17 +292,11 @@ public class TestLob extends TestBase {
stat
.
execute
(
"create memory table test(x clob unique)"
);
stat
.
execute
(
"insert into test values('hello')"
);
stat
.
execute
(
"insert into test values('world')"
);
try
{
stat
.
execute
(
"insert into test values('world')"
);
}
catch
(
SQLException
e
)
{
assertEquals
(
ErrorCode
.
DUPLICATE_KEY_1
,
e
.
getErrorCode
());
}
assertThrows
(
ErrorCode
.
DUPLICATE_KEY_1
,
stat
).
execute
(
"insert into test values('world')"
);
stat
.
execute
(
"insert into test values(space(10000) || 'a')"
);
try
{
stat
.
execute
(
"insert into test values(space(10000) || 'a')"
);
}
catch
(
SQLException
e
)
{
assertEquals
(
ErrorCode
.
DUPLICATE_KEY_1
,
e
.
getErrorCode
());
}
assertThrows
(
ErrorCode
.
DUPLICATE_KEY_1
,
stat
).
execute
(
"insert into test values(space(10000) || 'a')"
);
stat
.
execute
(
"insert into test values(space(10000) || 'b')"
);
conn
.
close
();
}
...
...
This diff is collapsed.
Click to expand it.
h2/src/test/org/h2/test/db/TestOpenClose.java
浏览文件 @
b0d2049a
...
...
@@ -54,9 +54,12 @@ public class TestOpenClose extends TestBase implements DatabaseEventListener {
}
deleteDb
(
"openClose"
);
Connection
conn
;
conn
=
DriverManager
.
getConnection
(
"jdbc:h2:"
+
getBaseDir
()
+
"/openClose;FILE_LOCK=FS"
);
conn
=
DriverManager
.
getConnection
(
"jdbc:h2:"
+
getBaseDir
()
+
"/openClose;FILE_LOCK=FS"
);
try
{
DriverManager
.
getConnection
(
"jdbc:h2:"
+
getBaseDir
()
+
"/openClose;FILE_LOCK=FS;OPEN_NEW=TRUE"
);
DriverManager
.
getConnection
(
"jdbc:h2:"
+
getBaseDir
()
+
"/openClose;FILE_LOCK=FS;OPEN_NEW=TRUE"
);
fail
();
}
catch
(
SQLException
e
)
{
assertEquals
(
ErrorCode
.
DATABASE_ALREADY_OPEN_1
,
e
.
getErrorCode
());
}
...
...
This diff is collapsed.
Click to expand it.
h2/src/test/org/h2/test/db/TestOptimizations.java
浏览文件 @
b0d2049a
...
...
@@ -16,6 +16,7 @@ import java.util.ArrayList;
import
java.util.HashMap
;
import
java.util.Random
;
import
java.util.TreeSet
;
import
org.h2.constant.ErrorCode
;
import
org.h2.test.TestBase
;
import
org.h2.tools.SimpleResultSet
;
import
org.h2.util.New
;
...
...
@@ -134,12 +135,7 @@ public class TestOptimizations extends TestBase {
prep
.
execute
();
prep
.
close
();
prep
=
conn
.
prepareStatement
(
"select ?"
);
try
{
prep
.
execute
();
fail
(
"Parameter value still set"
);
}
catch
(
SQLException
e
)
{
assertKnownException
(
e
);
}
assertThrows
(
ErrorCode
.
PARAMETER_NOT_SET_1
,
prep
).
execute
();
prep
.
close
();
conn
.
close
();
}
...
...
This diff is collapsed.
Click to expand it.
h2/src/test/org/h2/test/db/TestOutOfMemory.java
浏览文件 @
b0d2049a
...
...
@@ -52,13 +52,8 @@ public class TestOutOfMemory extends TestBase {
fail
();
}
catch
(
SQLException
e
)
{
assertEquals
(
ErrorCode
.
OUT_OF_MEMORY
,
e
.
getErrorCode
());
try
{
conn
.
close
();
fail
();
}
catch
(
SQLException
e2
)
{
assertEquals
(
ErrorCode
.
DATABASE_IS_CLOSED
,
e2
.
getErrorCode
());
}
}
assertThrows
(
ErrorCode
.
DATABASE_IS_CLOSED
,
conn
).
close
();
freeMemory
();
conn
=
null
;
conn
=
getConnection
(
"outOfMemory"
);
...
...
@@ -70,7 +65,7 @@ public class TestOutOfMemory extends TestBase {
try
{
conn
.
close
();
}
catch
(
SQLException
e
)
{
// out of memory will close the database
// out of memory will
/ may
close the database
assertKnownException
(
e
);
}
}
...
...
This diff is collapsed.
Click to expand it.
h2/src/test/org/h2/test/db/TestReadOnly.java
浏览文件 @
b0d2049a
...
...
@@ -64,18 +64,10 @@ public class TestReadOnly extends TestBase {
conn
.
close
();
conn
=
getConnection
(
"readonly;ACCESS_MODE_DATA=r"
);
Statement
stat
=
conn
.
createStatement
();
try
{
stat
.
execute
(
"CREATE TABLE TEST(ID INT)"
);
fail
();
}
catch
(
SQLException
e
)
{
assertKnownException
(
e
);
}
try
{
stat
.
execute
(
"SELECT * FROM TEST"
);
fail
();
}
catch
(
SQLException
e
)
{
assertKnownException
(
e
);
}
assertThrows
(
ErrorCode
.
DATABASE_IS_READ_ONLY
,
stat
).
execute
(
"CREATE TABLE TEST(ID INT)"
);
assertThrows
(
ErrorCode
.
TABLE_OR_VIEW_NOT_FOUND_1
,
stat
).
execute
(
"SELECT * FROM TEST"
);
stat
.
execute
(
"create local temporary linked table test("
+
"null, 'jdbc:h2:mem:test3', 'sa', 'sa', 'INFORMATION_SCHEMA.TABLES')"
);
ResultSet
rs
=
stat
.
executeQuery
(
"select * from test"
);
...
...
@@ -117,12 +109,8 @@ public class TestReadOnly extends TestBase {
assertTrue
(
conn
.
isReadOnly
());
stat
=
conn
.
createStatement
();
stat
.
execute
(
"SELECT * FROM TEST"
);
try
{
stat
.
execute
(
"DELETE FROM TEST"
);
fail
(
"read only delete"
);
}
catch
(
SQLException
e
)
{
assertKnownException
(
e
);
}
assertThrows
(
ErrorCode
.
DATABASE_IS_READ_ONLY
,
stat
).
execute
(
"DELETE FROM TEST"
);
conn
.
close
();
if
(
setReadOnly
)
{
...
...
@@ -132,12 +120,8 @@ public class TestReadOnly extends TestBase {
}
stat
=
conn
.
createStatement
();
stat
.
execute
(
"SELECT * FROM TEST"
);
try
{
stat
.
execute
(
"DELETE FROM TEST"
);
fail
(
"read only delete"
);
}
catch
(
SQLException
e
)
{
assertKnownException
(
e
);
}
assertThrows
(
ErrorCode
.
DATABASE_IS_READ_ONLY
,
stat
).
execute
(
"DELETE FROM TEST"
);
stat
.
execute
(
"SET DB_CLOSE_DELAY=0"
);
conn
.
close
();
}
...
...
@@ -158,6 +142,7 @@ public class TestReadOnly extends TestBase {
stat
.
execute
(
"insert into test select x from system_range(1, 11)"
);
try
{
getConnection
(
"readonly;ACCESS_MODE_DATA=r;OPEN_NEW=TRUE"
);
fail
();
}
catch
(
SQLException
e
)
{
assertEquals
(
ErrorCode
.
DATABASE_ALREADY_OPEN_1
,
e
.
getErrorCode
());
}
...
...
This diff is collapsed.
Click to expand it.
h2/src/test/org/h2/test/db/TestRights.java
浏览文件 @
b0d2049a
...
...
@@ -86,12 +86,7 @@ public class TestRights extends TestBase {
String
sql
=
"select * from admin_only where 1=0"
;
stat
.
execute
(
sql
);
try
{
stat2
.
execute
(
sql
);
fail
();
}
catch
(
SQLException
e
)
{
assertEquals
(
ErrorCode
.
NOT_ENOUGH_RIGHTS_FOR_1
,
e
.
getErrorCode
());
}
assertThrows
(
ErrorCode
.
NOT_ENOUGH_RIGHTS_FOR_1
,
stat2
).
execute
(
sql
);
DatabaseMetaData
meta
=
conn2
.
getMetaData
();
ResultSet
rs
;
...
...
@@ -119,12 +114,8 @@ public class TestRights extends TestBase {
String
user
=
getUser
().
toUpperCase
();
Connection
conn
=
getConnection
(
"rights"
);
stat
=
conn
.
createStatement
();
try
{
stat
.
execute
(
"DROP USER "
+
user
);
fail
();
}
catch
(
SQLException
e
)
{
assertEquals
(
ErrorCode
.
CANNOT_DROP_CURRENT_USER
,
e
.
getErrorCode
());
}
assertThrows
(
ErrorCode
.
CANNOT_DROP_CURRENT_USER
,
stat
).
execute
(
"DROP USER "
+
user
);
stat
.
execute
(
"CREATE USER TEST PASSWORD 'TEST' ADMIN"
);
stat
.
execute
(
"DROP USER "
+
user
);
conn
.
close
();
...
...
@@ -176,12 +167,8 @@ public class TestRights extends TestBase {
stat
.
execute
(
"CREATE TABLE TEST(ID INT)"
);
Connection
conn2
=
getConnection
(
"rights"
,
"READER"
,
getPassword
(
"READER"
));
Statement
stat2
=
conn2
.
createStatement
();
try
{
stat2
.
execute
(
"SELECT * FROM TEST"
);
fail
();
}
catch
(
SQLException
e
)
{
assertKnownException
(
e
);
}
assertThrows
(
ErrorCode
.
NOT_ENOUGH_RIGHTS_FOR_1
,
stat2
).
execute
(
"SELECT * FROM TEST"
);
stat2
.
execute
(
"CREATE LOCAL TEMPORARY TABLE IF NOT EXISTS MY_TEST(ID INT)"
);
stat2
.
execute
(
"INSERT INTO MY_TEST VALUES(1)"
);
stat2
.
execute
(
"SELECT * FROM MY_TEST"
);
...
...
@@ -205,18 +192,10 @@ public class TestRights extends TestBase {
conn
=
getConnection
(
"rights"
);
stat
=
conn
.
createStatement
();
stat
.
execute
(
"select * from b.test"
);
try
{
stat
.
execute
(
"alter user test1 admin false"
);
fail
();
}
catch
(
SQLException
e
)
{
assertKnownException
(
e
);
}
try
{
stat
.
execute
(
"drop user test1"
);
fail
();
}
catch
(
SQLException
e
)
{
assertKnownException
(
e
);
}
assertThrows
(
ErrorCode
.
CANNOT_DROP_2
,
stat
).
execute
(
"alter user test1 admin false"
);
assertThrows
(
ErrorCode
.
CANNOT_DROP_2
,
stat
).
execute
(
"drop user test1"
);
stat
.
execute
(
"drop schema b"
);
stat
.
execute
(
"alter user test1 admin false"
);
stat
.
execute
(
"drop user test1"
);
...
...
@@ -256,7 +235,8 @@ public class TestRights extends TestBase {
executeError
(
"UPDATE TEST SET NAME=(SELECT PASSWORD FROM PASS)"
);
executeError
(
"DELETE FROM TEST WHERE NAME=(SELECT PASSWORD FROM PASS)"
);
executeError
(
"SELECT * FROM (SELECT * FROM PASS)"
);
executeError
(
"CREATE VIEW X AS SELECT * FROM PASS_READER"
);
assertThrows
(
ErrorCode
.
TABLE_OR_VIEW_NOT_FOUND_1
,
stat
).
execute
(
"CREATE VIEW X AS SELECT * FROM PASS_READER"
);
conn
.
close
();
conn
=
getConnection
(
"rights"
);
...
...
@@ -276,7 +256,8 @@ public class TestRights extends TestBase {
executeSuccess
(
"GRANT SELECT ON ROLE_TABLE TO TEST_ROLE"
);
executeSuccess
(
"GRANT UPDATE ON ROLE_TABLE TO TEST_ROLE"
);
executeSuccess
(
"REVOKE UPDATE ON ROLE_TABLE FROM TEST_ROLE"
);
executeError
(
"REVOKE SELECT, SUB1 ON ROLE_TABLE FROM TEST_ROLE"
);
assertThrows
(
ErrorCode
.
ROLES_AND_RIGHT_CANNOT_BE_MIXED
,
stat
).
execute
(
"REVOKE SELECT, SUB1 ON ROLE_TABLE FROM TEST_ROLE"
);
executeSuccess
(
"GRANT TEST_ROLE TO TEST"
);
executeSuccess
(
"GRANT SELECT ON PUB_TABLE TO PUBLIC"
);
executeSuccess
(
"GRANT SELECT ON TEST TO TEST"
);
...
...
@@ -315,7 +296,8 @@ public class TestRights extends TestBase {
conn
=
getConnection
(
"rights;LOG=2"
,
"TEST"
,
getPassword
(
"def"
));
stat
=
conn
.
createStatement
();
executeError
(
"SET DEFAULT_TABLE_TYPE MEMORY"
);
assertThrows
(
ErrorCode
.
ADMIN_RIGHTS_REQUIRED
,
stat
).
execute
(
"SET DEFAULT_TABLE_TYPE MEMORY"
);
executeSuccess
(
"SELECT * FROM TEST"
);
executeSuccess
(
"SELECT * FROM SYSTEM_RANGE(1,2)"
);
...
...
@@ -330,15 +312,21 @@ public class TestRights extends TestBase {
executeSuccess
(
"SELECT * FROM SUB_TABLE"
);
executeSuccess
(
"INSERT INTO SUB_TABLE VALUES(1)"
);
executeError
(
"DELETE FROM SUB_TABLE"
);
executeError
(
"UPDATE FROM SUB_TABLE"
);
executeError
(
"CREATE USER TEST3 PASSWORD 'def'"
);
executeError
(
"ALTER USER TEST2 ADMIN FALSE"
);
executeError
(
"ALTER USER TEST2 SET PASSWORD 'ghi'"
);
executeError
(
"ALTER USER TEST2 RENAME TO TEST_X"
);
executeError
(
"ALTER USER TEST RENAME TO TEST_X"
);
executeError
(
"UPDATE SUB_TABLE SET ID=0"
);
assertThrows
(
ErrorCode
.
ADMIN_RIGHTS_REQUIRED
,
stat
).
execute
(
"CREATE USER TEST3 PASSWORD 'def'"
);
assertThrows
(
ErrorCode
.
ADMIN_RIGHTS_REQUIRED
,
stat
).
execute
(
"ALTER USER TEST2 ADMIN FALSE"
);
assertThrows
(
ErrorCode
.
ADMIN_RIGHTS_REQUIRED
,
stat
).
execute
(
"ALTER USER TEST2 SET PASSWORD 'ghi'"
);
assertThrows
(
ErrorCode
.
ADMIN_RIGHTS_REQUIRED
,
stat
).
execute
(
"ALTER USER TEST2 RENAME TO TEST_X"
);
assertThrows
(
ErrorCode
.
ADMIN_RIGHTS_REQUIRED
,
stat
).
execute
(
"ALTER USER TEST RENAME TO TEST_X"
);
executeSuccess
(
"ALTER USER TEST SET PASSWORD 'ghi'"
);
executeError
(
"DROP USER TEST2"
);
assertThrows
(
ErrorCode
.
ADMIN_RIGHTS_REQUIRED
,
stat
).
execute
(
"DROP USER TEST2"
);
conn
.
close
();
conn
=
getConnection
(
"rights"
);
...
...
@@ -372,13 +360,8 @@ public class TestRights extends TestBase {
executeSuccess
(
"DROP TABLE TEST"
);
}
private
void
executeError
(
String
sql
)
{
try
{
stat
.
execute
(
sql
);
fail
(
"not admin"
);
}
catch
(
SQLException
e
)
{
assertKnownException
(
e
);
}
private
void
executeError
(
String
sql
)
throws
SQLException
{
assertThrows
(
ErrorCode
.
NOT_ENOUGH_RIGHTS_FOR_1
,
stat
).
execute
(
sql
);
}
private
void
executeSuccess
(
String
sql
)
throws
SQLException
{
...
...
This diff is collapsed.
Click to expand it.
h2/src/test/org/h2/test/db/TestRunscript.java
浏览文件 @
b0d2049a
...
...
@@ -215,12 +215,8 @@ public class TestRunscript extends TestBase implements Trigger {
sql
+=
" CIPHER AES PASSWORD 'wrongPassword'"
;
}
if
(
password
)
{
try
{
stat2
.
execute
(
sql
);
fail
();
}
catch
(
SQLException
e
)
{
assertKnownException
(
e
);
}
assertThrows
(
ErrorCode
.
FILE_ENCRYPTION_ERROR_1
,
stat2
).
execute
(
sql
);
}
sql
=
"runscript from '"
+
getBaseDir
()
+
"/backup.2.sql'"
;
if
(
password
)
{
...
...
This diff is collapsed.
Click to expand it.
h2/src/test/org/h2/test/db/TestSQLInjection.java
浏览文件 @
b0d2049a
...
...
@@ -12,6 +12,7 @@ import java.sql.ResultSet;
import
java.sql.SQLException
;
import
java.sql.Statement
;
import
org.h2.constant.ErrorCode
;
import
org.h2.test.TestBase
;
/**
...
...
@@ -50,23 +51,13 @@ public class TestSQLInjection extends TestBase {
stat
.
execute
(
"CALL $$Hello World$$"
);
stat
.
execute
(
"SET ALLOW_LITERALS NUMBERS"
);
stat
.
execute
(
"CALL 123"
);
try
{
stat
.
execute
(
"CALL 'Hello'"
);
fail
();
}
catch
(
SQLException
e
)
{
assertKnownException
(
e
);
}
try
{
stat
.
execute
(
"CALL $$Hello World$$"
);
fail
();
}
catch
(
SQLException
e
)
{
assertKnownException
(
e
);
}
assertThrows
(
ErrorCode
.
LITERALS_ARE_NOT_ALLOWED
,
stat
).
execute
(
"CALL 'Hello'"
);
assertThrows
(
ErrorCode
.
SYNTAX_ERROR_1
,
stat
).
execute
(
"CALL $$Hello World$$"
);
stat
.
execute
(
"SET ALLOW_LITERALS NONE"
);
try
{
assertTrue
(
checkPasswordInsecure
(
"123456"
)
);
checkPasswordInsecure
(
"123456"
);
fail
();
}
catch
(
SQLException
e
)
{
assertKnownException
(
e
);
...
...
This diff is collapsed.
Click to expand it.
h2/src/test/org/h2/test/db/TestTempTables.java
浏览文件 @
b0d2049a
...
...
@@ -10,6 +10,7 @@ import java.sql.Connection;
import
java.sql.ResultSet
;
import
java.sql.SQLException
;
import
java.sql.Statement
;
import
org.h2.constant.ErrorCode
;
import
org.h2.engine.Constants
;
import
org.h2.test.TestBase
;
import
org.h2.util.IOUtils
;
...
...
@@ -185,12 +186,8 @@ public class TestTempTables extends TestBase {
stat
.
execute
(
"drop index idx1"
);
stat
.
execute
(
"create index idx1 on test(id)"
);
stat
.
execute
(
"insert into test select x from system_range(1, 10)"
);
try
{
stat
.
execute
(
"alter table test add column x int"
);
fail
();
}
catch
(
SQLException
e
)
{
assertKnownException
(
e
);
}
assertThrows
(
ErrorCode
.
FEATURE_NOT_SUPPORTED_1
,
stat
).
execute
(
"alter table test add column x int"
);
stat
.
execute
(
"drop table test"
);
}
...
...
@@ -255,12 +252,9 @@ public class TestTempTables extends TestBase {
rs
=
s1
.
executeQuery
(
"select * from test_temp"
);
assertResultRowCount
(
1
,
rs
);
c1
.
commit
();
try
{
s1
.
executeQuery
(
"select * from test_temp"
);
fail
(
"test_temp should have been dropped automatically"
);
}
catch
(
SQLException
e
)
{
assertKnownException
(
e
);
}
// test_temp should have been dropped automatically
assertThrows
(
ErrorCode
.
TABLE_OR_VIEW_NOT_FOUND_1
,
s1
).
executeQuery
(
"select * from test_temp"
);
}
}
This diff is collapsed.
Click to expand it.
h2/src/test/org/h2/test/db/TestTransaction.java
浏览文件 @
b0d2049a
...
...
@@ -101,12 +101,8 @@ public class TestTransaction extends TestBase {
prep
.
execute
();
Connection
conn2
=
getConnection
(
"transaction"
);
conn2
.
setAutoCommit
(
false
);
try
{
conn2
.
createStatement
().
execute
(
"select * from test for update"
);
fail
();
}
catch
(
SQLException
e
)
{
assertEquals
(
ErrorCode
.
LOCK_TIMEOUT_1
,
e
.
getErrorCode
());
}
assertThrows
(
ErrorCode
.
LOCK_TIMEOUT_1
,
conn2
.
createStatement
()).
execute
(
"select * from test for update"
);
conn2
.
close
();
conn
.
close
();
}
...
...
@@ -126,15 +122,12 @@ public class TestTransaction extends TestBase {
prep
.
execute
();
Connection
conn2
=
getConnection
(
"transaction"
);
conn2
.
setAutoCommit
(
false
);
Statement
stat2
=
conn2
.
createStatement
();
if
(
config
.
mvcc
&&
Constants
.
VERSION_MINOR
>=
3
)
{
conn2
.
createStatement
().
execute
(
"update test set name = 'Welt' where id = 2"
);
}
try
{
conn2
.
createStatement
().
execute
(
"update test set name = 'Hallo' where id = 1"
);
fail
();
}
catch
(
SQLException
e
)
{
assertKnownException
(
e
);
stat2
.
execute
(
"update test set name = 'Welt' where id = 2"
);
}
assertThrows
(
ErrorCode
.
LOCK_TIMEOUT_1
,
stat2
).
execute
(
"update test set name = 'Hallo' where id = 1"
);
conn2
.
close
();
conn
.
close
();
}
...
...
@@ -172,13 +165,9 @@ public class TestTransaction extends TestBase {
conn
=
getConnection
(
"transaction"
);
}
stat
=
conn
.
createStatement
();
try
{
stat
.
execute
(
"delete from master"
);
fail
();
}
catch
(
SQLException
ex
)
{
// ok
assertThrows
(
ErrorCode
.
REFERENTIAL_INTEGRITY_VIOLATED_CHILD_EXISTS_1
,
stat
).
execute
(
"delete from master"
);
conn
.
rollback
();
}
rs
=
stat
.
executeQuery
(
"select * from master where id=1"
);
assertResultRowCount
(
1
,
rs
);
rs
=
stat
.
executeQuery
(
"select * from child1"
);
...
...
@@ -219,12 +208,8 @@ public class TestTransaction extends TestBase {
conn
=
getConnection
(
"transaction"
);
}
stat
=
conn
.
createStatement
();
try
{
stat
.
execute
(
"delete from master"
);
fail
();
}
catch
(
SQLException
ex
)
{
// ok
}
assertThrows
(
ErrorCode
.
REFERENTIAL_INTEGRITY_VIOLATED_CHILD_EXISTS_1
,
stat
).
execute
(
"delete from master"
);
rs
=
stat
.
executeQuery
(
"select * from master where id=1"
);
assertResultRowCount
(
1
,
rs
);
rs
=
stat
.
executeQuery
(
"select * from child1 where id=1"
);
...
...
@@ -268,12 +253,8 @@ public class TestTransaction extends TestBase {
c2
.
setAutoCommit
(
false
);
s1
.
executeUpdate
(
"insert into A(code) values('one')"
);
Statement
s2
=
c2
.
createStatement
();
try
{
s2
.
executeUpdate
(
"insert into B values('two', 1)"
);
fail
();
}
catch
(
SQLException
e
)
{
assertKnownException
(
e
);
}
assertThrows
(
ErrorCode
.
LOCK_TIMEOUT_1
,
s2
).
executeUpdate
(
"insert into B values('two', 1)"
);
c2
.
commit
();
c1
.
rollback
();
c1
.
close
();
...
...
@@ -420,12 +401,7 @@ public class TestTransaction extends TestBase {
result
=
New
.
arrayList
();
rs1
=
s1
.
executeQuery
(
"SELECT * FROM NEST1 ORDER BY ID"
);
rs2
=
s1
.
executeQuery
(
"SELECT * FROM NEST2 ORDER BY ID"
);
try
{
rs1
.
next
();
fail
(
"next worked on a closed result set"
);
}
catch
(
SQLException
e
)
{
assertKnownException
(
e
);
}
assertThrows
(
ErrorCode
.
OBJECT_CLOSED
,
rs1
).
next
();
// this is already closed, so but closing again should no do any harm
rs1
.
close
();
while
(
rs2
.
next
())
{
...
...
This diff is collapsed.
Click to expand it.
h2/src/test/org/h2/test/db/TestTriggersConstraints.java
浏览文件 @
b0d2049a
...
...
@@ -106,13 +106,9 @@ public class TestTriggersConstraints extends TestBase implements Trigger {
stat
.
execute
(
"create table test(id int) as select 1"
);
stat
.
execute
(
"create trigger test_u before update on test "
+
"for each row call \""
+
DeleteTrigger
.
class
.
getName
()
+
"\""
);
try
{
stat
.
execute
(
"update test set id = 2"
);
fail
();
}
catch
(
SQLException
e
)
{
// this threw a NullPointerException
assertKnownException
(
e
);
}
assertThrows
(
ErrorCode
.
ROW_NOT_FOUND_WHEN_DELETING_1
,
stat
).
execute
(
"update test set id = 2"
);
stat
.
execute
(
"drop table test"
);
conn
.
close
();
}
...
...
@@ -392,12 +388,8 @@ public class TestTriggersConstraints extends TestBase implements Trigger {
stat
.
execute
(
"DROP TRIGGER IF EXISTS INS_BEFORE"
);
stat
.
execute
(
"DROP TRIGGER IF EXISTS INS_BEFORE"
);
stat
.
execute
(
"DROP TRIGGER IF EXISTS INS_AFTER_ROLLBACK"
);
try
{
stat
.
execute
(
"DROP TRIGGER INS_BEFORE"
);
fail
();
}
catch
(
SQLException
e
)
{
assertKnownException
(
e
);
}
assertThrows
(
ErrorCode
.
TRIGGER_NOT_FOUND_1
,
stat
).
execute
(
"DROP TRIGGER INS_BEFORE"
);
stat
.
execute
(
"DROP TRIGGER INS_AFTER"
);
stat
.
execute
(
"DROP TRIGGER UPD_BEFORE"
);
stat
.
execute
(
"UPDATE TEST SET NAME=NAME||'-upd-no_trigger'"
);
...
...
@@ -420,7 +412,7 @@ public class TestTriggersConstraints extends TestBase implements Trigger {
}
}
public
void
fire
(
Connection
conn
,
Object
[]
oldRow
,
Object
[]
newRow
)
{
public
void
fire
(
Connection
conn
,
Object
[]
oldRow
,
Object
[]
newRow
)
throws
SQLException
{
if
(
mustNotCallTrigger
)
{
throw
new
AssertionError
(
"must not be called now"
);
}
...
...
@@ -452,27 +444,10 @@ public class TestTriggersConstraints extends TestBase implements Trigger {
// ignore
}
private
void
checkCommit
(
Connection
conn
)
{
try
{
conn
.
commit
();
throw
new
AssertionError
(
"Commit must not work here"
);
}
catch
(
SQLException
e
)
{
try
{
assertKnownException
(
e
);
}
catch
(
Exception
e2
)
{
throw
new
AssertionError
(
"Unexpected: "
+
e
.
toString
());
}
}
try
{
conn
.
createStatement
().
execute
(
"CREATE TABLE X(ID INT)"
);
throw
new
AssertionError
(
"CREATE TABLE WORKED, but implicitly commits"
);
}
catch
(
SQLException
e
)
{
try
{
assertKnownException
(
e
);
}
catch
(
Exception
e2
)
{
throw
new
AssertionError
(
"Unexpected: "
+
e
.
toString
());
}
}
private
void
checkCommit
(
Connection
conn
)
throws
SQLException
{
assertThrows
(
ErrorCode
.
COMMIT_ROLLBACK_NOT_ALLOWED
,
conn
).
commit
();
assertThrows
(
ErrorCode
.
COMMIT_ROLLBACK_NOT_ALLOWED
,
conn
.
createStatement
()).
execute
(
"CREATE TABLE X(ID INT)"
);
}
public
void
init
(
Connection
conn
,
String
schemaName
,
String
trigger
,
String
tableName
,
boolean
before
,
int
type
)
{
...
...
This diff is collapsed.
Click to expand it.
h2/src/test/org/h2/test/db/TestView.java
浏览文件 @
b0d2049a
...
...
@@ -11,6 +11,7 @@ import java.sql.PreparedStatement;
import
java.sql.ResultSet
;
import
java.sql.SQLException
;
import
java.sql.Statement
;
import
org.h2.constant.ErrorCode
;
import
org.h2.test.TestBase
;
/**
...
...
@@ -74,12 +75,8 @@ public class TestView extends TestBase {
stat
.
execute
(
"INSERT INTO Test(f1, f2) VALUES ('value1','value3')"
);
PreparedStatement
ps
=
conn
.
prepareStatement
(
"CREATE VIEW Test_View AS SELECT f2 FROM Test WHERE f1=?"
);
ps
.
setString
(
1
,
"value1"
);
try
{
ps
.
executeUpdate
();
fail
();
}
catch
(
SQLException
e
)
{
assertKnownException
(
e
);
}
assertThrows
(
ErrorCode
.
FEATURE_NOT_SUPPORTED_1
,
ps
).
executeUpdate
();
// ResultSet rs;
// rs = stat.executeQuery("SELECT * FROM Test_View");
// assertTrue(rs.next());
...
...
This diff is collapsed.
Click to expand it.
h2/src/test/org/h2/test/db/TestViewAlterTable.java
浏览文件 @
b0d2049a
...
...
@@ -71,12 +71,8 @@ public class TestViewAlterTable extends TestBase {
// simple
stat
.
execute
(
"create table test(id identity, name varchar) as select x, 'Hello'"
);
stat
.
execute
(
"create view test_view as select * from test"
);
try
{
stat
.
execute
(
"alter table test drop name"
);
fail
();
}
catch
(
SQLException
e
)
{
assertEquals
(
ErrorCode
.
VIEW_IS_INVALID_2
,
e
.
getErrorCode
());
}
assertThrows
(
ErrorCode
.
VIEW_IS_INVALID_2
,
stat
).
execute
(
"alter table test drop name"
);
ResultSet
rs
=
stat
.
executeQuery
(
"select * from test_view"
);
assertTrue
(
rs
.
next
());
stat
.
execute
(
"drop view test_view"
);
...
...
@@ -84,12 +80,9 @@ public class TestViewAlterTable extends TestBase {
// nested
createTestData
();
try
{
stat
.
execute
(
"alter table test drop column a"
);
fail
(
"Should throw exception because V1 uses column A"
);
}
catch
(
SQLException
e
)
{
assertEquals
(
ErrorCode
.
VIEW_IS_INVALID_2
,
e
.
getErrorCode
());
}
// should throw exception because V1 uses column A
assertThrows
(
ErrorCode
.
VIEW_IS_INVALID_2
,
stat
).
execute
(
"alter table test drop column a"
);
stat
.
execute
(
"drop table test cascade"
);
}
...
...
@@ -109,14 +102,11 @@ public class TestViewAlterTable extends TestBase {
createTestData
();
stat
.
execute
(
"create view v4 as select * from test"
);
stat
.
execute
(
"alter table test add d int default 6"
);
try
{
stat
.
executeQuery
(
"select d from v4"
);
// H2 doesn't remember v4 as 'select * from test',
// it instead remembers each individual column that was in 'test' when the
// view was originally created. This is consistent with PostgreSQL.
}
catch
(
SQLException
e
)
{
assertEquals
(
ErrorCode
.
COLUMN_NOT_FOUND_1
,
e
.
getErrorCode
());
}
assertThrows
(
ErrorCode
.
COLUMN_NOT_FOUND_1
,
stat
).
executeQuery
(
"select d from v4"
);
checkViewRemainsValid
();
}
...
...
This diff is collapsed.
Click to expand it.
h2/src/test/org/h2/test/db/TestViewDropView.java
浏览文件 @
b0d2049a
...
...
@@ -48,12 +48,8 @@ public class TestViewDropView extends TestBase {
}
private
void
testCreateForceView
()
throws
SQLException
{
try
{
stat
.
execute
(
"create view test_view as select * from test"
);
fail
();
}
catch
(
SQLException
e
)
{
assertEquals
(
ErrorCode
.
TABLE_OR_VIEW_NOT_FOUND_1
,
e
.
getErrorCode
());
}
assertThrows
(
ErrorCode
.
TABLE_OR_VIEW_NOT_FOUND_1
,
stat
).
execute
(
"create view test_view as select * from test"
);
stat
.
execute
(
"create force view test_view as select * from test"
);
stat
.
execute
(
"create table test(id int)"
);
stat
.
execute
(
"alter view test_view recompile"
);
...
...
@@ -71,64 +67,34 @@ public class TestViewDropView extends TestBase {
ResultSet
rs
=
stat
.
executeQuery
(
"select value from information_schema.settings where name = 'DROP_RESTRICT'"
);
rs
.
next
();
boolean
dropRestrict
=
rs
.
getBoolean
(
1
);
try
{
// Should fail because have dependencies
stat
.
execute
(
"drop view v1"
);
if
(
dropRestrict
)
{
fail
();
}
}
catch
(
SQLException
e
)
{
if
(!
dropRestrict
)
{
assertEquals
(
ErrorCode
.
CANNOT_DROP_2
,
e
.
getErrorCode
());
}
}
if
(
dropRestrict
)
{
// should fail because have dependencies
assertThrows
(
ErrorCode
.
CANNOT_DROP_2
,
stat
).
execute
(
"drop view v1"
);
}
else
{
stat
.
execute
(
"drop view v1"
);
checkViewRemainsValid
();
}
}
private
void
testDropViewRestrict
()
throws
SQLException
{
createTestData
();
try
{
// Should fail because have dependencies
stat
.
execute
(
"drop view v1 restrict"
);
fail
();
}
catch
(
SQLException
e
)
{
assertEquals
(
ErrorCode
.
CANNOT_DROP_2
,
e
.
getErrorCode
());
}
// should fail because have dependencies
assertThrows
(
ErrorCode
.
CANNOT_DROP_2
,
stat
).
execute
(
"drop view v1 restrict"
);
checkViewRemainsValid
();
}
private
void
testDropViewCascade
()
throws
SQLException
{
createTestData
();
stat
.
execute
(
"drop view v1 cascade"
);
try
{
stat
.
execute
(
"select * from v1"
);
fail
(
"Exception should be thrown - v1 should be deleted"
);
}
catch
(
SQLException
e
)
{
assertEquals
(
ErrorCode
.
TABLE_OR_VIEW_NOT_FOUND_1
,
e
.
getErrorCode
());
}
try
{
stat
.
execute
(
"select * from v2"
);
fail
(
"Exception should be thrown - v2 should be deleted"
);
}
catch
(
SQLException
e
)
{
assertEquals
(
ErrorCode
.
TABLE_OR_VIEW_NOT_FOUND_1
,
e
.
getErrorCode
());
}
try
{
stat
.
execute
(
"select * from v3"
);
fail
(
"Exception should be thrown - v3 should be deleted"
);
}
catch
(
SQLException
e
)
{
assertEquals
(
ErrorCode
.
TABLE_OR_VIEW_NOT_FOUND_1
,
e
.
getErrorCode
());
}
// v1, v2, v3 should be deleted
assertThrows
(
ErrorCode
.
TABLE_OR_VIEW_NOT_FOUND_1
,
stat
).
execute
(
"select * from v1"
);
assertThrows
(
ErrorCode
.
TABLE_OR_VIEW_NOT_FOUND_1
,
stat
).
execute
(
"select * from v2"
);
assertThrows
(
ErrorCode
.
TABLE_OR_VIEW_NOT_FOUND_1
,
stat
).
execute
(
"select * from v3"
);
stat
.
execute
(
"drop table test"
);
}
...
...
@@ -142,16 +108,11 @@ public class TestViewDropView extends TestBase {
private
void
testCreateOrReplaceViewWithNowInvalidDependentViews
()
throws
SQLException
{
createTestData
();
try
{
// v2 and v3 need more than just "c", so we should get an error
stat
.
execute
(
"create or replace view v1 as select c from test"
);
fail
(
"Exception should be thrown - dependent views need more columns than just 'c'"
);
}
catch
(
SQLException
e
)
{
assertEquals
(
ErrorCode
.
COLUMN_NOT_FOUND_1
,
e
.
getErrorCode
());
}
// Make sure our old views come back ok
// dependent views need more columns than just 'c'
assertThrows
(
ErrorCode
.
COLUMN_NOT_FOUND_1
,
stat
).
execute
(
"create or replace view v1 as select c from test"
);
// make sure our old views come back ok
checkViewRemainsValid
();
}
...
...
@@ -161,18 +122,9 @@ public class TestViewDropView extends TestBase {
// v2 and v3 need more than just "c",
// but we want to force the creation of v1 anyway
stat
.
execute
(
"create or replace force view v1 as select c from test"
);
try
{
// now v2 and v3 are broken, but they still exist
ResultSet
rs
=
stat
.
executeQuery
(
"select b from v2"
);
assertTrue
(
rs
.
next
());
assertEquals
(
1
,
rs
.
getInt
(
1
));
assertFalse
(
rs
.
next
());
}
catch
(
SQLException
e
)
{
assertEquals
(
ErrorCode
.
COLUMN_NOT_FOUND_1
,
e
.
getErrorCode
());
}
assertThrows
(
ErrorCode
.
COLUMN_NOT_FOUND_1
,
stat
).
executeQuery
(
"select b from v2"
);
stat
.
execute
(
"drop table test cascade"
);
}
...
...
This diff is collapsed.
Click to expand it.
h2/src/test/org/h2/test/jdbc/TestCallableStatement.java
浏览文件 @
b0d2049a
...
...
@@ -138,21 +138,12 @@ public class TestCallableStatement extends TestBase {
}
// test for exceptions after closing
call
.
close
();
try
{
call
.
executeUpdate
();
}
catch
(
SQLException
e
)
{
assertEquals
(
ErrorCode
.
OBJECT_CLOSED
,
e
.
getErrorCode
());
}
try
{
call
.
registerOutParameter
(
1
,
Types
.
INTEGER
);
}
catch
(
SQLException
e
)
{
assertEquals
(
ErrorCode
.
OBJECT_CLOSED
,
e
.
getErrorCode
());
}
try
{
call
.
getString
(
"X"
);
}
catch
(
SQLException
e
)
{
assertEquals
(
ErrorCode
.
OBJECT_CLOSED
,
e
.
getErrorCode
());
}
assertThrows
(
ErrorCode
.
OBJECT_CLOSED
,
call
).
executeUpdate
();
assertThrows
(
ErrorCode
.
OBJECT_CLOSED
,
call
).
registerOutParameter
(
1
,
Types
.
INTEGER
);
assertThrows
(
ErrorCode
.
OBJECT_CLOSED
,
call
).
getString
(
"X"
);
}
/**
...
...
This diff is collapsed.
Click to expand it.
h2/src/test/org/h2/test/jdbc/TestCancel.java
浏览文件 @
b0d2049a
...
...
@@ -81,12 +81,8 @@ public class TestCancel extends TestBase {
Connection
conn
=
getConnection
(
"cancel"
);
Statement
stat
=
conn
.
createStatement
();
stat
.
execute
(
"set query_timeout 1"
);
try
{
stat
.
execute
(
"select count(*) from system_range(1, 1000000), system_range(1, 1000000)"
);
fail
();
}
catch
(
SQLException
e
)
{
assertKnownException
(
e
);
}
assertThrows
(
ErrorCode
.
STATEMENT_WAS_CANCELED
,
stat
).
execute
(
"select count(*) from system_range(1, 1000000), system_range(1, 1000000)"
);
stat
.
execute
(
"set query_timeout 0"
);
stat
.
execute
(
"select count(*) from system_range(1, 1000), system_range(1, 1000)"
);
conn
.
close
();
...
...
@@ -119,12 +115,8 @@ public class TestCancel extends TestBase {
ResultSet
rs
=
s2
.
executeQuery
(
"SELECT VALUE FROM INFORMATION_SCHEMA.SETTINGS WHERE NAME = 'QUERY_TIMEOUT'"
);
rs
.
next
();
assertEquals
(
1000
,
rs
.
getInt
(
1
));
try
{
stat
.
executeQuery
(
"SELECT MAX(RAND()) FROM SYSTEM_RANGE(1, 100000000)"
);
fail
();
}
catch
(
SQLException
e
)
{
assertEquals
(
ErrorCode
.
STATEMENT_WAS_CANCELED
,
e
.
getErrorCode
());
}
assertThrows
(
ErrorCode
.
STATEMENT_WAS_CANCELED
,
stat
).
executeQuery
(
"SELECT MAX(RAND()) FROM SYSTEM_RANGE(1, 100000000)"
);
stat
.
setQueryTimeout
(
0
);
stat
.
execute
(
"SET QUERY_TIMEOUT 1100"
);
assertEquals
(
2
,
stat
.
getQueryTimeout
());
...
...
@@ -136,12 +128,8 @@ public class TestCancel extends TestBase {
Connection
conn
=
getConnection
(
"cancel"
);
Statement
stat
=
conn
.
createStatement
();
stat
.
execute
(
"SET QUERY_TIMEOUT 10"
);
try
{
stat
.
executeQuery
(
"SELECT MAX(RAND()) FROM SYSTEM_RANGE(1, 100000000)"
);
fail
();
}
catch
(
SQLException
e
)
{
assertEquals
(
ErrorCode
.
STATEMENT_WAS_CANCELED
,
e
.
getErrorCode
());
}
assertThrows
(
ErrorCode
.
STATEMENT_WAS_CANCELED
,
stat
).
executeQuery
(
"SELECT MAX(RAND()) FROM SYSTEM_RANGE(1, 100000000)"
);
conn
.
close
();
}
...
...
@@ -149,12 +137,8 @@ public class TestCancel extends TestBase {
deleteDb
(
"cancel"
);
Connection
conn
=
getConnection
(
"cancel;MAX_QUERY_TIMEOUT=10"
);
Statement
stat
=
conn
.
createStatement
();
try
{
stat
.
executeQuery
(
"SELECT MAX(RAND()) FROM SYSTEM_RANGE(1, 100000000)"
);
fail
();
}
catch
(
SQLException
e
)
{
assertEquals
(
ErrorCode
.
STATEMENT_WAS_CANCELED
,
e
.
getErrorCode
());
}
assertThrows
(
ErrorCode
.
STATEMENT_WAS_CANCELED
,
stat
).
executeQuery
(
"SELECT MAX(RAND()) FROM SYSTEM_RANGE(1, 100000000)"
);
conn
.
close
();
}
...
...
@@ -186,20 +170,16 @@ public class TestCancel extends TestBase {
prep
.
execute
();
}
trace
(
"inserted"
);
// TODO test insert.. select
// TODO test insert
into .
.. select
for
(
int
i
=
1
;;)
{
Statement
query
=
conn
.
createStatement
();
CancelThread
cancel
=
new
CancelThread
(
query
,
i
);
visit
(
0
);
cancel
.
start
();
Thread
.
yield
();
try
{
query
.
executeQuery
(
"SELECT VISIT(ID), (SELECT SUM(X) FROM SYSTEM_RANGE(1, 10000) WHERE X<>ID) FROM TEST ORDER BY ID"
);
}
catch
(
SQLException
e
)
{
assertKnownException
(
e
);
// ignore canceled statements
}
assertThrows
(
ErrorCode
.
STATEMENT_WAS_CANCELED
,
query
).
executeQuery
(
"SELECT VISIT(ID), (SELECT SUM(X) "
+
"FROM SYSTEM_RANGE(1, 10000) WHERE X<>ID) FROM TEST ORDER BY ID"
);
cancel
.
stopNow
();
cancel
.
join
();
if
(
lastVisited
==
0
)
{
...
...
This diff is collapsed.
Click to expand it.
h2/src/test/org/h2/test/jdbc/TestDatabaseEventListener.java
浏览文件 @
b0d2049a
...
...
@@ -14,6 +14,7 @@ import java.util.Properties;
import
org.h2.Driver
;
import
org.h2.api.DatabaseEventListener
;
import
org.h2.constant.ErrorCode
;
import
org.h2.test.TestBase
;
/**
...
...
@@ -126,11 +127,7 @@ public class TestDatabaseEventListener extends TestBase implements DatabaseEvent
stat
.
execute
(
"insert into test values(2)"
);
stat
.
execute
(
"checkpoint sync"
);
stat
.
execute
(
"shutdown immediately"
);
try
{
conn
.
close
();
}
catch
(
SQLException
e
)
{
assertKnownException
(
e
);
}
assertThrows
(
ErrorCode
.
DATABASE_IS_CLOSED
,
conn
).
close
();
// now the index should be re-built
conn
=
DriverManager
.
getConnection
(
url
,
p
);
conn
.
close
();
...
...
This diff is collapsed.
Click to expand it.
h2/src/test/org/h2/test/jdbc/TestLobApi.java
浏览文件 @
b0d2049a
...
...
@@ -18,6 +18,7 @@ import java.sql.PreparedStatement;
import
java.sql.ResultSet
;
import
java.sql.Statement
;
import
java.util.Random
;
import
org.h2.constant.ErrorCode
;
import
org.h2.jdbc.JdbcConnection
;
import
org.h2.test.TestBase
;
...
...
@@ -65,8 +66,9 @@ public class TestLobApi extends TestBase {
stat
=
conn
.
createStatement
();
stat
.
execute
(
"create table test(id identity, c clob, b blob)"
);
PreparedStatement
prep
=
conn
.
prepareStatement
(
"insert into test values(null, ?, ?)"
);
try
{
prep
.
setCharacterStream
(
1
,
new
Reader
()
{
assertThrows
(
ErrorCode
.
IO_EXCEPTION_2
,
prep
).
setCharacterStream
(
1
,
new
Reader
()
{
int
pos
;
public
int
read
(
char
[]
buff
,
int
off
,
int
len
)
throws
IOException
{
pos
+=
len
;
...
...
@@ -82,16 +84,14 @@ public class TestLobApi extends TestBase {
// nothing to do
}
},
-
1
);
fail
();
}
catch
(
Exception
e
)
{
// expected
}
prep
.
setString
(
1
,
new
String
(
new
char
[
10000
]));
prep
.
setBytes
(
2
,
new
byte
[
0
]);
prep
.
execute
();
prep
.
setString
(
1
,
""
);
try
{
prep
.
setBinaryStream
(
2
,
new
InputStream
()
{
assertThrows
(
ErrorCode
.
IO_EXCEPTION_2
,
prep
).
setBinaryStream
(
2
,
new
InputStream
()
{
int
pos
;
public
int
read
()
throws
IOException
{
pos
++;
...
...
@@ -104,10 +104,7 @@ public class TestLobApi extends TestBase {
return
0
;
}
},
-
1
);
fail
();
}
catch
(
Exception
e
)
{
// expected
}
prep
.
setBytes
(
2
,
new
byte
[
10000
]);
prep
.
execute
();
ResultSet
rs
=
stat
.
executeQuery
(
"select c, b from test order by id"
);
...
...
This diff is collapsed.
Click to expand it.
h2/src/test/org/h2/test/jdbc/TestNativeSQL.java
浏览文件 @
b0d2049a
...
...
@@ -12,6 +12,7 @@ import java.sql.SQLException;
import
java.sql.Statement
;
import
java.util.Random
;
import
org.h2.constant.ErrorCode
;
import
org.h2.test.TestBase
;
/**
...
...
@@ -232,12 +233,8 @@ public class TestNativeSQL extends TestBase {
stat
.
setEscapeProcessing
(
true
);
stat
.
execute
(
"CALL {d '2001-01-01'}"
);
stat
.
setEscapeProcessing
(
false
);
try
{
stat
.
execute
(
"CALL {d '2001-01-01'} // this is a test"
);
fail
(
"expected error if setEscapeProcessing=false"
);
}
catch
(
SQLException
e
)
{
assertKnownException
(
e
);
}
assertThrows
(
ErrorCode
.
SYNTAX_ERROR_2
,
stat
).
execute
(
"CALL {d '2001-01-01'} // this is a test"
);
assertFalse
(
conn
.
isClosed
());
}
...
...
This diff is collapsed.
Click to expand it.
h2/src/test/org/h2/test/jdbc/TestPreparedStatement.java
浏览文件 @
b0d2049a
...
...
@@ -125,12 +125,8 @@ public class TestPreparedStatement extends TestBase {
}
private
void
testExecuteUpdateCall
(
Connection
conn
)
throws
SQLException
{
Statement
stat
=
conn
.
createStatement
();
try
{
stat
.
executeUpdate
(
"CALL HASH('SHA256', STRINGTOUTF8('Password'), 1000)"
);
}
catch
(
SQLException
e
)
{
assertEquals
(
ErrorCode
.
DATA_CONVERSION_ERROR_1
,
e
.
getErrorCode
());
}
assertThrows
(
ErrorCode
.
DATA_CONVERSION_ERROR_1
,
conn
.
createStatement
()).
executeUpdate
(
"CALL HASH('SHA256', STRINGTOUTF8('Password'), 1000)"
);
}
private
void
testPrepareExecute
(
Connection
conn
)
throws
SQLException
{
...
...
@@ -185,21 +181,10 @@ public class TestPreparedStatement extends TestBase {
private
void
testExecuteErrorTwice
(
Connection
conn
)
throws
SQLException
{
PreparedStatement
prep
=
conn
.
prepareStatement
(
"CREATE TABLE BAD AS SELECT A"
);
try
{
prep
.
execute
();
fail
();
}
catch
(
SQLException
e
)
{
assertKnownException
(
e
);
}
try
{
prep
.
execute
();
fail
();
}
catch
(
SQLException
e
)
{
assertKnownException
(
e
);
}
assertThrows
(
ErrorCode
.
COLUMN_NOT_FOUND_1
,
prep
).
execute
();
assertThrows
(
ErrorCode
.
COLUMN_NOT_FOUND_1
,
prep
).
execute
();
}
private
void
testTempView
(
Connection
conn
)
throws
SQLException
{
Statement
stat
=
conn
.
createStatement
();
PreparedStatement
prep
;
...
...
@@ -293,15 +278,8 @@ public class TestPreparedStatement extends TestBase {
}
private
void
testUnknownDataType
(
Connection
conn
)
throws
SQLException
{
try
{
PreparedStatement
prep
=
conn
.
prepareStatement
(
"SELECT * FROM (SELECT ? FROM DUAL)"
);
prep
.
setInt
(
1
,
1
);
prep
.
execute
();
fail
();
}
catch
(
SQLException
e
)
{
assertKnownException
(
e
);
}
assertThrows
(
ErrorCode
.
UNKNOWN_DATA_TYPE_1
,
conn
).
prepareStatement
(
"SELECT * FROM (SELECT ? FROM DUAL)"
);
PreparedStatement
prep
=
conn
.
prepareStatement
(
"SELECT -?"
);
prep
.
setInt
(
1
,
1
);
prep
.
execute
();
...
...
@@ -528,25 +506,10 @@ public class TestPreparedStatement extends TestBase {
assertEquals
(
0
,
pm
.
getScale
(
1
));
assertEquals
(
ResultSetMetaData
.
columnNullableUnknown
,
pm
.
isNullable
(
1
));
assertEquals
(
pm
.
isSigned
(
1
),
true
);
try
{
pm
.
getPrecision
(
0
);
fail
();
}
catch
(
SQLException
e
)
{
assertKnownException
(
e
);
}
try
{
pm
.
getPrecision
(
4
);
fail
();
}
catch
(
SQLException
e
)
{
assertKnownException
(
e
);
}
assertThrows
(
ErrorCode
.
INVALID_VALUE_2
,
pm
).
getPrecision
(
0
);
assertThrows
(
ErrorCode
.
INVALID_VALUE_2
,
pm
).
getPrecision
(
4
);
prep
.
close
();
try
{
pm
.
getPrecision
(
1
);
fail
();
}
catch
(
SQLException
e
)
{
assertKnownException
(
e
);
}
assertThrows
(
ErrorCode
.
OBJECT_CLOSED
,
pm
).
getPrecision
(
1
);
Statement
stat
=
conn
.
createStatement
();
stat
.
execute
(
"CREATE TABLE TEST3(ID INT, NAME VARCHAR(255), DATA DECIMAL(10,2))"
);
...
...
@@ -653,12 +616,8 @@ public class TestPreparedStatement extends TestBase {
prep
.
setString
(
1
,
"Hello"
);
rs
=
prep
.
executeQuery
();
assertFalse
(
rs
.
next
());
try
{
conn
.
prepareStatement
(
"select ? from dual union select ? from dual"
);
fail
();
}
catch
(
SQLException
e
)
{
assertKnownException
(
e
);
}
assertThrows
(
ErrorCode
.
UNKNOWN_DATA_TYPE_1
,
conn
).
prepareStatement
(
"select ? from dual union select ? from dual"
);
prep
=
conn
.
prepareStatement
(
"select cast(? as varchar) from dual union select ? from dual"
);
assertEquals
(
2
,
prep
.
getParameterMetaData
().
getParameterCount
());
prep
.
setString
(
1
,
"a"
);
...
...
This diff is collapsed.
Click to expand it.
h2/src/test/org/h2/test/jdbc/TestResultSet.java
浏览文件 @
b0d2049a
...
...
@@ -28,6 +28,7 @@ import java.util.Calendar;
import
java.util.Locale
;
import
java.util.TimeZone
;
import
org.h2.constant.ErrorCode
;
import
org.h2.constant.SysProperties
;
import
org.h2.test.TestBase
;
...
...
@@ -453,24 +454,9 @@ public class TestResultSet extends TestBase {
// 0 should be an allowed value (but it's not defined what is actually
// means)
rs
.
setFetchSize
(
0
);
trace
(
"after set to 0, fetch size="
+
rs
.
getFetchSize
());
// this should break
try
{
rs
.
setFetchSize
(-
1
);
fail
(
"fetch size -1 is not allowed"
);
}
catch
(
SQLException
e
)
{
assertKnownException
(
e
);
trace
(
e
.
toString
());
}
trace
(
"after try to set to -1, fetch size="
+
rs
.
getFetchSize
());
try
{
rs
.
setFetchSize
(
100
);
fail
(
"fetch size 100 is bigger than maxrows - not allowed"
);
}
catch
(
SQLException
e
)
{
assertKnownException
(
e
);
trace
(
e
.
toString
());
}
trace
(
"after try set to 100, fetch size="
+
rs
.
getFetchSize
());
assertThrows
(
ErrorCode
.
INVALID_VALUE_2
,
rs
).
setFetchSize
(-
1
);
// fetch size 100 is bigger than maxrows - not allowed
assertThrows
(
ErrorCode
.
INVALID_VALUE_2
,
rs
).
setFetchSize
(
100
);
rs
.
setFetchSize
(
6
);
assertTrue
(
rs
.
getRow
()
==
1
);
...
...
This diff is collapsed.
Click to expand it.
h2/src/test/org/h2/test/jdbc/TestStatement.java
浏览文件 @
b0d2049a
...
...
@@ -11,6 +11,7 @@ import java.sql.ResultSet;
import
java.sql.SQLException
;
import
java.sql.Savepoint
;
import
java.sql.Statement
;
import
org.h2.constant.ErrorCode
;
import
org.h2.constant.SysProperties
;
import
org.h2.jdbc.JdbcStatement
;
import
org.h2.test.TestBase
;
...
...
@@ -101,36 +102,24 @@ public class TestStatement extends TestBase {
stat
.
execute
(
"INSERT INTO TEST VALUES(0, 'Hi')"
);
Savepoint
savepoint1
=
conn
.
setSavepoint
();
int
id1
=
savepoint1
.
getSavepointId
();
try
{
savepoint1
.
getSavepointName
();
fail
();
}
catch
(
SQLException
e
)
{
assertKnownException
(
e
);
}
assertThrows
(
ErrorCode
.
SAVEPOINT_IS_UNNAMED
,
savepoint1
).
getSavepointName
();
stat
.
execute
(
"DELETE FROM TEST"
);
conn
.
rollback
(
savepoint1
);
stat
.
execute
(
"UPDATE TEST SET NAME='Hello'"
);
Savepoint
savepoint2a
=
conn
.
setSavepoint
();
Savepoint
savepoint2
=
conn
.
setSavepoint
();
conn
.
releaseSavepoint
(
savepoint2a
);
try
{
savepoint2a
.
getSavepointId
();
fail
();
}
catch
(
SQLException
e
)
{
assertKnownException
(
e
);
}
assertThrows
(
ErrorCode
.
SAVEPOINT_IS_INVALID_1
,
savepoint2a
).
getSavepointId
();
int
id2
=
savepoint2
.
getSavepointId
();
assertTrue
(
id1
!=
id2
);
stat
.
execute
(
"UPDATE TEST SET NAME='Hallo' WHERE NAME='Hello'"
);
Savepoint
savepointTest
=
conn
.
setSavepoint
(
"Joe's"
);
stat
.
execute
(
"DELETE FROM TEST"
);
assertEquals
(
savepointTest
.
getSavepointName
(),
"Joe's"
);
try
{
savepointTest
.
getSavepointId
();
fail
();
}
catch
(
SQLException
e
)
{
assertKnownException
(
e
);
}
assertThrows
(
ErrorCode
.
SAVEPOINT_IS_NAMED
,
savepointTest
).
getSavepointId
();
conn
.
rollback
(
savepointTest
);
conn
.
commit
();
ResultSet
rs
=
stat
.
executeQuery
(
"SELECT NAME FROM TEST"
);
...
...
@@ -138,12 +127,8 @@ public class TestStatement extends TestBase {
String
name
=
rs
.
getString
(
1
);
assertEquals
(
name
,
"Hallo"
);
assertFalse
(
rs
.
next
());
try
{
conn
.
rollback
(
savepoint2
);
fail
();
}
catch
(
SQLException
e
)
{
assertKnownException
(
e
);
}
assertThrows
(
ErrorCode
.
SAVEPOINT_IS_INVALID_1
,
conn
).
rollback
(
savepoint2
);
stat
.
execute
(
"DROP TABLE TEST"
);
conn
.
setAutoCommit
(
true
);
}
...
...
@@ -209,13 +194,7 @@ public class TestStatement extends TestBase {
assertTrue
(
stat
.
getQueryTimeout
()
==
10
);
stat
.
setQueryTimeout
(
0
);
assertTrue
(
stat
.
getQueryTimeout
()
==
0
);
// this is supposed to throw an exception
try
{
stat
.
setQueryTimeout
(-
1
);
fail
(
"setQueryTimeout(-1) didn't throw an exception"
);
}
catch
(
SQLException
e
)
{
assertKnownException
(
e
);
}
assertThrows
(
ErrorCode
.
INVALID_VALUE_2
,
stat
).
setQueryTimeout
(-
1
);
assertTrue
(
stat
.
getQueryTimeout
()
==
0
);
trace
(
"executeUpdate"
);
count
=
stat
.
executeUpdate
(
"CREATE TABLE TEST(ID INT PRIMARY KEY,VALUE VARCHAR(255))"
);
...
...
@@ -235,13 +214,10 @@ public class TestStatement extends TestBase {
assertEquals
(
0
,
count
);
count
=
stat
.
executeUpdate
(
"DELETE FROM TEST WHERE ID=2"
);
assertEquals
(
1
,
count
);
try
{
stat
.
executeUpdate
(
"SELECT * FROM TEST"
);
fail
(
"executeUpdate allowed SELECT"
);
}
catch
(
SQLException
e
)
{
assertKnownException
(
e
);
trace
(
"no error - SELECT not allowed with executeUpdate"
);
}
assertThrows
(
ErrorCode
.
METHOD_NOT_ALLOWED_FOR_QUERY
,
stat
).
executeUpdate
(
"SELECT * FROM TEST"
);
count
=
stat
.
executeUpdate
(
"DROP TABLE TEST"
);
assertTrue
(
count
==
0
);
...
...
@@ -261,55 +237,29 @@ public class TestStatement extends TestBase {
result
=
stat
.
execute
(
"DROP TABLE TEST"
);
assertTrue
(!
result
);
trace
(
"executeQuery"
);
try
{
stat
.
executeQuery
(
"CREATE TABLE TEST(ID INT PRIMARY KEY,VALUE VARCHAR(255))"
);
fail
(
"executeQuery allowed CREATE TABLE"
);
}
catch
(
SQLException
e
)
{
assertKnownException
(
e
);
trace
(
"no error - CREATE not allowed with executeQuery"
);
}
assertThrows
(
ErrorCode
.
METHOD_ONLY_ALLOWED_FOR_QUERY
,
stat
).
executeQuery
(
"CREATE TABLE TEST(ID INT PRIMARY KEY,VALUE VARCHAR(255))"
);
stat
.
execute
(
"CREATE TABLE TEST(ID INT PRIMARY KEY,VALUE VARCHAR(255))"
);
try
{
stat
.
executeQuery
(
"INSERT INTO TEST VALUES(1,'Hello')"
);
fail
(
"executeQuery allowed INSERT"
);
}
catch
(
SQLException
e
)
{
assertKnownException
(
e
);
trace
(
"no error - INSERT not allowed with executeQuery"
);
}
try
{
stat
.
executeQuery
(
"UPDATE TEST SET VALUE='LDBC' WHERE ID=2"
);
fail
(
"executeQuery allowed UPDATE"
);
}
catch
(
SQLException
e
)
{
assertKnownException
(
e
);
trace
(
"no error - UPDATE not allowed with executeQuery"
);
}
try
{
stat
.
executeQuery
(
"DELETE FROM TEST WHERE ID=3"
);
fail
(
"executeQuery allowed DELETE"
);
}
catch
(
SQLException
e
)
{
assertKnownException
(
e
);
trace
(
"no error - DELETE not allowed with executeQuery"
);
}
assertThrows
(
ErrorCode
.
METHOD_ONLY_ALLOWED_FOR_QUERY
,
stat
).
executeQuery
(
"INSERT INTO TEST VALUES(1,'Hello')"
);
assertThrows
(
ErrorCode
.
METHOD_ONLY_ALLOWED_FOR_QUERY
,
stat
).
executeQuery
(
"UPDATE TEST SET VALUE='LDBC' WHERE ID=2"
);
assertThrows
(
ErrorCode
.
METHOD_ONLY_ALLOWED_FOR_QUERY
,
stat
).
executeQuery
(
"DELETE FROM TEST WHERE ID=3"
);
stat
.
executeQuery
(
"SELECT * FROM TEST"
);
try
{
stat
.
executeQuery
(
"DROP TABLE TEST"
);
fail
(
"executeQuery allowed DROP"
);
}
catch
(
SQLException
e
)
{
assertKnownException
(
e
);
trace
(
"no error - DROP not allowed with executeQuery"
);
}
assertThrows
(
ErrorCode
.
METHOD_ONLY_ALLOWED_FOR_QUERY
,
stat
).
executeQuery
(
"DROP TABLE TEST"
);
// getMoreResults
rs
=
stat
.
executeQuery
(
"SELECT * FROM TEST"
);
assertFalse
(
stat
.
getMoreResults
());
try
{
// supposed to be closed now
rs
.
next
();
fail
(
"getMoreResults didn't close this result set"
);
}
catch
(
SQLException
e
)
{
assertKnownException
(
e
);
trace
(
"no error - getMoreResults is supposed to close the result set"
);
}
assertThrows
(
ErrorCode
.
OBJECT_CLOSED
,
rs
).
next
();
assertTrue
(
stat
.
getUpdateCount
()
==
-
1
);
count
=
stat
.
executeUpdate
(
"DELETE FROM TEST"
);
assertFalse
(
stat
.
getMoreResults
());
...
...
This diff is collapsed.
Click to expand it.
h2/src/test/org/h2/test/jdbc/TestTransactionIsolation.java
浏览文件 @
b0d2049a
...
...
@@ -9,6 +9,7 @@ package org.h2.test.jdbc;
import
java.sql.Connection
;
import
java.sql.SQLException
;
import
org.h2.constant.ErrorCode
;
import
org.h2.test.TestBase
;
/**
...
...
@@ -66,12 +67,8 @@ public class TestTransactionIsolation extends TestBase {
// serializable: write lock
conn1
.
createStatement
().
executeUpdate
(
"UPDATE TEST SET ID=2"
);
try
{
assertSingleValue
(
conn2
.
createStatement
(),
"SELECT * FROM TEST"
,
1
);
fail
(
"Expected lock timeout"
);
}
catch
(
SQLException
e
)
{
assertKnownException
(
e
);
}
assertThrows
(
ErrorCode
.
LOCK_TIMEOUT_1
,
conn2
.
createStatement
()).
executeQuery
(
"SELECT * FROM TEST"
);
conn1
.
commit
();
conn2
.
commit
();
...
...
@@ -88,12 +85,8 @@ public class TestTransactionIsolation extends TestBase {
assertSingleValue
(
conn1
.
createStatement
(),
"SELECT * FROM TEST"
,
3
);
assertSingleValue
(
conn2
.
createStatement
(),
"SELECT * FROM TEST"
,
3
);
conn2
.
createStatement
().
executeUpdate
(
"UPDATE TEST SET ID=4"
);
try
{
conn1
.
createStatement
().
executeUpdate
(
"DELETE FROM TEST"
);
fail
(
"Expected lock timeout"
);
}
catch
(
SQLException
e
)
{
assertKnownException
(
e
);
}
assertThrows
(
ErrorCode
.
LOCK_TIMEOUT_1
,
conn1
.
createStatement
()).
executeUpdate
(
"DELETE FROM TEST"
);
conn2
.
commit
();
conn1
.
commit
();
assertSingleValue
(
conn1
.
createStatement
(),
"SELECT * FROM TEST"
,
4
);
...
...
This diff is collapsed.
Click to expand it.
h2/src/test/org/h2/test/jdbc/TestUpdatableResultSet.java
浏览文件 @
b0d2049a
...
...
@@ -20,6 +20,7 @@ import java.sql.Time;
import
java.sql.Timestamp
;
import
java.sql.Types
;
import
org.h2.constant.ErrorCode
;
import
org.h2.constant.SysProperties
;
import
org.h2.test.TestBase
;
...
...
@@ -187,14 +188,7 @@ public class TestUpdatableResultSet extends TestBase {
assertEquals
(
1
,
rs
.
getRow
());
rs
.
next
();
try
{
rs
.
insertRow
();
fail
();
}
catch
(
SQLException
e
)
{
assertKnownException
(
e
);
}
assertThrows
(
ErrorCode
.
RESULT_SET_READONLY
,
rs
).
insertRow
();
assertFalse
(
rs
.
isBeforeFirst
());
assertFalse
(
rs
.
isAfterLast
());
assertEquals
(
2
,
rs
.
getInt
(
1
));
...
...
@@ -246,13 +240,8 @@ public class TestUpdatableResultSet extends TestBase {
assertFalse
(
rs
.
absolute
(
4
));
assertEquals
(
0
,
rs
.
getRow
());
try
{
// allowed for compatibility
assertFalse
(
rs
.
absolute
(
0
));
// actually, we allow it for compatibility
// error("absolute 0 not allowed");
}
catch
(
SQLException
e
)
{
assertKnownException
(
e
);
}
assertTrue
(
rs
.
absolute
(
3
));
assertEquals
(
3
,
rs
.
getRow
());
...
...
This diff is collapsed.
Click to expand it.
h2/src/test/org/h2/test/jdbc/TestZloty.java
浏览文件 @
b0d2049a
...
...
@@ -12,6 +12,7 @@ import java.sql.PreparedStatement;
import
java.sql.ResultSet
;
import
java.sql.SQLException
;
import
org.h2.constant.ErrorCode
;
import
org.h2.test.TestBase
;
/**
...
...
@@ -92,16 +93,10 @@ public class TestZloty extends TestBase {
prep
.
setBigDecimal
(
2
,
new
BigDecimal
(
"10.0"
));
prep
.
execute
();
prep
.
setInt
(
1
,
2
);
try
{
prep
.
setBigDecimal
(
2
,
new
ZlotyBigDecimal
(
"11.0"
));
prep
.
execute
();
fail
();
}
catch
(
SQLException
e
)
{
assertKnownException
(
e
);
}
assertThrows
(
ErrorCode
.
INVALID_CLASS_2
,
prep
).
setBigDecimal
(
2
,
new
ZlotyBigDecimal
(
"11.0"
));
prep
.
setInt
(
1
,
3
);
try
{
BigDecimal
value
=
new
BigDecimal
(
"12.100000"
)
{
private
static
final
long
serialVersionUID
=
1L
;
...
...
@@ -110,12 +105,8 @@ public class TestZloty extends TestBase {
return
"12,100000 EURO"
;
}
};
prep
.
setBigDecimal
(
2
,
value
);
prep
.
execute
();
fail
();
}
catch
(
SQLException
e
)
{
assertKnownException
(
e
);
}
assertThrows
(
ErrorCode
.
INVALID_CLASS_2
,
prep
).
setBigDecimal
(
2
,
value
);
conn
.
close
();
}
...
...
This diff is collapsed.
Click to expand it.
h2/src/test/org/h2/test/jdbcx/TestConnectionPool.java
浏览文件 @
b0d2049a
...
...
@@ -12,6 +12,7 @@ import java.sql.Connection;
import
java.sql.DriverManager
;
import
java.sql.SQLException
;
import
java.sql.Statement
;
import
javax.sql.DataSource
;
import
org.h2.jdbcx.JdbcConnectionPool
;
import
org.h2.jdbcx.JdbcDataSource
;
...
...
@@ -231,18 +232,11 @@ public class TestConnectionPool extends TestBase {
conn
.
close
();
}
pool
.
dispose
();
try
{
pool
.
getConnection
();
fail
();
}
catch
(
IllegalStateException
e
)
{
// expected
}
try
{
pool
.
getConnection
(
null
,
null
);
fail
();
}
catch
(
UnsupportedOperationException
e
)
{
// expected
}
DataSource
ds
=
pool
;
assertThrows
(
IllegalStateException
.
class
,
ds
).
getConnection
();
assertThrows
(
UnsupportedOperationException
.
class
,
ds
).
getConnection
(
null
,
null
);
}
}
This diff is collapsed.
Click to expand it.
h2/src/test/org/h2/test/mvcc/TestMvcc1.java
浏览文件 @
b0d2049a
...
...
@@ -30,7 +30,9 @@ public class TestMvcc1 extends TestBase {
* @param a ignored
*/
public
static
void
main
(
String
...
a
)
throws
Exception
{
TestBase
.
createCaller
().
init
().
test
();
TestBase
test
=
TestBase
.
createCaller
().
init
();
test
.
config
.
mvcc
=
true
;
test
.
test
();
}
public
void
test
()
throws
SQLException
{
...
...
@@ -46,12 +48,8 @@ public class TestMvcc1 extends TestBase {
ResultSet
rs
=
stat
.
executeQuery
(
"select * from information_schema.settings where name='MVCC'"
);
rs
.
next
();
assertEquals
(
"FALSE"
,
rs
.
getString
(
"VALUE"
));
try
{
stat
.
execute
(
"SET MVCC TRUE"
);
fail
();
}
catch
(
SQLException
e
)
{
assertEquals
(
ErrorCode
.
CANNOT_CHANGE_SETTING_WHEN_OPEN_1
,
e
.
getErrorCode
());
}
assertThrows
(
ErrorCode
.
CANNOT_CHANGE_SETTING_WHEN_OPEN_1
,
stat
).
execute
(
"SET MVCC TRUE"
);
rs
=
stat
.
executeQuery
(
"select * from information_schema.settings where name='MVCC'"
);
rs
.
next
();
assertEquals
(
"FALSE"
,
rs
.
getString
(
"VALUE"
));
...
...
@@ -85,12 +83,8 @@ public class TestMvcc1 extends TestBase {
c2
.
setAutoCommit
(
false
);
// table rollback problem
try
{
s1
.
execute
(
"create table b(primary key(x))"
);
fail
();
}
catch
(
SQLException
e
)
{
// ok
}
assertThrows
(
ErrorCode
.
COLUMN_NOT_FOUND_1
,
s1
).
execute
(
"create table b(primary key(x))"
);
s1
.
execute
(
"create table a(id int as 1 unique)"
);
s1
.
execute
(
"drop table a"
);
...
...
@@ -112,12 +106,8 @@ public class TestMvcc1 extends TestBase {
s1
.
execute
(
"create table b (name varchar(100) not null, a integer, "
+
"primary key(name), foreign key(a) references a(id))"
);
s1
.
execute
(
"insert into a(code) values('one')"
);
try
{
s2
.
execute
(
"insert into b values('un B', 1)"
);
fail
();
}
catch
(
SQLException
e
)
{
assertKnownException
(
e
);
}
assertThrows
(
ErrorCode
.
REFERENTIAL_INTEGRITY_VIOLATED_PARENT_MISSING_1
,
s2
).
execute
(
"insert into b values('un B', 1)"
);
c2
.
commit
();
c1
.
rollback
();
s1
.
execute
(
"drop table a, b"
);
...
...
@@ -127,13 +117,8 @@ public class TestMvcc1 extends TestBase {
// when an uncommitted transaction changed something
s1
.
execute
(
"create table test(id int primary key)"
);
s1
.
execute
(
"insert into test values(1)"
);
try
{
s2
.
execute
(
"drop table test"
);
fail
();
}
catch
(
SQLException
e
)
{
// lock timeout expected
assertKnownException
(
e
);
}
assertThrows
(
ErrorCode
.
LOCK_TIMEOUT_1
,
s2
).
execute
(
"drop table test"
);
c1
.
rollback
();
s2
.
execute
(
"drop table test"
);
c2
.
rollback
();
...
...
@@ -154,13 +139,8 @@ public class TestMvcc1 extends TestBase {
s1
.
execute
(
"insert into test values(1, 'y')"
);
c1
.
commit
();
s2
.
execute
(
"select * from test where id = 1 for update"
);
try
{
s1
.
execute
(
"delete from test"
);
fail
();
}
catch
(
SQLException
e
)
{
// lock timeout expected
assertKnownException
(
e
);
}
assertThrows
(
ErrorCode
.
LOCK_TIMEOUT_1
,
s1
).
execute
(
"delete from test"
);
c2
.
rollback
();
s1
.
execute
(
"drop table test"
);
c1
.
commit
();
...
...
@@ -384,12 +364,8 @@ public class TestMvcc1 extends TestBase {
s1
.
execute
(
"create table test(id int primary key, name varchar(255))"
);
s1
.
execute
(
"insert into test values(1, 'Hello'), (2, 'World')"
);
c1
.
commit
();
try
{
s1
.
execute
(
"update test set id=2 where id=1"
);
fail
();
}
catch
(
SQLException
e
)
{
assertKnownException
(
e
);
}
assertThrows
(
ErrorCode
.
DUPLICATE_KEY_1
,
s1
).
execute
(
"update test set id=2 where id=1"
);
rs
=
s1
.
executeQuery
(
"select * from test order by id"
);
assertTrue
(
rs
.
next
());
assertEquals
(
1
,
rs
.
getInt
(
1
));
...
...
This diff is collapsed.
Click to expand it.
h2/src/test/org/h2/test/mvcc/TestMvcc2.java
浏览文件 @
b0d2049a
...
...
@@ -130,39 +130,19 @@ public class TestMvcc2 extends TestBase {
stat
.
execute
(
"insert into test select x, 'Hello' from system_range(1, 10)"
);
stat
.
execute
(
"select * from test where id = 3 for update"
);
conn
.
commit
();
try
{
stat
.
execute
(
"select sum(id) from test for update"
);
fail
();
}
catch
(
SQLException
e
)
{
assertEquals
(
ErrorCode
.
FEATURE_NOT_SUPPORTED_1
,
e
.
getErrorCode
());
}
try
{
stat
.
execute
(
"select distinct id from test for update"
);
fail
();
}
catch
(
SQLException
e
)
{
assertEquals
(
ErrorCode
.
FEATURE_NOT_SUPPORTED_1
,
e
.
getErrorCode
());
}
try
{
stat
.
execute
(
"select id from test group by id for update"
);
fail
();
}
catch
(
SQLException
e
)
{
assertEquals
(
ErrorCode
.
FEATURE_NOT_SUPPORTED_1
,
e
.
getErrorCode
());
}
try
{
stat
.
execute
(
"select t1.id from test t1, test t2 for update"
);
fail
();
}
catch
(
SQLException
e
)
{
assertEquals
(
ErrorCode
.
FEATURE_NOT_SUPPORTED_1
,
e
.
getErrorCode
());
}
assertThrows
(
ErrorCode
.
FEATURE_NOT_SUPPORTED_1
,
stat
).
execute
(
"select sum(id) from test for update"
);
assertThrows
(
ErrorCode
.
FEATURE_NOT_SUPPORTED_1
,
stat
).
execute
(
"select distinct id from test for update"
);
assertThrows
(
ErrorCode
.
FEATURE_NOT_SUPPORTED_1
,
stat
).
execute
(
"select id from test group by id for update"
);
assertThrows
(
ErrorCode
.
FEATURE_NOT_SUPPORTED_1
,
stat
).
execute
(
"select t1.id from test t1, test t2 for update"
);
stat
.
execute
(
"select * from test where id = 3 for update"
);
conn2
.
setAutoCommit
(
false
);
conn2
.
createStatement
().
execute
(
"select * from test where id = 4 for update"
);
try
{
conn2
.
createStatement
().
execute
(
"select * from test where id = 3 for update"
);
fail
();
}
catch
(
SQLException
e
)
{
assertEquals
(
ErrorCode
.
LOCK_TIMEOUT_1
,
e
.
getErrorCode
());
}
assertThrows
(
ErrorCode
.
LOCK_TIMEOUT_1
,
conn2
.
createStatement
()).
execute
(
"select * from test where id = 3 for update"
);
conn
.
close
();
}
...
...
This diff is collapsed.
Click to expand it.
h2/src/test/org/h2/test/mvcc/TestMvccMultiThreaded.java
浏览文件 @
b0d2049a
...
...
@@ -8,7 +8,6 @@ package org.h2.test.mvcc;
import
java.sql.Connection
;
import
java.sql.ResultSet
;
import
java.sql.SQLException
;
import
java.sql.Statement
;
import
java.util.concurrent.CountDownLatch
;
...
...
@@ -44,12 +43,8 @@ public class TestMvccMultiThreaded extends TestBase {
Statement
stat
=
conn
.
createStatement
();
stat
.
execute
(
"create table test(x int primary key, y int unique)"
);
stat
.
execute
(
"insert into test values(1, 1)"
);
try
{
stat
.
execute
(
"merge into test values(2, 1)"
);
fail
();
}
catch
(
SQLException
e
)
{
assertEquals
(
ErrorCode
.
DUPLICATE_KEY_1
,
e
.
getErrorCode
());
}
assertThrows
(
ErrorCode
.
DUPLICATE_KEY_1
,
stat
).
execute
(
"merge into test values(2, 1)"
);
stat
.
execute
(
"merge into test values(1, 2)"
);
conn
.
close
();
...
...
This diff is collapsed.
Click to expand it.
h2/src/test/org/h2/test/rowlock/TestRowLocks.java
浏览文件 @
b0d2049a
...
...
@@ -11,6 +11,7 @@ import java.sql.ResultSet;
import
java.sql.SQLException
;
import
java.sql.Statement
;
import
org.h2.constant.ErrorCode
;
import
org.h2.test.TestBase
;
import
org.h2.util.Task
;
...
...
@@ -70,12 +71,8 @@ public class TestRowLocks extends TestBase {
assertEquals
(
"Hello"
,
getSingleValue
(
s2
,
"SELECT NAME FROM TEST WHERE ID=1"
));
s2
.
execute
(
"UPDATE TEST SET NAME='Hallo' WHERE ID=2"
);
try
{
s2
.
executeUpdate
(
"UPDATE TEST SET NAME='Hi' WHERE ID=1"
);
fail
();
}
catch
(
SQLException
e
)
{
assertKnownException
(
e
);
}
assertThrows
(
ErrorCode
.
LOCK_TIMEOUT_1
,
s2
).
executeUpdate
(
"UPDATE TEST SET NAME='Hi' WHERE ID=1"
);
c1
.
commit
();
c2
.
commit
();
...
...
This diff is collapsed.
Click to expand it.
h2/src/test/org/h2/test/server/TestNestedLoop.java
浏览文件 @
b0d2049a
...
...
@@ -11,6 +11,7 @@ import java.sql.ResultSet;
import
java.sql.SQLException
;
import
java.sql.Statement
;
import
org.h2.constant.ErrorCode
;
import
org.h2.test.TestBase
;
/**
...
...
@@ -39,20 +40,10 @@ public class TestNestedLoop extends TestBase {
}
ResultSet
rs
=
stat
.
executeQuery
(
"select id from test"
);
stat
.
executeQuery
(
"select id from test"
);
try
{
rs
.
next
();
fail
(
"Result set should be closed"
);
}
catch
(
SQLException
e
)
{
assertKnownException
(
e
);
}
assertThrows
(
ErrorCode
.
OBJECT_CLOSED
,
rs
).
next
();
rs
=
stat
.
executeQuery
(
"select id from test"
);
stat
.
close
();
try
{
rs
.
next
();
fail
(
"Result set should be closed"
);
}
catch
(
SQLException
e
)
{
assertKnownException
(
e
);
}
assertThrows
(
ErrorCode
.
OBJECT_CLOSED
,
rs
).
next
();
stat
=
conn
.
createStatement
();
rs
=
stat
.
executeQuery
(
"select id from test"
);
Statement
stat2
=
conn
.
createStatement
();
...
...
This diff is collapsed.
Click to expand it.
h2/src/test/org/h2/test/synth/TestNestedJoins.java
浏览文件 @
b0d2049a
...
...
@@ -241,16 +241,11 @@ public class TestNestedJoins extends TestBase {
ResultSet
rs
;
String
sql
;
// Issue 288
try
{
stat
.
execute
(
"select 1 from dual a right outer join (select b.x from dual b) c on unknown.x = c.x, dual d"
);
fail
();
}
catch
(
SQLException
e
)
{
// this threw a NullPointerException
assertEquals
(
ErrorCode
.
COLUMN_NOT_FOUND_1
,
e
.
getErrorCode
());
}
// issue 288
assertThrows
(
ErrorCode
.
COLUMN_NOT_FOUND_1
,
stat
).
execute
(
"select 1 from dual a right outer join (select b.x from dual b) c on unknown.x = c.x, dual d"
);
//
I
ssue 288
//
i
ssue 288
stat
.
execute
(
"create table test(id int primary key)"
);
stat
.
execute
(
"insert into test values(1)"
);
// this threw the exception Column "T.ID" must be in the GROUP BY list
...
...
@@ -258,14 +253,14 @@ public class TestNestedJoins extends TestBase {
"(select t2.id, count(*) c from test t2 group by t2.id) x on x.id = t.id "
+
"where t.id = 1"
);
//
T
he query plan of queries with subqueries
//
t
he query plan of queries with subqueries
// that contain nested joins was wrong
stat
.
execute
(
"select 1 from (select 2 from ((test t1 inner join test t2 "
+
"on t1.id=t2.id) inner join test t3 on t3.id=t1.id)) x"
);
stat
.
execute
(
"drop table test"
);
//
I
ssue 288
//
i
ssue 288
/*
create table test(id int);
select 1 from test a right outer join test b on a.id = 1, test c;
...
...
@@ -319,7 +314,7 @@ public class TestNestedJoins extends TestBase {
"test b on a.id=b.id left outer join o on o.id=a.id where b.x=1"
);
assertTrue
(
rs
.
next
());
sql
=
rs
.
getString
(
1
);
// TODO
S
upport optimizing queries with both inner and outer joins
// TODO
s
upport optimizing queries with both inner and outer joins
// assertTrue("using table scan", sql.indexOf("tableScan") < 0);
stat
.
execute
(
"drop table test"
);
stat
.
execute
(
"drop table o"
);
...
...
This diff is collapsed.
Click to expand it.
h2/src/test/org/h2/test/unit/TestAutoReconnect.java
浏览文件 @
b0d2049a
...
...
@@ -176,12 +176,8 @@ public class TestAutoReconnect extends TestBase implements DatabaseEventListener
conn
.
setAutoCommit
(
false
);
restart
();
try
{
conn
.
createStatement
().
execute
(
"select * from test"
);
fail
();
}
catch
(
SQLException
e
)
{
assertKnownException
(
e
);
}
assertThrows
(
ErrorCode
.
CONNECTION_BROKEN_1
,
conn
.
createStatement
()).
execute
(
"select * from test"
);
conn
.
close
();
if
(
autoServer
)
{
...
...
This diff is collapsed.
Click to expand it.
h2/src/test/org/h2/test/unit/TestCollation.java
浏览文件 @
b0d2049a
...
...
@@ -7,7 +7,6 @@
package
org
.
h2
.
test
.
unit
;
import
java.sql.Connection
;
import
java.sql.SQLException
;
import
java.sql.Statement
;
import
org.h2.constant.ErrorCode
;
import
org.h2.test.TestBase
;
...
...
@@ -30,19 +29,12 @@ public class TestCollation extends TestBase {
deleteDb
(
"collation"
);
Connection
conn
=
getConnection
(
"collation"
);
Statement
stat
=
conn
.
createStatement
();
try
{
stat
.
execute
(
"set collation xyz"
);
fail
();
}
catch
(
SQLException
e
)
{
assertEquals
(
ErrorCode
.
INVALID_VALUE_2
,
e
.
getErrorCode
());
}
assertThrows
(
ErrorCode
.
INVALID_VALUE_2
,
stat
).
execute
(
"set collation xyz"
);
stat
.
execute
(
"set collation en"
);
stat
.
execute
(
"set collation default_en"
);
try
{
stat
.
execute
(
"set collation icu4j_en"
);
}
catch
(
SQLException
e
)
{
assertEquals
(
ErrorCode
.
CLASS_NOT_FOUND_1
,
e
.
getErrorCode
());
}
assertThrows
(
ErrorCode
.
CLASS_NOT_FOUND_1
,
stat
).
execute
(
"set collation icu4j_en"
);
conn
.
close
();
deleteDb
(
"collation"
);
}
...
...
This diff is collapsed.
Click to expand it.
h2/src/test/org/h2/test/unit/TestFileLockSerialized.java
浏览文件 @
b0d2049a
...
...
@@ -15,6 +15,7 @@ import java.sql.SQLException;
import
java.sql.Statement
;
import
java.util.Arrays
;
import
java.util.List
;
import
org.h2.constant.ErrorCode
;
import
org.h2.jdbc.JdbcConnection
;
import
org.h2.store.fs.FileSystem
;
import
org.h2.test.TestBase
;
...
...
@@ -225,12 +226,8 @@ public class TestFileLockSerialized extends TestBase {
Statement
stat
=
conn
.
createStatement
();
stat
.
execute
(
"create table test(id int primary key)"
);
((
JdbcConnection
)
conn
).
setPowerOffCount
(
1
);
try
{
stat
.
execute
(
"insert into test values(1)"
);
fail
();
}
catch
(
SQLException
e
)
{
// ignore
}
assertThrows
(
ErrorCode
.
DATABASE_IS_CLOSED
,
stat
).
execute
(
"insert into test values(1)"
);
Connection
conn2
=
DriverManager
.
getConnection
(
writeUrl
,
"sa"
,
"sa"
);
Statement
stat2
=
conn2
.
createStatement
();
...
...
@@ -239,11 +236,7 @@ public class TestFileLockSerialized extends TestBase {
conn2
.
close
();
try
{
conn
.
close
();
}
catch
(
SQLException
e
)
{
// ignore
}
assertThrows
(
ErrorCode
.
DATABASE_IS_CLOSED
,
conn
).
close
();
}
private
void
testConcurrentReadWrite
()
throws
Exception
{
...
...
This diff is collapsed.
Click to expand it.
h2/src/test/org/h2/test/unit/TestFileSystem.java
浏览文件 @
b0d2049a
...
...
@@ -220,12 +220,7 @@ public class TestFileSystem extends TestBase {
assertEquals
(
10000
,
fo
.
length
());
fo
.
seek
(
20000
);
assertEquals
(
20000
,
fo
.
getFilePointer
());
try
{
fo
.
readFully
(
buffer
,
0
,
1
);
fail
();
}
catch
(
EOFException
e
)
{
// expected
}
assertThrows
(
EOFException
.
class
,
fo
).
readFully
(
buffer
,
0
,
1
);
assertEquals
(
fsBase
+
"/test"
,
fo
.
getName
().
replace
(
'\\'
,
'/'
));
assertEquals
(
"test"
,
fs
.
getFileName
(
fo
.
getName
()));
assertEquals
(
fsBase
,
fs
.
getParent
(
fo
.
getName
()).
replace
(
'\\'
,
'/'
));
...
...
@@ -238,18 +233,8 @@ public class TestFileSystem extends TestBase {
byte
[]
test
=
new
byte
[
10000
];
fo
.
readFully
(
test
,
0
,
10000
);
assertEquals
(
buffer
,
test
);
try
{
fo
.
write
(
test
,
0
,
10
);
fail
();
}
catch
(
IOException
e
)
{
// expected
}
try
{
fo
.
setFileLength
(
10
);
fail
();
}
catch
(
IOException
e
)
{
// expected
}
assertThrows
(
IOException
.
class
,
fo
).
write
(
test
,
0
,
10
);
assertThrows
(
IOException
.
class
,
fo
).
setFileLength
(
10
);
fo
.
close
();
long
lastMod
=
fs
.
getLastModified
(
fsBase
+
"/test"
);
if
(
lastMod
<
time
-
1999
)
{
...
...
@@ -305,12 +290,7 @@ public class TestFileSystem extends TestBase {
RandomAccessFile
ra
=
new
RandomAccessFile
(
file
,
"rw"
);
fs
.
delete
(
s
);
FileObject
f
=
fs
.
openFileObject
(
s
,
"rw"
);
try
{
f
.
readFully
(
new
byte
[
1
],
0
,
1
);
fail
();
}
catch
(
EOFException
e
)
{
// expected
}
assertThrows
(
EOFException
.
class
,
f
).
readFully
(
new
byte
[
1
],
0
,
1
);
f
.
sync
();
Random
random
=
new
Random
(
seed
);
int
size
=
getSize
(
100
,
500
);
...
...
This diff is collapsed.
Click to expand it.
h2/src/test/org/h2/test/unit/TestOldVersion.java
浏览文件 @
b0d2049a
...
...
@@ -108,11 +108,8 @@ public class TestOldVersion extends TestBase {
private
void
testOldClientNewServer
()
throws
Exception
{
Server
server
=
org
.
h2
.
tools
.
Server
.
createTcpServer
(
"-tcpPort"
,
"9001"
);
server
.
start
();
try
{
driver
.
connect
(
"jdbc:h2:tcp://localhost:9001/mem:test"
,
null
);
}
catch
(
SQLException
e
)
{
assertEquals
(
ErrorCode
.
DRIVER_VERSION_ERROR_2
,
e
.
getErrorCode
());
}
assertThrows
(
ErrorCode
.
DRIVER_VERSION_ERROR_2
,
driver
).
connect
(
"jdbc:h2:tcp://localhost:9001/mem:test"
,
null
);
server
.
stop
();
Class
<?>
serverClass
=
cl
.
loadClass
(
"org.h2.tools.Server"
);
...
...
This diff is collapsed.
Click to expand it.
h2/src/test/org/h2/test/unit/TestPageStore.java
浏览文件 @
b0d2049a
...
...
@@ -17,6 +17,7 @@ import java.util.Random;
import
java.util.Set
;
import
java.util.TreeSet
;
import
org.h2.api.DatabaseEventListener
;
import
org.h2.constant.ErrorCode
;
import
org.h2.result.Row
;
import
org.h2.store.Page
;
import
org.h2.test.TestBase
;
...
...
@@ -269,18 +270,8 @@ public class TestPageStore extends TestBase implements DatabaseEventListener {
Statement
stat2
=
conn2
.
createStatement
();
stat2
.
execute
(
"create table test2 as select x from system_range(1, 5000)"
);
stat2
.
execute
(
"shutdown immediately"
);
try
{
conn
.
close
();
fail
();
}
catch
(
SQLException
e
)
{
assertKnownException
(
e
);
}
try
{
conn2
.
close
();
fail
();
}
catch
(
SQLException
e
)
{
assertKnownException
(
e
);
}
assertThrows
(
ErrorCode
.
DATABASE_IS_CLOSED
,
conn
).
close
();
assertThrows
(
ErrorCode
.
DATABASE_IS_CLOSED
,
conn2
).
close
();
}
private
void
testDuplicateKey
()
throws
SQLException
{
...
...
@@ -443,12 +434,8 @@ public class TestPageStore extends TestBase implements DatabaseEventListener {
conn
.
createStatement
().
execute
(
"INSERT INTO TEST VALUES(1, 'Hello')"
);
conn
.
close
();
conn
=
getConnection
(
url
);
try
{
conn
.
createStatement
().
execute
(
"INSERT INTO TEST VALUES(2, 'Hello')"
);
fail
();
}
catch
(
SQLException
e
)
{
assertKnownException
(
e
);
}
assertThrows
(
ErrorCode
.
DUPLICATE_KEY_1
,
conn
.
createStatement
()).
execute
(
"INSERT INTO TEST VALUES(2, 'Hello')"
);
conn
.
close
();
}
...
...
@@ -665,12 +652,8 @@ public class TestPageStore extends TestBase implements DatabaseEventListener {
stat
.
execute
(
"INSERT INTO TEST VALUES(1)"
);
conn
.
close
();
conn
=
getConnection
(
"pageStore"
);
try
{
conn
.
createStatement
().
execute
(
"INSERT INTO TEST VALUES(1)"
);
fail
();
}
catch
(
SQLException
e
)
{
assertKnownException
(
e
);
}
assertThrows
(
ErrorCode
.
DUPLICATE_KEY_1
,
conn
.
createStatement
()).
execute
(
"INSERT INTO TEST VALUES(1)"
);
conn
.
close
();
}
...
...
@@ -683,11 +666,7 @@ public class TestPageStore extends TestBase implements DatabaseEventListener {
stat
.
execute
(
"INSERT INTO TEST SELECT X FROM SYSTEM_RANGE(20, 100)"
);
stat
.
execute
(
"INSERT INTO TEST SELECT X FROM SYSTEM_RANGE(1000, 1100)"
);
stat
.
execute
(
"SHUTDOWN IMMEDIATELY"
);
try
{
conn
.
close
();
}
catch
(
SQLException
e
)
{
// ignore
}
assertThrows
(
ErrorCode
.
DATABASE_IS_CLOSED
,
conn
).
close
();
conn
=
getConnection
(
"pageStore"
);
conn
.
close
();
}
...
...
This diff is collapsed.
Click to expand it.
h2/src/test/org/h2/test/unit/TestPageStoreCoverage.java
浏览文件 @
b0d2049a
...
...
@@ -10,6 +10,7 @@ import java.sql.Connection;
import
java.sql.ResultSet
;
import
java.sql.SQLException
;
import
java.sql.Statement
;
import
org.h2.constant.ErrorCode
;
import
org.h2.engine.Constants
;
import
org.h2.store.fs.FileObject
;
import
org.h2.store.fs.FileSystem
;
...
...
@@ -113,12 +114,7 @@ public class TestPageStoreCoverage extends TestBase {
stat
.
execute
(
"drop table test2"
);
stat
.
execute
(
"insert into test select null, space(10) from system_range(1, 10)"
);
stat
.
execute
(
"shutdown immediately"
);
try
{
conn
.
close
();
fail
();
}
catch
(
SQLException
e
)
{
// ignore
}
assertThrows
(
ErrorCode
.
DATABASE_IS_CLOSED
,
conn
).
close
();
conn
=
getConnection
(
URL
);
stat
=
conn
.
createStatement
();
stat
.
execute
(
"drop all objects"
);
...
...
@@ -134,12 +130,7 @@ public class TestPageStoreCoverage extends TestBase {
stat
.
execute
(
"create table test"
+
i
+
"(id identity, name varchar)"
);
}
stat
.
execute
(
"shutdown immediately"
);
try
{
conn
.
close
();
fail
();
}
catch
(
SQLException
e
)
{
// ignore
}
assertThrows
(
ErrorCode
.
DATABASE_IS_CLOSED
,
conn
).
close
();
conn
=
getConnection
(
URL
);
conn
.
createStatement
().
execute
(
"drop all objects"
);
conn
.
close
();
...
...
This diff is collapsed.
Click to expand it.
h2/src/test/org/h2/test/unit/TestPgServer.java
浏览文件 @
b0d2049a
...
...
@@ -55,12 +55,8 @@ public class TestPgServer extends TestBase {
private
void
testPgClient
()
throws
SQLException
{
Connection
conn
=
DriverManager
.
getConnection
(
"jdbc:postgresql://localhost:5535/test"
,
"sa"
,
"sa"
);
Statement
stat
=
conn
.
createStatement
();
try
{
stat
.
execute
(
"select ***"
);
fail
();
}
catch
(
SQLException
e
)
{
assertKnownException
(
e
);
}
assertThrows
(
SQLException
.
class
,
stat
).
execute
(
"select ***"
);
stat
.
execute
(
"create user test password 'test'"
);
stat
.
execute
(
"create table test(id int primary key, name varchar)"
);
stat
.
execute
(
"create index idx_test_name on test(name, id)"
);
...
...
This diff is collapsed.
Click to expand it.
h2/src/test/org/h2/test/unit/TestServlet.java
浏览文件 @
b0d2049a
...
...
@@ -22,6 +22,7 @@ import javax.servlet.Servlet;
import
javax.servlet.ServletContext
;
import
javax.servlet.ServletContextEvent
;
import
org.h2.constant.ErrorCode
;
import
org.h2.server.web.DbStarter
;
import
org.h2.test.TestBase
;
import
org.h2.util.New
;
...
...
@@ -200,13 +201,8 @@ public class TestServlet extends TestBase {
stat2
.
execute
(
"SELECT * FROM T"
);
stat2
.
execute
(
"DROP TABLE T"
);
try
{
stat1
.
execute
(
"SELECT * FROM T"
);
fail
();
}
catch
(
SQLException
e
)
{
assertKnownException
(
e
);
}
assertThrows
(
ErrorCode
.
TABLE_OR_VIEW_NOT_FOUND_1
,
stat1
).
execute
(
"SELECT * FROM T"
);
conn2
.
close
();
listener
.
contextDestroyed
(
event
);
...
...
@@ -220,12 +216,8 @@ public class TestServlet extends TestBase {
}
// connection must be closed
try
{
stat1
.
execute
(
"SELECT * FROM DUAL"
);
fail
();
}
catch
(
SQLException
e
)
{
assertKnownException
(
e
);
}
assertThrows
(
ErrorCode
.
OBJECT_CLOSED
,
stat1
).
execute
(
"SELECT * FROM DUAL"
);
deleteDb
(
"servlet"
);
...
...
This diff is collapsed.
Click to expand it.
h2/src/test/org/h2/test/unit/TestTools.java
浏览文件 @
b0d2049a
...
...
@@ -290,18 +290,10 @@ public class TestTools extends TestBase {
assertTrue
(
ts
==
rs
.
getTimestamp
(
"j"
));
assertTrue
(
ts
==
rs
.
getTimestamp
(
10
));
try
{
rs
.
getString
(
11
);
fail
();
}
catch
(
SQLException
e
)
{
assertEquals
(
ErrorCode
.
INVALID_VALUE_2
,
e
.
getErrorCode
());
}
try
{
rs
.
getString
(
"NOT_FOUND"
);
fail
();
}
catch
(
SQLException
e
)
{
assertEquals
(
ErrorCode
.
COLUMN_NOT_FOUND_1
,
e
.
getErrorCode
());
}
assertThrows
(
ErrorCode
.
INVALID_VALUE_2
,
(
ResultSet
)
rs
).
getString
(
11
);
assertThrows
(
ErrorCode
.
COLUMN_NOT_FOUND_1
,
(
ResultSet
)
rs
).
getString
(
"NOT_FOUND"
);
// all 'updateX' methods are not supported
for
(
Method
m:
rs
.
getClass
().
getMethods
())
{
...
...
@@ -348,12 +340,8 @@ public class TestTools extends TestBase {
assertFalse
(
rs
.
isClosed
());
assertEquals
(
1
,
rs
.
getRow
());
assertFalse
(
rs
.
next
());
try
{
rs
.
getInt
(
1
);
fail
();
}
catch
(
SQLException
e
)
{
assertEquals
(
ErrorCode
.
NO_DATA_AVAILABLE
,
e
.
getErrorCode
());
}
assertThrows
(
ErrorCode
.
NO_DATA_AVAILABLE
,
(
ResultSet
)
rs
).
getInt
(
1
);
assertTrue
(
rs
.
isClosed
());
assertEquals
(
0
,
rs
.
getRow
());
}
...
...
@@ -367,8 +355,7 @@ public class TestTools extends TestBase {
private
void
testWrongServer
()
throws
Exception
{
try
{
// try to connect when the server is not running
Connection
conn
=
getConnection
(
"jdbc:h2:tcp://localhost:9001/test"
);
conn
.
close
();
getConnection
(
"jdbc:h2:tcp://localhost:9001/test"
);
fail
();
}
catch
(
SQLException
e
)
{
assertEquals
(
ErrorCode
.
CONNECTION_BROKEN_1
,
e
.
getErrorCode
());
...
...
@@ -386,8 +373,7 @@ public class TestTools extends TestBase {
task
.
execute
();
Thread
.
sleep
(
100
);
try
{
Connection
conn
=
getConnection
(
"jdbc:h2:tcp://localhost:9001/test"
);
conn
.
close
();
getConnection
(
"jdbc:h2:tcp://localhost:9001/test"
);
fail
();
}
catch
(
SQLException
e
)
{
assertEquals
(
ErrorCode
.
CONNECTION_BROKEN_1
,
e
.
getErrorCode
());
...
...
This diff is collapsed.
Click to expand it.
h2/src/test/org/h2/test/unit/TestValue.java
浏览文件 @
b0d2049a
...
...
@@ -80,6 +80,7 @@ public class TestValue extends TestBase {
assertEquals
(
"1234567890.1234567"
,
v
.
convertPrecision
(
10
,
true
).
getString
());
try
{
v
.
convertPrecision
(
10
,
false
);
fail
();
}
catch
(
DbException
e
)
{
assertEquals
(
ErrorCode
.
NUMERIC_VALUE_OUT_OF_RANGE_1
,
e
.
getErrorCode
());
}
...
...
This diff is collapsed.
Click to expand it.
编写
预览
Markdown
格式
0%
重试
或
添加新文件
添加附件
取消
您添加了
0
人
到此讨论。请谨慎行事。
请先完成此评论的编辑!
取消
请
注册
或者
登录
后发表评论