Skip to content
项目
群组
代码片段
帮助
正在加载...
帮助
为 GitLab 提交贡献
登录/注册
切换导航
H
h2database
项目
项目
详情
活动
周期分析
仓库
仓库
文件
提交
分支
标签
贡献者
分枝图
比较
统计图
议题
0
议题
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
CI / CD
CI / CD
流水线
作业
计划
统计图
Wiki
Wiki
代码片段
代码片段
成员
成员
折叠边栏
关闭边栏
活动
分枝图
统计图
创建新议题
作业
提交
议题看板
打开侧边栏
Administrator
h2database
Commits
efe8c198
提交
efe8c198
authored
1月 08, 2018
作者:
sylvain-ilm
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
added STANDARD_DROP_TABLE_RESTRICT setting
上级
697a9691
显示空白字符变更
内嵌
并排
正在显示
5 个修改的文件
包含
45 行增加
和
8 行删除
+45
-8
DropTable.java
h2/src/main/org/h2/command/ddl/DropTable.java
+9
-6
DbSettings.java
h2/src/main/org/h2/engine/DbSettings.java
+11
-0
TestAll.java
h2/src/test/org/h2/test/TestAll.java
+4
-0
TestBase.java
h2/src/test/org/h2/test/TestBase.java
+4
-0
TestCases.java
h2/src/test/org/h2/test/db/TestCases.java
+17
-2
没有找到文件。
h2/src/main/org/h2/command/ddl/DropTable.java
浏览文件 @
efe8c198
...
...
@@ -84,6 +84,8 @@ public class DropTable extends SchemaCommand {
buff
.
append
(
v
.
getName
());
}
}
if
(
session
.
getDatabase
()
.
getSettings
().
standardDropTableRestrict
)
{
final
List
<
Constraint
>
constraints
=
table
.
getConstraints
();
if
(
constraints
!=
null
&&
constraints
.
size
()
>
0
)
{
for
(
Constraint
c
:
constraints
)
{
...
...
@@ -93,6 +95,7 @@ public class DropTable extends SchemaCommand {
}
}
}
}
if
(
buff
.
length
()
>
0
)
throw
DbException
.
get
(
ErrorCode
.
CANNOT_DROP_2
,
tableName
,
buff
.
toString
());
...
...
h2/src/main/org/h2/engine/DbSettings.java
浏览文件 @
efe8c198
...
...
@@ -350,6 +350,17 @@ public class DbSettings extends SettingsBase {
*/
public
final
boolean
multiThreaded
=
get
(
"MULTI_THREADED"
,
false
);
/**
* Database setting <code>STANDARD_DROP_TABLE_RESTRICT</code> (default:
* false).<br />
* <code>true</code> if DROP TABLE RESTRICT should fail if there's any
* foreign key referencing the table to be dropped. <code>false</code> if
* foreign keys referencing the table to be dropped should be silently
* dropped as well.
*/
public
final
boolean
standardDropTableRestrict
=
get
(
"STANDARD_DROP_TABLE_RESTRICT"
,
false
);
private
DbSettings
(
HashMap
<
String
,
String
>
s
)
{
super
(
s
);
}
...
...
h2/src/test/org/h2/test/TestAll.java
浏览文件 @
efe8c198
...
...
@@ -11,6 +11,7 @@ import java.util.ArrayList;
import
java.util.Properties
;
import
java.util.TimerTask
;
import
java.util.concurrent.TimeUnit
;
import
org.h2.Driver
;
import
org.h2.engine.Constants
;
import
org.h2.store.fs.FilePathRec
;
...
...
@@ -431,6 +432,7 @@ java org.h2.test.TestAll timer
/** If not null the database should be opened with the collation parameter */
public
String
collation
;
public
boolean
stdDropTableRestrict
;
/**
* The AB-BA locking detector.
...
...
@@ -618,6 +620,7 @@ kill -9 `jps -l | grep "org.h2.test." | cut -d " " -f 1`
defrag
=
false
;
traceLevelFile
=
throttle
=
0
;
cipher
=
null
;
stdDropTableRestrict
=
false
;
// memory is a good match for multi-threaded, makes things happen
// faster, more chance of exposing race conditions
...
...
@@ -1127,6 +1130,7 @@ kill -9 `jps -l | grep "org.h2.test." | cut -d " " -f 1`
appendIf
(
buff
,
defrag
,
"defrag"
);
appendIf
(
buff
,
splitFileSystem
,
"split"
);
appendIf
(
buff
,
collation
!=
null
,
collation
);
appendIf
(
buff
,
stdDropTableRestrict
,
"stdDropTableRestrict"
);
return
buff
.
toString
();
}
...
...
h2/src/test/org/h2/test/TestBase.java
浏览文件 @
efe8c198
...
...
@@ -34,6 +34,7 @@ import java.util.ArrayList;
import
java.util.LinkedList
;
import
java.util.SimpleTimeZone
;
import
java.util.concurrent.TimeUnit
;
import
org.h2.jdbc.JdbcConnection
;
import
org.h2.message.DbException
;
import
org.h2.store.fs.FilePath
;
...
...
@@ -333,6 +334,9 @@ public abstract class TestBase {
if
(
config
.
collation
!=
null
)
{
url
=
addOption
(
url
,
"COLLATION"
,
config
.
collation
);
}
if
(
config
.
stdDropTableRestrict
)
{
url
=
addOption
(
url
,
"STANDARD_DROP_TABLE_RESTRICT"
,
"TRUE"
);
}
return
"jdbc:h2:"
+
url
;
}
...
...
h2/src/test/org/h2/test/db/TestCases.java
浏览文件 @
efe8c198
...
...
@@ -279,11 +279,23 @@ public class TestCases extends TestBase {
conn
.
close
();
}
private
void
testDropTable
()
throws
SQLException
{
final
boolean
prevVal
=
config
.
stdDropTableRestrict
;
try
{
for
(
final
boolean
newVal
:
new
boolean
[]
{
true
,
false
})
{
config
.
stdDropTableRestrict
=
newVal
;
_testDropTable
();
}
}
finally
{
config
.
stdDropTableRestrict
=
prevVal
;
}
}
private
static
enum
DropDependent
{
NONE
,
VIEW
,
FOREIGN_KEY
;
}
private
void
testDropTable
()
throws
SQLException
{
private
void
_
testDropTable
()
throws
SQLException
{
trace
(
"testDrop"
);
for
(
final
boolean
restrict
:
new
boolean
[]
{
true
,
false
})
{
...
...
@@ -301,7 +313,10 @@ public class TestCases extends TestBase {
}
// drop allowed if no references or cascade
final
boolean
expectedDropSuccess
=
dropDep
==
DropDependent
.
NONE
||
!
restrict
;
final
boolean
expectedDropSuccess
=
dropDep
==
DropDependent
.
NONE
||
(!
config
.
stdDropTableRestrict
&&
dropDep
==
DropDependent
.
FOREIGN_KEY
)
||
!
restrict
;
assertThrows
(
expectedDropSuccess
?
0
:
ErrorCode
.
CANNOT_DROP_2
,
stat
).
execute
(
"drop table test "
+
(
restrict
?
"restrict"
:
"cascade"
));
assertThrows
(
expectedDropSuccess
?
ErrorCode
.
TABLE_OR_VIEW_NOT_FOUND_1
:
0
,
stat
).
execute
(
"select * from test"
);
...
...
编写
预览
Markdown
格式
0%
重试
或
添加新文件
添加附件
取消
您添加了
0
人
到此讨论。请谨慎行事。
请先完成此评论的编辑!
取消
请
注册
或者
登录
后发表评论