Skip to content
项目
群组
代码片段
帮助
正在加载...
帮助
为 GitLab 提交贡献
登录/注册
切换导航
H
h2database
项目
项目
详情
活动
周期分析
仓库
仓库
文件
提交
分支
标签
贡献者
分枝图
比较
统计图
议题
0
议题
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
CI / CD
CI / CD
流水线
作业
计划
统计图
Wiki
Wiki
代码片段
代码片段
成员
成员
折叠边栏
关闭边栏
活动
分枝图
统计图
创建新议题
作业
提交
议题看板
打开侧边栏
Administrator
h2database
Commits
2358ead2
提交
2358ead2
authored
5月 16, 2012
作者:
noelgrandin
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Jacob Qvortrup <jfq@arosii.dk> added SCRIPT TABLE and SCRIPT SCHEMA extensions
上级
da9d7900
全部展开
隐藏空白字符变更
内嵌
并排
正在显示
5 个修改的文件
包含
338 行增加
和
1 行删除
+338
-1
help.csv
h2/src/docsrc/help/help.csv
+8
-0
changelog.html
h2/src/docsrc/html/changelog.html
+1
-0
Parser.java
h2/src/main/org/h2/command/Parser.java
+26
-0
ScriptCommand.java
h2/src/main/org/h2/command/dml/ScriptCommand.java
+89
-1
TestRunscript.java
h2/src/test/org/h2/test/db/TestRunscript.java
+214
-0
没有找到文件。
h2/src/docsrc/help/help.csv
浏览文件 @
2358ead2
...
...
@@ -147,6 +147,10 @@ SCRIPT [ SIMPLE ] [ NODATA ] [ NOPASSWORDS ] [ NOSETTINGS ]
[ TO fileNameString [ scriptCompression ]
[ CIPHER cipher PASSWORD string ] ]
[ CHARSET charsetString ]
[ TABLE tableName ]
[ TABLE ( tableName, ... ) ]
[ SCHEMA schemaName ]
[ SCHEMA ( schemaName, ... ) ]
","
Creates a SQL script from the database.
...
...
@@ -169,6 +173,10 @@ and LZF are supported (LZF is faster but uses more space).
The password must be in single quotes; it is case sensitive and can contain spaces.
This command locks objects while it is running.
TABLE will dump the DDL only for the selected table.
SCHEMA will dump the DDL only for objects in the selected schema.
","
SCRIPT NODATA
"
...
...
h2/src/docsrc/html/changelog.html
浏览文件 @
2358ead2
...
...
@@ -42,6 +42,7 @@ Change Log
</li><li>
TRUNC was added as an alias for TRUNCATE.
</li><li>
Small optimisation for accessing result values by column name.
</li><li>
Fix for bug in Statement#getMoreResults(int)
</li><li>
Jacob Qvortrup
<jfq
@
arosii
.
dk
>
added SCRIPT TABLE and SCRIPT SCHEMA extensions(int)
</li></ul>
<h2>
Version 1.3.166 (2012-04-08)
</h2>
...
...
h2/src/main/org/h2/command/Parser.java
浏览文件 @
2358ead2
...
...
@@ -10,6 +10,7 @@ import java.math.BigDecimal;
import
java.math.BigInteger
;
import
java.text.Collator
;
import
java.util.ArrayList
;
import
java.util.Collection
;
import
java.util.HashSet
;
import
org.h2.api.Trigger
;
import
org.h2.command.ddl.AlterIndexRename
;
...
...
@@ -4689,6 +4690,31 @@ public class Parser {
private
ScriptCommand
parseScript
()
{
ScriptCommand
command
=
new
ScriptCommand
(
session
);
boolean
data
=
true
,
passwords
=
true
,
settings
=
true
,
dropTables
=
false
,
simple
=
false
;
if
(
readIf
(
"SCHEMA"
))
{
java
.
util
.
Set
<
String
>
schemaNames
=
new
HashSet
<
String
>();
if
(
readIf
(
"("
))
{
do
{
schemaNames
.
add
(
readUniqueIdentifier
());
}
while
(
readIf
(
","
));
read
(
")"
);
}
else
{
schemaNames
.
add
(
readUniqueIdentifier
());
}
command
.
setSchemaNames
(
schemaNames
);
}
else
if
(
readIf
(
"TABLE"
))
{
Collection
<
Table
>
tables
=
new
ArrayList
<
Table
>();
if
(
readIf
(
"("
))
{
do
{
Table
table
=
readTableOrView
();
tables
.
add
(
table
);
}
while
(
readIf
(
","
));
read
(
")"
);
}
else
{
Table
table
=
readTableOrView
();
tables
.
add
(
table
);
}
command
.
setTables
(
tables
);
}
if
(
readIf
(
"SIMPLE"
))
{
simple
=
true
;
}
...
...
h2/src/main/org/h2/command/dml/ScriptCommand.java
浏览文件 @
2358ead2
...
...
@@ -16,10 +16,13 @@ import java.sql.PreparedStatement;
import
java.sql.ResultSet
;
import
java.sql.SQLException
;
import
java.util.ArrayList
;
import
java.util.Collection
;
import
java.util.Collections
;
import
java.util.Comparator
;
import
java.util.Set
;
import
org.h2.command.CommandInterface
;
import
org.h2.command.Parser
;
import
org.h2.constant.ErrorCode
;
import
org.h2.constant.SysProperties
;
import
org.h2.constraint.Constraint
;
import
org.h2.engine.Comment
;
...
...
@@ -64,6 +67,8 @@ import org.h2.value.ValueString;
public
class
ScriptCommand
extends
ScriptBase
{
private
String
charset
=
Constants
.
VERSION_MINOR
<
3
?
SysProperties
.
FILE_ENCODING
:
Constants
.
UTF8
;
private
Set
<
String
>
schemaNames
;
private
Collection
<
Table
>
tables
;
private
boolean
passwords
;
private
boolean
data
;
private
boolean
settings
;
...
...
@@ -86,6 +91,14 @@ public class ScriptCommand extends ScriptBase {
// TODO lock all tables for 'script' command
public
void
setSchemaNames
(
Set
<
String
>
schemaNames
)
{
this
.
schemaNames
=
schemaNames
;
}
public
void
setTables
(
Collection
<
Table
>
tables
)
{
this
.
tables
=
tables
;
}
public
void
setData
(
boolean
data
)
{
this
.
data
=
data
;
}
...
...
@@ -121,6 +134,15 @@ public class ScriptCommand extends ScriptBase {
public
ResultInterface
query
(
int
maxrows
)
{
session
.
getUser
().
checkAdmin
();
reset
();
Database
db
=
session
.
getDatabase
();
if
(
schemaNames
!=
null
)
{
for
(
String
schemaName
:
schemaNames
)
{
Schema
schema
=
db
.
findSchema
(
schemaName
);
if
(
schema
==
null
)
{
throw
DbException
.
get
(
ErrorCode
.
SCHEMA_NOT_FOUND_1
,
schemaName
);
}
}
}
try
{
result
=
createResult
();
deleteStore
();
...
...
@@ -128,7 +150,6 @@ public class ScriptCommand extends ScriptBase {
if
(
out
!=
null
)
{
buffer
=
new
byte
[
Constants
.
IO_BUFFER_SIZE
];
}
Database
db
=
session
.
getDatabase
();
if
(
settings
)
{
for
(
Setting
setting
:
db
.
getAllSettings
())
{
if
(
setting
.
getName
().
equals
(
SetTypes
.
getTypeName
(
SetTypes
.
CREATE_BUILD
)))
{
...
...
@@ -149,6 +170,9 @@ public class ScriptCommand extends ScriptBase {
add
(
role
.
getCreateSQL
(
true
),
false
);
}
for
(
Schema
schema
:
db
.
getAllSchemas
())
{
if
(
excludeSchema
(
schema
))
{
continue
;
}
add
(
schema
.
getCreateSQL
(),
false
);
}
for
(
UserDataType
datatype
:
db
.
getAllUserDataTypes
())
{
...
...
@@ -158,6 +182,9 @@ public class ScriptCommand extends ScriptBase {
add
(
datatype
.
getCreateSQL
(),
false
);
}
for
(
SchemaObject
obj
:
db
.
getAllSchemaObjects
(
DbObject
.
CONSTANT
))
{
if
(
excludeSchema
(
obj
.
getSchema
()))
{
continue
;
}
Constant
constant
=
(
Constant
)
obj
;
add
(
constant
.
getCreateSQL
(),
false
);
}
...
...
@@ -170,6 +197,12 @@ public class ScriptCommand extends ScriptBase {
}
});
for
(
Table
table
:
tables
)
{
if
(
excludeSchema
(
table
.
getSchema
()))
{
continue
;
}
if
(
excludeTable
(
table
))
{
continue
;
}
if
(
table
.
isHidden
())
{
continue
;
}
...
...
@@ -184,6 +217,9 @@ public class ScriptCommand extends ScriptBase {
}
}
for
(
SchemaObject
obj
:
db
.
getAllSchemaObjects
(
DbObject
.
FUNCTION_ALIAS
))
{
if
(
excludeSchema
(
obj
.
getSchema
()))
{
continue
;
}
if
(
drop
)
{
add
(
obj
.
getDropSQL
(),
false
);
}
...
...
@@ -196,6 +232,9 @@ public class ScriptCommand extends ScriptBase {
add
(
agg
.
getCreateSQL
(),
false
);
}
for
(
SchemaObject
obj
:
db
.
getAllSchemaObjects
(
DbObject
.
SEQUENCE
))
{
if
(
excludeSchema
(
obj
.
getSchema
()))
{
continue
;
}
Sequence
sequence
=
(
Sequence
)
obj
;
if
(
drop
)
{
add
(
sequence
.
getDropSQL
(),
false
);
...
...
@@ -204,6 +243,12 @@ public class ScriptCommand extends ScriptBase {
}
int
count
=
0
;
for
(
Table
table
:
tables
)
{
if
(
excludeSchema
(
table
.
getSchema
()))
{
continue
;
}
if
(
excludeTable
(
table
))
{
continue
;
}
if
(
table
.
isHidden
())
{
continue
;
}
...
...
@@ -311,7 +356,13 @@ public class ScriptCommand extends ScriptBase {
}
});
for
(
SchemaObject
obj
:
constraints
)
{
if
(
excludeSchema
(
obj
.
getSchema
()))
{
continue
;
}
Constraint
constraint
=
(
Constraint
)
obj
;
if
(
excludeTable
(
constraint
.
getTable
()))
{
continue
;
}
if
(
constraint
.
getTable
().
isHidden
())
{
continue
;
}
...
...
@@ -320,10 +371,25 @@ public class ScriptCommand extends ScriptBase {
}
}
for
(
SchemaObject
obj
:
db
.
getAllSchemaObjects
(
DbObject
.
TRIGGER
))
{
if
(
excludeSchema
(
obj
.
getSchema
()))
{
continue
;
}
TriggerObject
trigger
=
(
TriggerObject
)
obj
;
if
(
excludeTable
(
trigger
.
getTable
()))
{
continue
;
}
add
(
trigger
.
getCreateSQL
(),
false
);
}
for
(
Right
right
:
db
.
getAllRights
())
{
Table
table
=
right
.
getGrantedTable
();
if
(
table
!=
null
)
{
if
(
excludeSchema
(
table
.
getSchema
()))
{
continue
;
}
if
(
excludeTable
(
table
))
{
continue
;
}
}
add
(
right
.
getCreateSQL
(),
false
);
}
for
(
Comment
comment
:
db
.
getAllComments
())
{
...
...
@@ -549,6 +615,28 @@ public class ScriptCommand extends ScriptBase {
}
}
private
boolean
excludeSchema
(
Schema
schema
)
{
if
(
this
.
schemaNames
!=
null
&&
!
this
.
schemaNames
.
contains
(
schema
.
getName
()))
{
return
true
;
}
if
(
this
.
tables
!=
null
)
{
boolean
containsTable
=
false
;
for
(
Table
table
:
schema
.
getAllTablesAndViews
())
{
if
(
tables
.
contains
(
table
))
{
table
.
checkSupportAlter
();
// This may not be the correct way to ensure that only real tables can be used as arguments.
containsTable
=
true
;
}
}
if
(!
containsTable
)
return
true
;
}
return
false
;
}
private
boolean
excludeTable
(
Table
table
)
{
return
this
.
tables
!=
null
&&
!
this
.
tables
.
contains
(
table
);
}
private
void
add
(
String
s
,
boolean
insert
)
throws
IOException
{
if
(
s
==
null
)
{
return
;
...
...
h2/src/test/org/h2/test/db/TestRunscript.java
浏览文件 @
2358ead2
差异被折叠。
点击展开。
编写
预览
Markdown
格式
0%
重试
或
添加新文件
添加附件
取消
您添加了
0
人
到此讨论。请谨慎行事。
请先完成此评论的编辑!
取消
请
注册
或者
登录
后发表评论