Skip to content
项目
群组
代码片段
帮助
正在加载...
帮助
为 GitLab 提交贡献
登录/注册
切换导航
H
h2database
项目
项目
详情
活动
周期分析
仓库
仓库
文件
提交
分支
标签
贡献者
分枝图
比较
统计图
议题
0
议题
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
CI / CD
CI / CD
流水线
作业
计划
统计图
Wiki
Wiki
代码片段
代码片段
成员
成员
折叠边栏
关闭边栏
活动
分枝图
统计图
创建新议题
作业
提交
议题看板
打开侧边栏
Administrator
h2database
Commits
70ef2e60
提交
70ef2e60
authored
14 年前
作者:
noelgrandin@gmail.com
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
add support for IF NOT EXISTS in ALTER TABLE
上级
e9571b3c
master
noel-pr1
plus33-master
pr/267
stumc-Issue#576
version-1.4.198
version-1.4.197
version-1.4.196
version-1.4.195
version-1.4.194
version-1.4.193
version-1.4.192
version-1.4.191
version-1.4.190
version-1.4.188
version-1.4.187
version-1.4.186
version-1.4.185
version-1.4.184
version-1.4.183
version-1.4.182
version-1.4.181
version-1.4.178
version-1.4.177
version-1.3
version-1.2
version-1.1
version-1.0
无相关合并请求
隐藏空白字符变更
内嵌
并排
正在显示
9 个修改的文件
包含
43 行增加
和
6 行删除
+43
-6
help.csv
h2/src/docsrc/help/help.csv
+1
-1
changelog.html
h2/src/docsrc/html/changelog.html
+1
-0
roadmap.html
h2/src/docsrc/html/roadmap.html
+0
-1
CommandInterface.java
h2/src/main/org/h2/command/CommandInterface.java
+5
-0
Parser.java
h2/src/main/org/h2/command/Parser.java
+2
-1
AlterTableAlterColumn.java
h2/src/main/org/h2/command/ddl/AlterTableAlterColumn.java
+12
-2
help.csv
h2/src/main/org/h2/res/help.csv
+1
-1
Table.java
h2/src/main/org/h2/table/Table.java
+10
-0
TestAlter.java
h2/src/test/org/h2/test/db/TestAlter.java
+11
-0
没有找到文件。
h2/src/docsrc/help/help.csv
浏览文件 @
70ef2e60
...
...
@@ -208,7 +208,7 @@ ALTER SEQUENCE SEQ_ID RESTART WITH 1000
"
"Commands (DDL)","ALTER TABLE ADD","
ALTER TABLE tableName ADD name dataType [ DEFAULT expression ]
ALTER TABLE tableName ADD
[ IF NOT EXISTS ]
name dataType [ DEFAULT expression ]
[ [ NOT ] NULL ] [ AUTO_INCREMENT | IDENTITY ] [ BEFORE columnName ]
","
Adds a new column to a table.
...
...
This diff is collapsed.
Click to expand it.
h2/src/docsrc/html/changelog.html
浏览文件 @
70ef2e60
...
...
@@ -34,6 +34,7 @@ Change Log
</li><li>
Linked tables: the index conditions was sometimes not used when querying the remote database.
</li><li>
Issue 294: OSGi: the versions were missing in manifest package exports.
</li><li>
The option -baseDir didn't work with symbolic links.
</li><li>
Support for ALTER TABLE ADD COLUMN IF NOT EXISTS.
</li><li>
Database-level connection settings could only be set in the database URL,
but not using the Properties parameter of DriverManager.getConnection(String url, Properties info).
</li></ul>
...
...
This diff is collapsed.
Click to expand it.
h2/src/docsrc/html/roadmap.html
浏览文件 @
70ef2e60
...
...
@@ -505,7 +505,6 @@ See also <a href="build.html#providing_patches">Providing Patches</a>.
disable autocommit for all connections.
</li><li>
Compatibility with MS Access: support "
&
" to concatenate text.
</li><li>
The BACKUP statement should not synchronize on the database, and therefore should not block other users.
</li><li>
Support ALTER TABLE ADD COLUMN IF NOT EXISTS.
</li><li>
Document the database file format.
</li><li>
Support reading LOBs.
</li><li>
Require appending DANGEROUS=TRUE when using certain dangerous settings such as
...
...
This diff is collapsed.
Click to expand it.
h2/src/main/org/h2/command/CommandInterface.java
浏览文件 @
70ef2e60
...
...
@@ -447,6 +447,11 @@ public interface CommandInterface {
*/
int
SHUTDOWN_DEFRAG
=
84
;
/**
* The type of a ALTER TABLE ADD IF NOT EXISTS statement.
*/
int
ALTER_TABLE_ADD_COLUMN_IF_NOT_EXISTS
=
85
;
/**
* Get command type.
*
...
...
This diff is collapsed.
Click to expand it.
h2/src/main/org/h2/command/Parser.java
浏览文件 @
70ef2e60
...
...
@@ -4778,9 +4778,10 @@ public class Parser {
private
AlterTableAlterColumn
parseAlterTableAddColumn
(
Table
table
)
{
readIf
(
"COLUMN"
);
boolean
ifNotExists
=
readIfNoExists
();
Schema
schema
=
table
.
getSchema
();
AlterTableAlterColumn
command
=
new
AlterTableAlterColumn
(
session
,
schema
);
command
.
setType
(
CommandInterface
.
ALTER_TABLE_ADD_COLUMN
);
command
.
setType
(
ifNotExists
?
CommandInterface
.
ALTER_TABLE_ADD_COLUMN_IF_NOT_EXISTS
:
CommandInterface
.
ALTER_TABLE_ADD_COLUMN
);
command
.
setTable
(
table
);
String
columnName
=
readColumnIdentifier
();
Column
column
=
parseColumnForTable
(
columnName
,
true
);
...
...
This diff is collapsed.
Click to expand it.
h2/src/main/org/h2/command/ddl/AlterTableAlterColumn.java
浏览文件 @
70ef2e60
...
...
@@ -35,6 +35,7 @@ import org.h2.util.New;
/**
* This class represents the statements
* ALTER TABLE ADD,
* ALTER TABLE ADD IF NOT EXISTS,
* ALTER TABLE ALTER COLUMN,
* ALTER TABLE ALTER COLUMN RESTART,
* ALTER TABLE ALTER COLUMN SELECTIVITY,
...
...
@@ -122,6 +123,13 @@ public class AlterTableAlterColumn extends SchemaCommand {
copyData
();
break
;
}
case
CommandInterface
.
ALTER_TABLE_ADD_COLUMN_IF_NOT_EXISTS
:
{
if
(!
table
.
doesColumnExist
(
newColumn
.
getName
()))
{
convertAutoIncrementColumn
(
newColumn
);
copyData
();
}
break
;
}
case
CommandInterface
.
ALTER_TABLE_DROP_COLUMN
:
{
if
(
table
.
getColumns
().
length
==
1
)
{
throw
DbException
.
get
(
ErrorCode
.
CANNOT_DROP_LAST_COLUMN
,
oldColumn
.
getSQL
());
...
...
@@ -216,7 +224,8 @@ public class AlterTableAlterColumn extends SchemaCommand {
if
(
type
==
CommandInterface
.
ALTER_TABLE_DROP_COLUMN
)
{
int
position
=
oldColumn
.
getColumnId
();
newColumns
.
remove
(
position
);
}
else
if
(
type
==
CommandInterface
.
ALTER_TABLE_ADD_COLUMN
)
{
}
else
if
(
type
==
CommandInterface
.
ALTER_TABLE_ADD_COLUMN
||
type
==
CommandInterface
.
ALTER_TABLE_ADD_COLUMN_IF_NOT_EXISTS
)
{
int
position
;
if
(
addBefore
==
null
)
{
position
=
columns
.
length
;
...
...
@@ -254,7 +263,8 @@ public class AlterTableAlterColumn extends SchemaCommand {
if
(
columnList
.
length
()
>
0
)
{
columnList
.
append
(
", "
);
}
if
(
type
==
CommandInterface
.
ALTER_TABLE_ADD_COLUMN
&&
nc
==
newColumn
)
{
if
((
type
==
CommandInterface
.
ALTER_TABLE_ADD_COLUMN
||
type
==
CommandInterface
.
ALTER_TABLE_ADD_COLUMN_IF_NOT_EXISTS
)
&&
nc
==
newColumn
)
{
Expression
def
=
nc
.
getDefaultExpression
();
columnList
.
append
(
def
==
null
?
"NULL"
:
def
.
getSQL
());
}
else
{
...
...
This diff is collapsed.
Click to expand it.
h2/src/main/org/h2/res/help.csv
浏览文件 @
70ef2e60
...
...
@@ -76,7 +76,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 name dataType [ DEFAULT expression ]
ALTER TABLE tableName ADD
[ IF NOT EXISTS ]
name dataType [ DEFAULT expression ]
[ [ NOT ] NULL ] [ AUTO_INCREMENT | IDENTITY ] [ BEFORE columnName ]
","
Adds a new column to a table."
...
...
This diff is collapsed.
Click to expand it.
h2/src/main/org/h2/table/Table.java
浏览文件 @
70ef2e60
...
...
@@ -589,6 +589,16 @@ public abstract class Table extends SchemaObjectBase {
return
column
;
}
/**
* Does the column with the given name exist?
*
* @param columnName the column name
* @return true if the column exists
*/
public
boolean
doesColumnExist
(
String
columnName
)
{
return
columnMap
.
containsKey
(
columnName
);
}
/**
* Get the best plan for the given search mask.
*
...
...
This diff is collapsed.
Click to expand it.
h2/src/test/org/h2/test/db/TestAlter.java
浏览文件 @
70ef2e60
...
...
@@ -38,6 +38,7 @@ public class TestAlter extends TestBase {
testAlterTableDropColumnWithReferences
();
testAlterTableAlterColumn
();
testAlterTableDropIdentityColumn
();
testAlterTableAddColumnIfNotExists
();
conn
.
close
();
deleteDb
(
"alter"
);
}
...
...
@@ -123,4 +124,14 @@ public class TestAlter extends TestBase {
stat
.
execute
(
"drop table t"
);
}
private
void
testAlterTableAddColumnIfNotExists
()
throws
SQLException
{
stat
.
execute
(
"create table t(x varchar) as select 'x'"
);
stat
.
execute
(
"alter table t add if not exists x int"
);
stat
.
execute
(
"drop table t"
);
stat
.
execute
(
"create table t(x varchar) as select 'x'"
);
stat
.
execute
(
"alter table t add if not exists y int"
);
stat
.
execute
(
"select x, y from t"
);
stat
.
execute
(
"drop table t"
);
}
}
This diff is collapsed.
Click to expand it.
编写
预览
Markdown
格式
0%
重试
或
添加新文件
添加附件
取消
您添加了
0
人
到此讨论。请谨慎行事。
请先完成此评论的编辑!
取消
请
注册
或者
登录
后发表评论