Skip to content
项目
群组
代码片段
帮助
正在加载...
帮助
为 GitLab 提交贡献
登录/注册
切换导航
H
h2database
项目
项目
详情
活动
周期分析
仓库
仓库
文件
提交
分支
标签
贡献者
分枝图
比较
统计图
议题
0
议题
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
CI / CD
CI / CD
流水线
作业
计划
统计图
Wiki
Wiki
代码片段
代码片段
成员
成员
折叠边栏
关闭边栏
活动
分枝图
统计图
创建新议题
作业
提交
议题看板
打开侧边栏
Administrator
h2database
Commits
8acef7b9
提交
8acef7b9
authored
13 年前
作者:
Thomas Mueller
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Source code formatting.
上级
7ac42788
隐藏空白字符变更
内嵌
并排
正在显示
1 个修改的文件
包含
66 行增加
和
66 行删除
+66
-66
AlterTableAlterColumn.java
h2/src/main/org/h2/command/ddl/AlterTableAlterColumn.java
+66
-66
没有找到文件。
h2/src/main/org/h2/command/ddl/AlterTableAlterColumn.java
浏览文件 @
8acef7b9
...
...
@@ -89,83 +89,83 @@ public class AlterTableAlterColumn extends SchemaCommand {
}
}
switch
(
type
)
{
case
CommandInterface
.
ALTER_TABLE_ALTER_COLUMN_NOT_NULL
:
{
if
(!
oldColumn
.
isNullable
())
{
// no change
break
;
}
checkNoNullValues
();
oldColumn
.
setNullable
(
false
);
db
.
update
(
session
,
table
);
case
CommandInterface
.
ALTER_TABLE_ALTER_COLUMN_NOT_NULL
:
{
if
(!
oldColumn
.
isNullable
())
{
// no change
break
;
}
c
ase
CommandInterface
.
ALTER_TABLE_ALTER_COLUMN_NULL
:
{
if
(
oldColumn
.
isNullable
())
{
// no change
break
;
}
checkNullable
();
oldColumn
.
setNullable
(
true
);
db
.
update
(
session
,
table
);
c
heckNoNullValues
();
oldColumn
.
setNullable
(
false
);
db
.
update
(
session
,
table
);
break
;
}
case
CommandInterface
.
ALTER_TABLE_ALTER_COLUMN_NULL
:
{
if
(
oldColumn
.
isNullable
())
{
// no change
break
;
}
case
CommandInterface
.
ALTER_TABLE_ALTER_COLUMN_DEFAULT
:
{
checkDefaultReferencesTable
(
defaultExpression
);
oldColumn
.
setSequence
(
null
);
oldColumn
.
setDefaultExpression
(
session
,
defaultExpression
);
removeSequence
(
sequence
);
checkNullable
();
oldColumn
.
setNullable
(
true
);
db
.
update
(
session
,
table
);
break
;
}
case
CommandInterface
.
ALTER_TABLE_ALTER_COLUMN_DEFAULT
:
{
checkDefaultReferencesTable
(
defaultExpression
);
oldColumn
.
setSequence
(
null
);
oldColumn
.
setDefaultExpression
(
session
,
defaultExpression
);
removeSequence
(
sequence
);
db
.
update
(
session
,
table
);
break
;
}
case
CommandInterface
.
ALTER_TABLE_ALTER_COLUMN_CHANGE_TYPE
:
{
// if the change is only increasing the precision, then we don't
// need to copy the table because the length is only a constraint,
// and does not affect the storage structure.
if
(
oldColumn
.
isWideningConversion
(
newColumn
))
{
convertAutoIncrementColumn
(
newColumn
);
oldColumn
.
copy
(
newColumn
);
db
.
update
(
session
,
table
);
break
;
}
case
CommandInterface
.
ALTER_TABLE_ALTER_COLUMN_CHANGE_TYPE
:
{
// if the change is only increasing the precision, then we don't
// need to copy the table because the length is only a constraint,
// and does not affect the storage structure.
if
(
oldColumn
.
isWideningConversion
(
newColumn
))
{
convertAutoIncrementColumn
(
newColumn
);
oldColumn
.
copy
(
newColumn
);
db
.
update
(
session
,
table
);
}
else
{
oldColumn
.
setSequence
(
null
);
oldColumn
.
setDefaultExpression
(
session
,
null
);
oldColumn
.
setConvertNullToDefault
(
false
);
if
(
oldColumn
.
isNullable
()
&&
!
newColumn
.
isNullable
())
{
checkNoNullValues
();
}
else
if
(!
oldColumn
.
isNullable
()
&&
newColumn
.
isNullable
())
{
checkNullable
();
}
convertAutoIncrementColumn
(
newColumn
);
copyData
();
}
break
;
}
case
CommandInterface
.
ALTER_TABLE_ADD_COLUMN
:
{
// ifNotExists only supported for single column add
if
(
ifNotExists
&&
columnsToAdd
.
size
()
==
1
&&
table
.
doesColumnExist
(
columnsToAdd
.
get
(
0
).
getName
()))
{
break
;
}
for
(
Column
column
:
columnsToAdd
)
{
convertAutoIncrementColumn
(
column
);
}
else
{
oldColumn
.
setSequence
(
null
);
oldColumn
.
setDefaultExpression
(
session
,
null
);
oldColumn
.
setConvertNullToDefault
(
false
);
if
(
oldColumn
.
isNullable
()
&&
!
newColumn
.
isNullable
())
{
checkNoNullValues
();
}
else
if
(!
oldColumn
.
isNullable
()
&&
newColumn
.
isNullable
())
{
checkNullable
();
}
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
());
}
table
.
dropSingleColumnConstraintsAndIndexes
(
session
,
oldColumn
);
copyData
();
break
;
}
case
CommandInterface
.
ALTER_TABLE_ADD_COLUMN
:
{
// ifNotExists only supported for single column add
if
(
ifNotExists
&&
columnsToAdd
.
size
()
==
1
&&
table
.
doesColumnExist
(
columnsToAdd
.
get
(
0
).
getName
()))
{
break
;
}
case
CommandInterface
.
ALTER_TABLE_ALTER_COLUMN_SELECTIVITY
:
{
int
value
=
newSelectivity
.
optimize
(
session
).
getValue
(
session
).
getInt
();
oldColumn
.
setSelectivity
(
value
);
db
.
update
(
session
,
table
);
break
;
for
(
Column
column
:
columnsToAdd
)
{
convertAutoIncrementColumn
(
column
);
}
default
:
DbException
.
throwInternalError
(
"type="
+
type
);
copyData
();
break
;
}
case
CommandInterface
.
ALTER_TABLE_DROP_COLUMN
:
{
if
(
table
.
getColumns
().
length
==
1
)
{
throw
DbException
.
get
(
ErrorCode
.
CANNOT_DROP_LAST_COLUMN
,
oldColumn
.
getSQL
());
}
table
.
dropSingleColumnConstraintsAndIndexes
(
session
,
oldColumn
);
copyData
();
break
;
}
case
CommandInterface
.
ALTER_TABLE_ALTER_COLUMN_SELECTIVITY
:
{
int
value
=
newSelectivity
.
optimize
(
session
).
getValue
(
session
).
getInt
();
oldColumn
.
setSelectivity
(
value
);
db
.
update
(
session
,
table
);
break
;
}
default
:
DbException
.
throwInternalError
(
"type="
+
type
);
}
return
0
;
}
...
...
This diff is collapsed.
Click to expand it.
编写
预览
Markdown
格式
0%
重试
或
添加新文件
添加附件
取消
您添加了
0
人
到此讨论。请谨慎行事。
请先完成此评论的编辑!
取消
请
注册
或者
登录
后发表评论