Skip to content
项目
群组
代码片段
帮助
正在加载...
帮助
为 GitLab 提交贡献
登录/注册
切换导航
H
h2database
项目
项目
详情
活动
周期分析
仓库
仓库
文件
提交
分支
标签
贡献者
分枝图
比较
统计图
议题
0
议题
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
CI / CD
CI / CD
流水线
作业
计划
统计图
Wiki
Wiki
代码片段
代码片段
成员
成员
折叠边栏
关闭边栏
活动
分枝图
统计图
创建新议题
作业
提交
议题看板
打开侧边栏
Administrator
h2database
Commits
5e7df467
提交
5e7df467
authored
5月 20, 2016
作者:
lukaseder
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
[#285] Add support for ALTER INDEX IF EXISTS
上级
e8cccd33
显示空白字符变更
内嵌
并排
正在显示
5 个修改的文件
包含
37 行增加
和
9 行删除
+37
-9
help.csv
h2/src/docsrc/help/help.csv
+1
-1
Parser.java
h2/src/main/org/h2/command/Parser.java
+4
-1
AlterIndexRename.java
h2/src/main/org/h2/command/ddl/AlterIndexRename.java
+24
-5
help.csv
h2/src/main/org/h2/res/help.csv
+1
-1
testScript.sql
h2/src/test/org/h2/test/testScript.sql
+7
-1
没有找到文件。
h2/src/docsrc/help/help.csv
浏览文件 @
5e7df467
...
...
@@ -192,7 +192,7 @@ SHOW TABLES
"
"Commands (DDL)","ALTER INDEX RENAME","
ALTER INDEX indexName RENAME TO newIndexName
ALTER INDEX
[ IF EXISTS ]
indexName RENAME TO newIndexName
","
Renames an index.
This command commits an open transaction in this connection.
...
...
h2/src/main/org/h2/command/Parser.java
浏览文件 @
5e7df467
...
...
@@ -4852,10 +4852,13 @@ public class Parser {
}
private
AlterIndexRename
parseAlterIndex
()
{
boolean
ifExists
=
readIfExists
(
false
);
String
indexName
=
readIdentifierWithSchema
();
Schema
old
=
getSchema
();
AlterIndexRename
command
=
new
AlterIndexRename
(
session
);
command
.
setOldIndex
(
getSchema
().
getIndex
(
indexName
));
command
.
setOldSchema
(
old
);
command
.
setOldName
(
indexName
);
command
.
setIfExists
(
ifExists
);
read
(
"RENAME"
);
read
(
"TO"
);
String
newName
=
readIdentifierWithSchema
(
old
.
getName
());
...
...
h2/src/main/org/h2/command/ddl/AlterIndexRename.java
浏览文件 @
5e7df467
...
...
@@ -20,6 +20,9 @@ import org.h2.schema.Schema;
*/
public
class
AlterIndexRename
extends
DefineCommand
{
private
boolean
ifExists
;
private
Schema
oldSchema
;
private
String
oldIndexName
;
private
Index
oldIndex
;
private
String
newIndexName
;
...
...
@@ -27,8 +30,16 @@ public class AlterIndexRename extends DefineCommand {
super
(
session
);
}
public
void
setOldIndex
(
Index
index
)
{
oldIndex
=
index
;
public
void
setIfExists
(
boolean
b
)
{
ifExists
=
b
;
}
public
void
setOldSchema
(
Schema
old
)
{
oldSchema
=
old
;
}
public
void
setOldName
(
String
name
)
{
oldIndexName
=
name
;
}
public
void
setNewName
(
String
name
)
{
...
...
@@ -39,9 +50,17 @@ public class AlterIndexRename extends DefineCommand {
public
int
update
()
{
session
.
commit
(
true
);
Database
db
=
session
.
getDatabase
();
Schema
schema
=
oldIndex
.
getSchema
();
if
(
schema
.
findIndex
(
session
,
newIndexName
)
!=
null
||
newIndexName
.
equals
(
oldIndex
.
getName
()))
{
oldIndex
=
oldSchema
.
findIndex
(
session
,
oldIndexName
);
if
(
oldIndex
==
null
)
{
if
(!
ifExists
)
{
throw
DbException
.
get
(
ErrorCode
.
INDEX_NOT_FOUND_1
,
newIndexName
);
}
else
{
return
0
;
}
}
if
(
oldSchema
.
findIndex
(
session
,
newIndexName
)
!=
null
||
newIndexName
.
equals
(
oldIndexName
))
{
throw
DbException
.
get
(
ErrorCode
.
INDEX_ALREADY_EXISTS_1
,
newIndexName
);
}
...
...
h2/src/main/org/h2/res/help.csv
浏览文件 @
5e7df467
...
...
@@ -67,7 +67,7 @@ SHOW { SCHEMAS | TABLES [ FROM schemaName ] |
","
Lists the schemas, tables, or the columns of a table."
"Commands (DDL)","ALTER INDEX RENAME","
ALTER INDEX indexName RENAME TO newIndexName
ALTER INDEX
[ IF EXISTS ]
indexName RENAME TO newIndexName
","
Renames an index."
"Commands (DDL)","ALTER SCHEMA RENAME","
...
...
h2/src/test/org/h2/test/testScript.sql
浏览文件 @
5e7df467
...
...
@@ -4458,7 +4458,13 @@ create index if not exists idx_id on s.test(id);
create index if not exists idx_id on s.test(id);
> ok
alter index s.idx_id rename to s.index_id;
alter index s.idx_id rename to s.x;
> ok
alter index if exists s.idx_id rename to s.x;
> ok
alter index if exists s.x rename to s.index_id;
> ok
alter sequence if exists s.seq restart with 10;
...
...
编写
预览
Markdown
格式
0%
重试
或
添加新文件
添加附件
取消
您添加了
0
人
到此讨论。请谨慎行事。
请先完成此评论的编辑!
取消
请
注册
或者
登录
后发表评论