Skip to content
项目
群组
代码片段
帮助
正在加载...
帮助
为 GitLab 提交贡献
登录/注册
切换导航
H
h2database
项目
项目
详情
活动
周期分析
仓库
仓库
文件
提交
分支
标签
贡献者
分枝图
比较
统计图
议题
0
议题
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
CI / CD
CI / CD
流水线
作业
计划
统计图
Wiki
Wiki
代码片段
代码片段
成员
成员
折叠边栏
关闭边栏
活动
分枝图
统计图
创建新议题
作业
提交
议题看板
打开侧边栏
Administrator
h2database
Commits
276ad6f5
提交
276ad6f5
authored
7月 04, 2010
作者:
sainsbury.kerry
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Implemented "Support ALTER SCHEMA name RENAME TO newName (rename schema)"
上级
e0403b2c
隐藏空白字符变更
内嵌
并排
正在显示
10 个修改的文件
包含
271 行增加
和
3 行删除
+271
-3
help.csv
h2/src/docsrc/help/help.csv
+9
-0
changelog.html
h2/src/docsrc/html/changelog.html
+1
-0
roadmap.html
h2/src/docsrc/html/roadmap.html
+0
-2
Parser.java
h2/src/main/org/h2/command/Parser.java
+23
-1
AlterSchemaRename.java
h2/src/main/org/h2/command/ddl/AlterSchemaRename.java
+56
-0
Database.java
h2/src/main/org/h2/engine/Database.java
+14
-0
help.csv
h2/src/main/org/h2/res/help.csv
+4
-0
Schema.java
h2/src/main/org/h2/schema/Schema.java
+19
-0
TestAll.java
h2/src/test/org/h2/test/TestAll.java
+2
-0
TestAlterSchemaRename.java
h2/src/test/org/h2/test/db/TestAlterSchemaRename.java
+143
-0
没有找到文件。
h2/src/docsrc/help/help.csv
浏览文件 @
276ad6f5
...
...
@@ -177,6 +177,15 @@ This command commits an open transaction.
ALTER INDEX IDXNAME RENAME TO IDX_TEST_NAME
"
"Commands (DDL)","ALTER SCHEMA RENAME","
ALTER SCHEMA schema RENAME TO newSchemaName
","
Renames a schema.
This command commits an open transaction.
","
ALTER SCHEMA TEST RENAME TO PRODUCTION
"
"Commands (DDL)","ALTER SEQUENCE","
ALTER SEQUENCE sequenceName [ RESTART WITH long ] [ INCREMENT BY long ]
","
...
...
h2/src/docsrc/html/changelog.html
浏览文件 @
276ad6f5
...
...
@@ -59,6 +59,7 @@ Change Log
</li><li>
Cluster: non-admin users could not connect when one of the cluster node was stopped. Issue 206.
</li><li>
DROP VIEW now supports the CASCADE and RESTRICT clauses (patch from Kerry Sainsbury)
</li><li>
CREATE VIEW now supports the OR REPLACE clause (patch from Kerry Sainsbury)
</li><li>
Support ALTER SCHEMA name RENAME TO newName (rename schema). (patch from Kerry Sainsbury)
</li><li>
Build tool: ability to only run one test using the -Dtest=className setting.
eg: build -Dtest=org.h2.test.db.TestViewDropView test (patch from Kerry Sainsbury).
</li></ul>
...
...
h2/src/docsrc/html/roadmap.html
浏览文件 @
276ad6f5
...
...
@@ -380,7 +380,6 @@ See also <a href="build.html#providing_patches">Providing Patches</a>.
</li><li>
Improve SQL documentation, see http://www.w3schools.com/sql/
</li><li>
MySQL compatibility: DatabaseMetaData.stores*() methods should return the same values. Test with SquirrelSQL.
</li><li>
MS SQL Server compatibility: support DATEPART syntax.
</li><li>
Oracle compatibility: support CREATE OR REPLACE VIEW syntax.
</li><li>
Sybase/DB2/Oracle compatibility: support out parameters in stored procedures - See http://code.google.com/p/h2database/issues/detail?id=83
</li><li>
Support INTERVAL data type (see Oracle and others).
</li><li>
Combine Server and Console tool (only keep Server).
...
...
@@ -464,7 +463,6 @@ See also <a href="build.html#providing_patches">Providing Patches</a>.
</li><li>
User defined functions: allow to store the bytecode (of just the class, or the jar file of the extension) in the database.
</li><li>
Compatibility: ResultSet.getObject() on a CLOB (TEXT) should return String for PostgreSQL and MySQL.
</li><li>
Optimizer: WHERE X=? AND Y IN(?), it always uses the index on Y. Should be cost based.
</li><li>
Support ALTER SCHEMA name RENAME TO newName (rename schema).
</li><li>
Make the cache scan resistant (currently a small cache is faster than a large cache for large table scans).
</li><li>
Issue 178: Optimizer: index usage when both ascending and descending indexes are available.
</li><li>
Issue 179: Related subqueries in HAVING clause
...
...
h2/src/main/org/h2/command/Parser.java
浏览文件 @
276ad6f5
...
...
@@ -13,6 +13,7 @@ import java.util.ArrayList;
import
java.util.HashSet
;
import
org.h2.api.Trigger
;
import
org.h2.command.ddl.AlterIndexRename
;
import
org.h2.command.ddl.AlterSchemaRename
;
import
org.h2.command.ddl.AlterTableAddConstraint
;
import
org.h2.command.ddl.AlterTableAlterColumn
;
import
org.h2.command.ddl.AlterTableDropConstraint
;
...
...
@@ -588,7 +589,7 @@ public class Parser {
return
command
;
}
private
Schema
getSchema
()
{
private
Schema
getSchema
(
String
schemaName
)
{
if
(
schemaName
==
null
)
{
return
null
;
}
...
...
@@ -604,6 +605,11 @@ public class Parser {
return
schema
;
}
private
Schema
getSchema
()
{
return
getSchema
(
schemaName
);
}
private
Column
readTableColumn
(
TableFilter
filter
)
{
String
tableAlias
=
null
;
String
columnName
=
readColumnIdentifier
();
...
...
@@ -4029,6 +4035,8 @@ public class Parser {
return
parseAlterUser
();
}
else
if
(
readIf
(
"INDEX"
))
{
return
parseAlterIndex
();
}
else
if
(
readIf
(
"SCHEMA"
))
{
return
parseAlterSchema
();
}
else
if
(
readIf
(
"SEQUENCE"
))
{
return
parseAlterSequence
();
}
else
if
(
readIf
(
"VIEW"
))
{
...
...
@@ -4069,6 +4077,20 @@ public class Parser {
return
command
;
}
private
AlterSchemaRename
parseAlterSchema
()
{
String
schemaName
=
readIdentifierWithSchema
();
Schema
old
=
getSchema
();
AlterSchemaRename
command
=
new
AlterSchemaRename
(
session
);
command
.
setOldSchema
(
getSchema
(
schemaName
));
read
(
"RENAME"
);
read
(
"TO"
);
String
newName
=
readIdentifierWithSchema
(
old
.
getName
());
checkSchema
(
old
);
command
.
setNewName
(
newName
);
return
command
;
}
private
AlterSequence
parseAlterSequence
()
{
String
sequenceName
=
readIdentifierWithSchema
();
Sequence
sequence
=
getSchema
().
getSequence
(
sequenceName
);
...
...
h2/src/main/org/h2/command/ddl/AlterSchemaRename.java
0 → 100644
浏览文件 @
276ad6f5
/*
* Copyright 2004-2010 H2 Group. Multiple-Licensed under the H2 License,
* Version 1.0, and under the Eclipse Public License, Version 1.0
* (http://h2database.com/html/license.html).
* Initial Developer: H2 Group
*/
package
org
.
h2
.
command
.
ddl
;
import
org.h2.constant.ErrorCode
;
import
org.h2.engine.Database
;
import
org.h2.engine.Session
;
import
org.h2.message.DbException
;
import
org.h2.schema.Schema
;
import
org.h2.schema.SchemaObject
;
import
java.util.ArrayList
;
/**
* This class represents the statement
* ALTER SCHEMA RENAME
*/
public
class
AlterSchemaRename
extends
DefineCommand
{
private
Schema
oldSchema
;
private
String
newSchemaName
;
public
AlterSchemaRename
(
Session
session
)
{
super
(
session
);
}
public
void
setOldSchema
(
Schema
Schema
)
{
oldSchema
=
Schema
;
}
public
void
setNewName
(
String
name
)
{
newSchemaName
=
name
;
}
public
int
update
()
{
session
.
commit
(
true
);
Database
db
=
session
.
getDatabase
();
if
(
db
.
findSchema
(
newSchemaName
)
!=
null
||
newSchemaName
.
equals
(
oldSchema
.
getName
()))
{
throw
DbException
.
get
(
ErrorCode
.
SCHEMA_ALREADY_EXISTS_1
,
newSchemaName
);
}
session
.
getUser
().
checkAdmin
();
db
.
renameDatabaseObject
(
session
,
oldSchema
,
newSchemaName
);
ArrayList
<
SchemaObject
>
all
=
db
.
getAllSchemaObjects
();
for
(
SchemaObject
schemaObject
:
all
)
{
db
.
update
(
session
,
schemaObject
);
}
return
0
;
}
}
h2/src/main/org/h2/engine/Database.java
浏览文件 @
276ad6f5
...
...
@@ -1226,6 +1226,20 @@ public class Database implements DataHandler {
return
New
.
arrayList
(
roles
.
values
());
}
/**
* Get all schema objects.
*
* @return all objects of all types
*/
public
ArrayList
<
SchemaObject
>
getAllSchemaObjects
()
{
initMetaTables
();
ArrayList
<
SchemaObject
>
list
=
New
.
arrayList
();
for
(
Schema
schema
:
schemas
.
values
())
{
list
.
addAll
(
schema
.
getAll
());
}
return
list
;
}
/**
* Get all schema objects of the given type.
*
...
...
h2/src/main/org/h2/res/help.csv
浏览文件 @
276ad6f5
...
...
@@ -65,6 +65,10 @@ Lists the schemas, tables, or the columns of a table."
ALTER INDEX indexName RENAME TO newIndexName
","
Renames an index."
"Commands (DDL)","ALTER SCHEMA RENAME","
ALTER SCHEMA schema RENAME TO newSchemaName
","
Renames a schema."
"Commands (DDL)","ALTER SEQUENCE","
ALTER SEQUENCE sequenceName [ RESTART WITH long ] [ INCREMENT BY long ]
","
...
...
h2/src/main/org/h2/schema/Schema.java
浏览文件 @
276ad6f5
...
...
@@ -467,6 +467,25 @@ public class Schema extends DbObjectBase {
return
sequence
;
}
/**
* Get all objects.
*
* @return a (possible empty) list of all objects
*/
public
ArrayList
<
SchemaObject
>
getAll
()
{
ArrayList
<
SchemaObject
>
all
=
New
.
arrayList
();
all
.
addAll
(
getMap
(
DbObject
.
TABLE_OR_VIEW
).
values
());
all
.
addAll
(
getMap
(
DbObject
.
SEQUENCE
).
values
());
all
.
addAll
(
getMap
(
DbObject
.
INDEX
).
values
());
all
.
addAll
(
getMap
(
DbObject
.
TRIGGER
).
values
());
all
.
addAll
(
getMap
(
DbObject
.
CONSTRAINT
).
values
());
all
.
addAll
(
getMap
(
DbObject
.
CONSTANT
).
values
());
all
.
addAll
(
getMap
(
DbObject
.
FUNCTION_ALIAS
).
values
());
return
all
;
}
/**
* Get all objects of the given type.
*
...
...
h2/src/test/org/h2/test/TestAll.java
浏览文件 @
276ad6f5
...
...
@@ -13,6 +13,7 @@ import org.h2.engine.Constants;
import
org.h2.store.fs.FileSystemDisk
;
import
org.h2.test.bench.TestPerformance
;
import
org.h2.test.db.TestAlter
;
import
org.h2.test.db.TestAlterSchemaRename
;
import
org.h2.test.db.TestAutoRecompile
;
import
org.h2.test.db.TestBackup
;
import
org.h2.test.db.TestBigDb
;
...
...
@@ -494,6 +495,7 @@ kill -9 `jps -l | grep "org.h2.test." | cut -d " " -f 1`
new
TestScriptSimple
().
runTest
(
this
);
new
TestScript
().
runTest
(
this
);
new
TestAlter
().
runTest
(
this
);
new
TestAlterSchemaRename
().
runTest
(
this
);
new
TestAutoRecompile
().
runTest
(
this
);
new
TestBackup
().
runTest
(
this
);
new
TestBigDb
().
runTest
(
this
);
...
...
h2/src/test/org/h2/test/db/TestAlterSchemaRename.java
0 → 100644
浏览文件 @
276ad6f5
/*
* Copyright 2004-2010 H2 Group. Multiple-Licensed under the H2 License,
* Version 1.0, and under the Eclipse Public License, Version 1.0
* (http://h2database.com/html/license.html).
* Initial Developer: H2 Group
*/
package
org
.
h2
.
test
.
db
;
import
org.h2.constant.ErrorCode
;
import
org.h2.test.TestBase
;
import
java.sql.Connection
;
import
java.sql.ResultSet
;
import
java.sql.SQLException
;
import
java.sql.Statement
;
/**
* Test ALTER SCHEMA RENAME statements.
*/
public
class
TestAlterSchemaRename
extends
TestBase
{
private
Connection
conn
;
private
Statement
stat
;
/**
* Run just this test.
*
* @param a ignored
*/
public
static
void
main
(
String
...
a
)
throws
Exception
{
TestBase
.
createCaller
().
init
().
test
();
}
public
void
test
()
throws
Exception
{
deleteDb
(
"alter"
);
conn
=
getConnection
(
"alter"
);
stat
=
conn
.
createStatement
();
testSimpleRename
();
testRenameToExistingSchema
();
testCrossSchemaViews
();
testAlias
();
conn
.
close
();
deleteDb
(
"alter"
);
}
private
void
testSimpleRename
()
throws
SQLException
{
stat
.
execute
(
"create schema s1"
);
stat
.
execute
(
"create table s1.tab(val int)"
);
stat
.
execute
(
"insert into s1.tab(val) values (3)"
);
ResultSet
rs
=
stat
.
executeQuery
(
"select * from s1.tab"
);
assertTrue
(
rs
.
next
());
assertEquals
(
3
,
rs
.
getInt
(
1
));
stat
.
execute
(
"alter schema s1 rename to s2"
);
rs
=
stat
.
executeQuery
(
"select * from s2.tab"
);
assertTrue
(
rs
.
next
());
assertEquals
(
3
,
rs
.
getInt
(
1
));
stat
.
execute
(
"drop schema s2"
);
}
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
());
}
stat
.
execute
(
"drop schema s1"
);
stat
.
execute
(
"drop schema s2"
);
}
private
void
testCrossSchemaViews
()
throws
SQLException
{
stat
.
execute
(
"create schema s1"
);
stat
.
execute
(
"create schema s2"
);
stat
.
execute
(
"create table s1.tab(val int)"
);
stat
.
execute
(
"insert into s1.tab(val) values (3)"
);
stat
.
execute
(
"create view s1.v1 as select * from s1.tab"
);
stat
.
execute
(
"create view s2.v1 as select val * 2 from s1.tab"
);
stat
.
execute
(
"alter schema s2 rename to s2_new"
);
ResultSet
rs
=
stat
.
executeQuery
(
"select * from s1.v1"
);
assertTrue
(
rs
.
next
());
assertEquals
(
3
,
rs
.
getInt
(
1
));
rs
=
stat
.
executeQuery
(
"select * from s2_new.v1"
);
assertTrue
(
rs
.
next
());
assertEquals
(
6
,
rs
.
getInt
(
1
));
if
(!
config
.
memory
)
{
conn
.
close
();
conn
=
getConnection
(
"alter"
);
stat
=
conn
.
createStatement
();
stat
.
executeQuery
(
"select * from s2_new.v1"
);
}
stat
.
execute
(
"drop schema s1"
);
stat
.
execute
(
"drop schema s2_new"
);
}
// Check that aliases in the schema got moved
private
void
testAlias
()
throws
SQLException
{
stat
.
execute
(
"create schema s1"
);
stat
.
execute
(
"CREATE ALIAS S1.REVERSE AS $$ "
+
"String reverse(String s) {"
+
" return new StringBuilder(s).reverse().toString();"
+
"} $$;"
);
stat
.
execute
(
"alter schema s1 rename to s2"
);
ResultSet
rs
=
stat
.
executeQuery
(
"CALL S2.REVERSE('1234')"
);
assertTrue
(
rs
.
next
());
assertEquals
(
"4321"
,
rs
.
getString
(
1
));
if
(!
config
.
memory
)
{
conn
.
close
();
conn
=
getConnection
(
"alter"
);
stat
=
conn
.
createStatement
();
stat
.
executeQuery
(
"CALL S2.REVERSE('1234')"
);
}
stat
.
execute
(
"drop schema s2"
);
}
}
\ No newline at end of file
编写
预览
Markdown
格式
0%
重试
或
添加新文件
添加附件
取消
您添加了
0
人
到此讨论。请谨慎行事。
请先完成此评论的编辑!
取消
请
注册
或者
登录
后发表评论