Skip to content
项目
群组
代码片段
帮助
正在加载...
帮助
为 GitLab 提交贡献
登录/注册
切换导航
H
h2database
项目
项目
详情
活动
周期分析
仓库
仓库
文件
提交
分支
标签
贡献者
分枝图
比较
统计图
议题
0
议题
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
CI / CD
CI / CD
流水线
作业
计划
统计图
Wiki
Wiki
代码片段
代码片段
成员
成员
折叠边栏
关闭边栏
活动
分枝图
统计图
创建新议题
作业
提交
议题看板
打开侧边栏
Administrator
h2database
Commits
72f2deb4
提交
72f2deb4
authored
10月 31, 2008
作者:
Thomas Mueller
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
ALTER TABLE used a lot of memory when using multi-version concurrency.
上级
b6aa62b2
隐藏空白字符变更
内嵌
并排
正在显示
1 个修改的文件
包含
33 行增加
和
48 行删除
+33
-48
AlterTableAlterColumn.java
h2/src/main/org/h2/command/ddl/AlterTableAlterColumn.java
+33
-48
没有找到文件。
h2/src/main/org/h2/command/ddl/AlterTableAlterColumn.java
浏览文件 @
72f2deb4
...
...
@@ -239,11 +239,41 @@ public class AlterTableAlterColumn extends SchemaCommand {
// can't just use this table, because most column objects are 'shared'
// with the old table
// still need a new id because using 0 would mean: the new table tries
// to use the rows of the table 0 (the
script
table)
// to use the rows of the table 0 (the
meta
table)
int
id
=
-
1
;
TableData
newTable
=
getSchema
().
createTable
(
tempName
,
id
,
newColumns
,
persistent
,
false
);
newTable
.
setComment
(
table
.
getComment
());
execute
(
newTable
.
getCreateSQL
(),
true
);
StringBuffer
buff
=
new
StringBuffer
(
newTable
.
getCreateSQL
());
StringBuffer
columnList
=
new
StringBuffer
();
for
(
int
i
=
0
;
i
<
newColumns
.
size
();
i
++)
{
Column
nc
=
(
Column
)
newColumns
.
get
(
i
);
if
(
columnList
.
length
()
>
0
)
{
columnList
.
append
(
", "
);
}
if
(
type
==
ADD
&&
nc
==
newColumn
)
{
Expression
def
=
nc
.
getDefaultExpression
();
columnList
.
append
(
def
==
null
?
"NULL"
:
def
.
getSQL
());
}
else
{
columnList
.
append
(
nc
.
getSQL
());
}
}
buff
.
append
(
" AS SELECT "
);
if
(
columnList
.
length
()
==
0
)
{
// special case insert into test select * from test
buff
.
append
(
"*"
);
}
else
{
buff
.
append
(
columnList
);
}
buff
.
append
(
" FROM "
);
buff
.
append
(
table
.
getSQL
());
String
newTableSQL
=
buff
.
toString
();
try
{
execute
(
newTableSQL
,
true
);
}
catch
(
SQLException
e
)
{
unlinkSequences
(
newTable
);
execute
(
"DROP TABLE "
+
newTable
.
getSQL
(),
true
);
throw
e
;
}
newTable
=
(
TableData
)
newTable
.
getSchema
().
getTableOrView
(
session
,
newTable
.
getName
());
ObjectArray
children
=
table
.
getChildren
();
ObjectArray
triggers
=
new
ObjectArray
();
...
...
@@ -283,51 +313,6 @@ public class AlterTableAlterColumn extends SchemaCommand {
}
}
}
StringBuffer
columnList
=
new
StringBuffer
();
for
(
int
i
=
0
;
i
<
newColumns
.
size
();
i
++)
{
Column
nc
=
(
Column
)
newColumns
.
get
(
i
);
if
(
type
==
ADD
&&
nc
==
newColumn
)
{
continue
;
}
if
(
columnList
.
length
()
>
0
)
{
columnList
.
append
(
", "
);
}
columnList
.
append
(
nc
.
getSQL
());
}
// TODO loop instead of use insert (saves memory)
/*
*
* Index scan = table.getBestPlanItem(null).getIndex(); Cursor cursor =
* scan.find(null, null); while (cursor.next()) { Row row =
* cursor.get(); Row newRow = newTable.getTemplateRow(); for (int i=0,
* j=0; i<columns.length; i++) { if(i == position) { continue; }
* newRow.setValue(j++, row.getValue(i)); }
* newTable.validateAndConvert(newRow); newTable.addRow(newRow); }
*/
StringBuffer
buff
=
new
StringBuffer
();
buff
.
append
(
"INSERT INTO "
);
buff
.
append
(
newTable
.
getSQL
());
buff
.
append
(
"("
);
buff
.
append
(
columnList
);
buff
.
append
(
") SELECT "
);
if
(
columnList
.
length
()
==
0
)
{
// special case insert into test select * from test
buff
.
append
(
"*"
);
}
else
{
buff
.
append
(
columnList
);
}
buff
.
append
(
" FROM "
);
buff
.
append
(
table
.
getSQL
());
String
sql
=
buff
.
toString
();
newTable
.
setCheckForeignKeyConstraints
(
session
,
false
,
false
);
try
{
execute
(
sql
,
false
);
}
catch
(
SQLException
e
)
{
unlinkSequences
(
newTable
);
execute
(
"DROP TABLE "
+
newTable
.
getSQL
(),
true
);
throw
e
;
}
newTable
.
setCheckForeignKeyConstraints
(
session
,
true
,
false
);
String
tableName
=
table
.
getName
();
table
.
setModified
();
for
(
int
i
=
0
;
i
<
columns
.
length
;
i
++)
{
...
...
@@ -340,7 +325,7 @@ public class AlterTableAlterColumn extends SchemaCommand {
}
}
for
(
int
i
=
0
;
i
<
triggers
.
size
();
i
++)
{
sql
=
(
String
)
triggers
.
get
(
i
);
String
sql
=
(
String
)
triggers
.
get
(
i
);
execute
(
sql
,
true
);
}
execute
(
"DROP TABLE "
+
table
.
getSQL
(),
true
);
...
...
编写
预览
Markdown
格式
0%
重试
或
添加新文件
添加附件
取消
您添加了
0
人
到此讨论。请谨慎行事。
请先完成此评论的编辑!
取消
请
注册
或者
登录
后发表评论