Skip to content
项目
群组
代码片段
帮助
正在加载...
帮助
为 GitLab 提交贡献
登录/注册
切换导航
H
h2database
项目
项目
详情
活动
周期分析
仓库
仓库
文件
提交
分支
标签
贡献者
分枝图
比较
统计图
议题
0
议题
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
CI / CD
CI / CD
流水线
作业
计划
统计图
Wiki
Wiki
代码片段
代码片段
成员
成员
折叠边栏
关闭边栏
活动
分枝图
统计图
创建新议题
作业
提交
议题看板
打开侧边栏
Administrator
h2database
Commits
9d53c2d0
提交
9d53c2d0
authored
12月 12, 2012
作者:
noelgrandin
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
support ALTER TABLE ADD ... AFTER.
Patch from Andrew Gaul argaul@gmail.com Fixes issue 401.
上级
9ab2a6b4
显示空白字符变更
内嵌
并排
正在显示
5 个修改的文件
包含
45 行增加
和
4 行删除
+45
-4
changelog.html
h2/src/docsrc/html/changelog.html
+1
-0
Parser.java
h2/src/main/org/h2/command/Parser.java
+2
-0
AlterTableAlterColumn.java
h2/src/main/org/h2/command/ddl/AlterTableAlterColumn.java
+10
-3
help.csv
h2/src/main/org/h2/res/help.csv
+1
-1
TestAlter.java
h2/src/test/org/h2/test/db/TestAlter.java
+31
-0
没有找到文件。
h2/src/docsrc/html/changelog.html
浏览文件 @
9d53c2d0
...
...
@@ -24,6 +24,7 @@ Change Log
</li><li>
MVStore: unified exception handling; the version is included in the messages.
</li><li>
MVStore: old data is now retained for 45 seconds by default.
</ul><li>
MVStore: compress is now disabled by default, and can be enabled on request.
</ul><li>
Support ALTER TABLE ADD ... AFTER. Patch from Andrew Gaul argaul@gmail.com. Fixes issue 401.
</li></ul>
<h2>
Version 1.3.170 (2012-11-30)
</h2>
...
...
h2/src/main/org/h2/command/Parser.java
浏览文件 @
9d53c2d0
...
...
@@ -4987,6 +4987,8 @@ public class Parser {
columnsToAdd
.
add
(
column
);
if
(
readIf
(
"BEFORE"
))
{
command
.
setAddBefore
(
readColumnIdentifier
());
}
else
if
(
readIf
(
"AFTER"
))
{
command
.
setAddAfter
(
readColumnIdentifier
());
}
}
command
.
setNewColumns
(
columnsToAdd
);
...
...
h2/src/main/org/h2/command/ddl/AlterTableAlterColumn.java
浏览文件 @
9d53c2d0
...
...
@@ -54,6 +54,7 @@ public class AlterTableAlterColumn extends SchemaCommand {
private
Expression
defaultExpression
;
private
Expression
newSelectivity
;
private
String
addBefore
;
private
String
addAfter
;
private
boolean
ifNotExists
;
private
ArrayList
<
Column
>
columnsToAdd
;
...
...
@@ -73,6 +74,10 @@ public class AlterTableAlterColumn extends SchemaCommand {
this
.
addBefore
=
before
;
}
public
void
setAddAfter
(
String
after
)
{
this
.
addAfter
=
after
;
}
public
int
update
()
{
session
.
commit
(
true
);
Database
db
=
session
.
getDatabase
();
...
...
@@ -270,10 +275,12 @@ public class AlterTableAlterColumn extends SchemaCommand {
newColumns
.
remove
(
position
);
}
else
if
(
type
==
CommandInterface
.
ALTER_TABLE_ADD_COLUMN
)
{
int
position
;
if
(
addBefore
==
null
)
{
position
=
columns
.
length
;
}
else
{
if
(
addBefore
!=
null
)
{
position
=
table
.
getColumn
(
addBefore
).
getColumnId
();
}
else
if
(
addAfter
!=
null
)
{
position
=
table
.
getColumn
(
addAfter
).
getColumnId
()
+
1
;
}
else
{
position
=
columns
.
length
;
}
for
(
Column
column
:
columnsToAdd
)
{
newColumns
.
add
(
position
++,
column
);
...
...
h2/src/main/org/h2/res/help.csv
浏览文件 @
9d53c2d0
...
...
@@ -80,7 +80,7 @@ ALTER SEQUENCE sequenceName [ RESTART WITH long ] [ INCREMENT BY long ]
Changes the next value and the increment of a sequence."
"Commands (DDL)","ALTER TABLE ADD","
ALTER TABLE tableName ADD [ COLUMN ]
{ [ IF NOT EXISTS ] columnDefinition [ BEFORE columnName ]
{ [ IF NOT EXISTS ] columnDefinition [ BEFORE columnName
| AFTER columnName
]
| ( { columnDefinition } [,...] ) }
","
Adds a new column to a table."
...
...
h2/src/test/org/h2/test/db/TestAlter.java
浏览文件 @
9d53c2d0
...
...
@@ -7,6 +7,7 @@
package
org
.
h2
.
test
.
db
;
import
java.sql.Connection
;
import
java.sql.DatabaseMetaData
;
import
java.sql.ResultSet
;
import
java.sql.SQLException
;
import
java.sql.Statement
;
...
...
@@ -42,6 +43,8 @@ public class TestAlter extends TestBase {
testAlterTableAddColumnIfNotExists
();
testAlterTableAddMultipleColumns
();
testAlterTableAlterColumn2
();
testAlterTableAddColumnBefore
();
testAlterTableAddColumnAfter
();
conn
.
close
();
deleteDb
(
"alter"
);
}
...
...
@@ -146,6 +149,34 @@ public class TestAlter extends TestBase {
stat
.
execute
(
"drop table t"
);
}
// column and field names must be upper-case due to getMetaData sensitivity
private
void
testAlterTableAddColumnBefore
()
throws
SQLException
{
stat
.
execute
(
"create table T(X varchar)"
);
stat
.
execute
(
"alter table T add Y int before X"
);
DatabaseMetaData
dbmeta
=
conn
.
getMetaData
();
ResultSet
rs
=
dbmeta
.
getColumns
(
null
,
null
,
"T"
,
null
);
assertTrue
(
rs
.
next
());
assertEquals
(
"Y"
,
rs
.
getString
(
"COLUMN_NAME"
));
assertTrue
(
rs
.
next
());
assertEquals
(
"X"
,
rs
.
getString
(
"COLUMN_NAME"
));
assertFalse
(
rs
.
next
());
stat
.
execute
(
"drop table T"
);
}
// column and field names must be upper-case due to getMetaData sensitivity
private
void
testAlterTableAddColumnAfter
()
throws
SQLException
{
stat
.
execute
(
"create table T(X varchar)"
);
stat
.
execute
(
"alter table T add Y int after X"
);
DatabaseMetaData
dbmeta
=
conn
.
getMetaData
();
ResultSet
rs
=
dbmeta
.
getColumns
(
null
,
null
,
"T"
,
null
);
assertTrue
(
rs
.
next
());
assertEquals
(
"X"
,
rs
.
getString
(
"COLUMN_NAME"
));
assertTrue
(
rs
.
next
());
assertEquals
(
"Y"
,
rs
.
getString
(
"COLUMN_NAME"
));
assertFalse
(
rs
.
next
());
stat
.
execute
(
"drop table T"
);
}
private
void
testAlterTableAlterColumn2
()
throws
SQLException
{
// ensure that increasing a VARCHAR columns length takes effect because
// we optimize this case
...
...
编写
预览
Markdown
格式
0%
重试
或
添加新文件
添加附件
取消
您添加了
0
人
到此讨论。请谨慎行事。
请先完成此评论的编辑!
取消
请
注册
或者
登录
后发表评论