Skip to content
项目
群组
代码片段
帮助
正在加载...
帮助
为 GitLab 提交贡献
登录/注册
切换导航
H
h2database
项目
项目
详情
活动
周期分析
仓库
仓库
文件
提交
分支
标签
贡献者
分枝图
比较
统计图
议题
0
议题
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
CI / CD
CI / CD
流水线
作业
计划
统计图
Wiki
Wiki
代码片段
代码片段
成员
成员
折叠边栏
关闭边栏
活动
分枝图
统计图
创建新议题
作业
提交
议题看板
打开侧边栏
Administrator
h2database
Commits
ae0975d4
提交
ae0975d4
authored
15 年前
作者:
Thomas Mueller
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Issue 125: Renaming primary keys was not persistent.
上级
e46a8da0
隐藏空白字符变更
内嵌
并排
正在显示
4 个修改的文件
包含
35 行增加
和
7 行删除
+35
-7
Parser.java
h2/src/main/org/h2/command/Parser.java
+5
-0
CreateIndex.java
h2/src/main/org/h2/command/ddl/CreateIndex.java
+6
-4
BaseIndex.java
h2/src/main/org/h2/index/BaseIndex.java
+1
-3
TestIndex.java
h2/src/test/org/h2/test/db/TestIndex.java
+23
-0
没有找到文件。
h2/src/main/org/h2/command/Parser.java
浏览文件 @
ae0975d4
...
@@ -3490,6 +3490,11 @@ public class Parser {
...
@@ -3490,6 +3490,11 @@ public class Parser {
hash
=
true
;
hash
=
true
;
}
}
primaryKey
=
true
;
primaryKey
=
true
;
if
(!
isToken
(
"ON"
))
{
ifNotExists
=
readIfNoExists
();
indexName
=
readIdentifierWithSchema
(
null
);
oldSchema
=
getSchema
();
}
}
else
{
}
else
{
if
(
readIf
(
"UNIQUE"
))
{
if
(
readIf
(
"UNIQUE"
))
{
unique
=
true
;
unique
=
true
;
...
...
This diff is collapsed.
Click to expand it.
h2/src/main/org/h2/command/ddl/CreateIndex.java
浏览文件 @
ae0975d4
...
@@ -63,10 +63,12 @@ public class CreateIndex extends SchemaCommand {
...
@@ -63,10 +63,12 @@ public class CreateIndex extends SchemaCommand {
persistent
=
false
;
persistent
=
false
;
}
}
int
id
=
getObjectId
(
true
,
false
);
int
id
=
getObjectId
(
true
,
false
);
if
(
primaryKey
)
{
if
(
indexName
==
null
)
{
indexName
=
table
.
getSchema
().
getUniqueIndexName
(
session
,
table
,
Constants
.
PREFIX_PRIMARY_KEY
);
if
(
primaryKey
)
{
}
else
if
(
indexName
==
null
)
{
indexName
=
table
.
getSchema
().
getUniqueIndexName
(
session
,
table
,
Constants
.
PREFIX_PRIMARY_KEY
);
indexName
=
table
.
getSchema
().
getUniqueIndexName
(
session
,
table
,
Constants
.
PREFIX_INDEX
);
}
else
{
indexName
=
table
.
getSchema
().
getUniqueIndexName
(
session
,
table
,
Constants
.
PREFIX_INDEX
);
}
}
}
if
(
getSchema
().
findIndex
(
session
,
indexName
)
!=
null
)
{
if
(
getSchema
().
findIndex
(
session
,
indexName
)
!=
null
)
{
if
(
ifNotExists
)
{
if
(
ifNotExists
)
{
...
...
This diff is collapsed.
Click to expand it.
h2/src/main/org/h2/index/BaseIndex.java
浏览文件 @
ae0975d4
...
@@ -323,9 +323,7 @@ public abstract class BaseIndex extends SchemaObjectBase implements Index {
...
@@ -323,9 +323,7 @@ public abstract class BaseIndex extends SchemaObjectBase implements Index {
public
String
getCreateSQLForCopy
(
Table
table
,
String
quotedName
)
{
public
String
getCreateSQLForCopy
(
Table
table
,
String
quotedName
)
{
StringBuilder
buff
=
new
StringBuilder
(
"CREATE "
);
StringBuilder
buff
=
new
StringBuilder
(
"CREATE "
);
buff
.
append
(
indexType
.
getSQL
());
buff
.
append
(
indexType
.
getSQL
());
if
(!
indexType
.
isPrimaryKey
())
{
buff
.
append
(
' '
).
append
(
quotedName
);
buff
.
append
(
' '
).
append
(
quotedName
);
}
buff
.
append
(
" ON "
).
append
(
table
.
getSQL
());
buff
.
append
(
" ON "
).
append
(
table
.
getSQL
());
if
(
comment
!=
null
)
{
if
(
comment
!=
null
)
{
buff
.
append
(
" COMMENT "
).
append
(
StringUtils
.
quoteStringSQL
(
comment
));
buff
.
append
(
" COMMENT "
).
append
(
StringUtils
.
quoteStringSQL
(
comment
));
...
...
This diff is collapsed.
Click to expand it.
h2/src/test/org/h2/test/db/TestIndex.java
浏览文件 @
ae0975d4
...
@@ -36,6 +36,7 @@ public class TestIndex extends TestBase {
...
@@ -36,6 +36,7 @@ public class TestIndex extends TestBase {
public
void
test
()
throws
SQLException
{
public
void
test
()
throws
SQLException
{
deleteDb
(
"index"
);
deleteDb
(
"index"
);
testRenamePrimaryKey
();
testRandomized
();
testRandomized
();
testDescIndex
();
testDescIndex
();
testHashIndex
();
testHashIndex
();
...
@@ -83,6 +84,28 @@ public class TestIndex extends TestBase {
...
@@ -83,6 +84,28 @@ public class TestIndex extends TestBase {
deleteDb
(
"index"
);
deleteDb
(
"index"
);
}
}
private
void
testRenamePrimaryKey
()
throws
SQLException
{
if
(
config
.
memory
)
{
return
;
}
reconnect
();
stat
.
execute
(
"create table test(id int not null)"
);
stat
.
execute
(
"alter table test add constraint x primary key(id)"
);
ResultSet
rs
;
rs
=
conn
.
getMetaData
().
getIndexInfo
(
null
,
null
,
"TEST"
,
true
,
false
);
rs
.
next
();
String
old
=
rs
.
getString
(
"INDEX_NAME"
);
stat
.
execute
(
"alter index "
+
old
+
" rename to y"
);
rs
=
conn
.
getMetaData
().
getIndexInfo
(
null
,
null
,
"TEST"
,
true
,
false
);
rs
.
next
();
assertEquals
(
"Y"
,
rs
.
getString
(
"INDEX_NAME"
));
reconnect
();
rs
=
conn
.
getMetaData
().
getIndexInfo
(
null
,
null
,
"TEST"
,
true
,
false
);
rs
.
next
();
assertEquals
(
"Y"
,
rs
.
getString
(
"INDEX_NAME"
));
stat
.
execute
(
"drop table test"
);
}
private
void
testRandomized
()
throws
SQLException
{
private
void
testRandomized
()
throws
SQLException
{
boolean
reopen
=
!
config
.
memory
;
boolean
reopen
=
!
config
.
memory
;
Random
random
=
new
Random
(
1
);
Random
random
=
new
Random
(
1
);
...
...
This diff is collapsed.
Click to expand it.
编写
预览
Markdown
格式
0%
重试
或
添加新文件
添加附件
取消
您添加了
0
人
到此讨论。请谨慎行事。
请先完成此评论的编辑!
取消
请
注册
或者
登录
后发表评论