Skip to content
项目
群组
代码片段
帮助
正在加载...
帮助
为 GitLab 提交贡献
登录/注册
切换导航
H
h2database
项目
项目
详情
活动
周期分析
仓库
仓库
文件
提交
分支
标签
贡献者
分枝图
比较
统计图
议题
0
议题
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
CI / CD
CI / CD
流水线
作业
计划
统计图
Wiki
Wiki
代码片段
代码片段
成员
成员
折叠边栏
关闭边栏
活动
分枝图
统计图
创建新议题
作业
提交
议题看板
打开侧边栏
Administrator
h2database
Commits
9c26bbb3
提交
9c26bbb3
authored
11月 15, 2008
作者:
Thomas Mueller
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
ALTER TABLE ALTER COLUMN could throw the wrong exception.
上级
96341778
隐藏空白字符变更
内嵌
并排
正在显示
6 个修改的文件
包含
84 行增加
和
25 行删除
+84
-25
changelog.html
h2/src/docsrc/html/changelog.html
+3
-1
AlterTableAlterColumn.java
h2/src/main/org/h2/command/ddl/AlterTableAlterColumn.java
+1
-20
Database.java
h2/src/main/org/h2/engine/Database.java
+14
-3
Table.java
h2/src/main/org/h2/table/Table.java
+5
-1
TestAll.java
h2/src/test/org/h2/test/TestAll.java
+2
-0
TestAlter.java
h2/src/test/org/h2/test/db/TestAlter.java
+59
-0
没有找到文件。
h2/src/docsrc/html/changelog.html
浏览文件 @
9c26bbb3
...
@@ -18,7 +18,9 @@ Change Log
...
@@ -18,7 +18,9 @@ Change Log
<h1>
Change Log
</h1>
<h1>
Change Log
</h1>
<h2>
Next Version (unreleased)
</h2>
<h2>
Next Version (unreleased)
</h2>
<ul><li>
Updatable result sets: the key columns can now be updated.
<ul><li>
ALTER TABLE ALTER COLUMN could throw the wrong exception in the last version
(Table not found).
</li><li>
Updatable result sets: the key columns can now be updated.
</li><li>
The H2DatabaseProvider for ActiveObjects is now included in the tools section.
</li><li>
The H2DatabaseProvider for ActiveObjects is now included in the tools section.
</li><li>
The H2Platform for Oracle Toplink Essential has been improved a bit.
</li><li>
The H2Platform for Oracle Toplink Essential has been improved a bit.
</li><li>
The Windows service to start H2 didn't work in version 1.1.
</li><li>
The Windows service to start H2 didn't work in version 1.1.
...
...
h2/src/main/org/h2/command/ddl/AlterTableAlterColumn.java
浏览文件 @
9c26bbb3
...
@@ -267,13 +267,7 @@ public class AlterTableAlterColumn extends SchemaCommand {
...
@@ -267,13 +267,7 @@ public class AlterTableAlterColumn extends SchemaCommand {
buff
.
append
(
" FROM "
);
buff
.
append
(
" FROM "
);
buff
.
append
(
table
.
getSQL
());
buff
.
append
(
table
.
getSQL
());
String
newTableSQL
=
buff
.
toString
();
String
newTableSQL
=
buff
.
toString
();
try
{
execute
(
newTableSQL
,
true
);
execute
(
newTableSQL
,
true
);
}
catch
(
SQLException
e
)
{
unlinkSequences
(
newTable
);
execute
(
"DROP TABLE "
+
newTable
.
getSQL
(),
true
);
throw
e
;
}
newTable
=
(
TableData
)
newTable
.
getSchema
().
getTableOrView
(
session
,
newTable
.
getName
());
newTable
=
(
TableData
)
newTable
.
getSchema
().
getTableOrView
(
session
,
newTable
.
getName
());
ObjectArray
children
=
table
.
getChildren
();
ObjectArray
children
=
table
.
getChildren
();
ObjectArray
triggers
=
new
ObjectArray
();
ObjectArray
triggers
=
new
ObjectArray
();
...
@@ -347,19 +341,6 @@ public class AlterTableAlterColumn extends SchemaCommand {
...
@@ -347,19 +341,6 @@ public class AlterTableAlterColumn extends SchemaCommand {
}
}
}
}
private
void
unlinkSequences
(
Table
table
)
{
Column
[]
columns
=
table
.
getColumns
();
for
(
int
i
=
0
;
i
<
columns
.
length
;
i
++)
{
// if we don't do that, the sequence is dropped when the table is
// dropped
Sequence
seq
=
columns
[
i
].
getSequence
();
if
(
seq
!=
null
)
{
table
.
removeSequence
(
session
,
seq
);
columns
[
i
].
setSequence
(
null
);
}
}
}
private
void
execute
(
String
sql
,
boolean
ddl
)
throws
SQLException
{
private
void
execute
(
String
sql
,
boolean
ddl
)
throws
SQLException
{
Prepared
command
=
session
.
prepare
(
sql
);
Prepared
command
=
session
.
prepare
(
sql
);
command
.
update
();
command
.
update
();
...
...
h2/src/main/org/h2/engine/Database.java
浏览文件 @
9c26bbb3
...
@@ -1528,7 +1528,14 @@ public class Database implements DataHandler {
...
@@ -1528,7 +1528,14 @@ public class Database implements DataHandler {
removeMeta
(
session
,
id
);
removeMeta
(
session
,
id
);
}
}
private
String
getDependentObject
(
SchemaObject
obj
)
{
/**
* Get the first table that depends on this object.
*
* @param obj the object to find
* @param except the table to exclude (or null)
* @return the first dependent table, or null
*/
public
Table
getDependentTable
(
SchemaObject
obj
,
Table
except
)
{
switch
(
obj
.
getType
())
{
switch
(
obj
.
getType
())
{
case
DbObject
.
COMMENT
:
case
DbObject
.
COMMENT
:
case
DbObject
.
CONSTRAINT
:
case
DbObject
.
CONSTRAINT
:
...
@@ -1543,10 +1550,13 @@ public class Database implements DataHandler {
...
@@ -1543,10 +1550,13 @@ public class Database implements DataHandler {
HashSet
set
=
new
HashSet
();
HashSet
set
=
new
HashSet
();
for
(
int
i
=
0
;
i
<
list
.
size
();
i
++)
{
for
(
int
i
=
0
;
i
<
list
.
size
();
i
++)
{
Table
t
=
(
Table
)
list
.
get
(
i
);
Table
t
=
(
Table
)
list
.
get
(
i
);
if
(
except
==
t
)
{
continue
;
}
set
.
clear
();
set
.
clear
();
t
.
addDependencies
(
set
);
t
.
addDependencies
(
set
);
if
(
set
.
contains
(
obj
))
{
if
(
set
.
contains
(
obj
))
{
return
t
.
getSQL
()
;
return
t
;
}
}
}
}
return
null
;
return
null
;
...
@@ -1595,7 +1605,8 @@ public class Database implements DataHandler {
...
@@ -1595,7 +1605,8 @@ public class Database implements DataHandler {
obj
.
getSchema
().
remove
(
obj
);
obj
.
getSchema
().
remove
(
obj
);
String
invalid
;
String
invalid
;
if
(
SysProperties
.
OPTIMIZE_DROP_DEPENDENCIES
)
{
if
(
SysProperties
.
OPTIMIZE_DROP_DEPENDENCIES
)
{
invalid
=
getDependentObject
(
obj
);
Table
t
=
getDependentTable
(
obj
,
null
);
invalid
=
t
==
null
?
null
:
t
.
getSQL
();
}
else
{
}
else
{
invalid
=
getFirstInvalidTable
(
session
);
invalid
=
getFirstInvalidTable
(
session
);
}
}
...
...
h2/src/main/org/h2/table/Table.java
浏览文件 @
9c26bbb3
...
@@ -404,7 +404,11 @@ public abstract class Table extends SchemaObjectBase {
...
@@ -404,7 +404,11 @@ public abstract class Table extends SchemaObjectBase {
Sequence
sequence
=
(
Sequence
)
sequences
.
get
(
0
);
Sequence
sequence
=
(
Sequence
)
sequences
.
get
(
0
);
sequences
.
remove
(
0
);
sequences
.
remove
(
0
);
if
(!
getTemporary
())
{
if
(!
getTemporary
())
{
database
.
removeSchemaObject
(
session
,
sequence
);
// only remove if no other table depends on this sequence
// this is possible when calling ALTER TABLE ALTER COLUMN
if
(
database
.
getDependentTable
(
sequence
,
this
)
==
null
)
{
database
.
removeSchemaObject
(
session
,
sequence
);
}
}
}
}
}
}
}
...
...
h2/src/test/org/h2/test/TestAll.java
浏览文件 @
9c26bbb3
...
@@ -12,6 +12,7 @@ import java.util.Properties;
...
@@ -12,6 +12,7 @@ import java.util.Properties;
import
org.h2.engine.Constants
;
import
org.h2.engine.Constants
;
import
org.h2.store.fs.FileSystemDisk
;
import
org.h2.store.fs.FileSystemDisk
;
import
org.h2.test.bench.TestPerformance
;
import
org.h2.test.bench.TestPerformance
;
import
org.h2.test.db.TestAlter
;
import
org.h2.test.db.TestAutoRecompile
;
import
org.h2.test.db.TestAutoRecompile
;
import
org.h2.test.db.TestBackup
;
import
org.h2.test.db.TestBackup
;
import
org.h2.test.db.TestBigDb
;
import
org.h2.test.db.TestBigDb
;
...
@@ -499,6 +500,7 @@ http://www.w3schools.com/sql/
...
@@ -499,6 +500,7 @@ http://www.w3schools.com/sql/
// db
// db
new
TestScriptSimple
().
runTest
(
this
);
new
TestScriptSimple
().
runTest
(
this
);
new
TestScript
().
runTest
(
this
);
new
TestScript
().
runTest
(
this
);
new
TestAlter
().
runTest
(
this
);
new
TestAutoRecompile
().
runTest
(
this
);
new
TestAutoRecompile
().
runTest
(
this
);
new
TestBackup
().
runTest
(
this
);
new
TestBackup
().
runTest
(
this
);
new
TestBigDb
().
runTest
(
this
);
new
TestBigDb
().
runTest
(
this
);
...
...
h2/src/test/org/h2/test/db/TestAlter.java
0 → 100644
浏览文件 @
9c26bbb3
/*
* Copyright 2004-2008 H2 Group. Multiple-Licensed under the H2 License,
* Version 1.0, and under the Eclipse Public License, Version 1.0
* (http://h2database.com/html/license.html).
* Initial Developer: H2 Group
*/
package
org
.
h2
.
test
.
db
;
import
java.sql.Connection
;
import
java.sql.SQLException
;
import
java.sql.Statement
;
import
org.h2.constant.ErrorCode
;
import
org.h2.test.TestBase
;
/**
* Test ALTER statements.
*/
public
class
TestAlter
extends
TestBase
{
private
Connection
conn
;
private
Statement
stat
;
/**
* Run just this test.
*
* @param a ignored
*/
public
static
void
main
(
String
[]
a
)
throws
Exception
{
TestBase
.
createCaller
().
init
().
test
();
}
public
void
test
()
throws
Exception
{
deleteDb
(
"alter"
);
conn
=
getConnection
(
"alter"
);
stat
=
conn
.
createStatement
();
testAlterTableAlterColumn
();
conn
.
close
();
deleteDb
(
"alter"
);
}
private
void
testAlterTableAlterColumn
()
throws
SQLException
{
stat
.
execute
(
"create table t(x varchar) as select 'x'"
);
try
{
stat
.
execute
(
"alter table t alter column x int"
);
}
catch
(
SQLException
e
)
{
assertEquals
(
ErrorCode
.
DATA_CONVERSION_ERROR_1
,
e
.
getErrorCode
());
}
stat
.
execute
(
"drop table t"
);
stat
.
execute
(
"create table t(id identity, x varchar) as select null, 'x'"
);
try
{
stat
.
execute
(
"alter table t alter column x int"
);
}
catch
(
SQLException
e
)
{
assertEquals
(
ErrorCode
.
DATA_CONVERSION_ERROR_1
,
e
.
getErrorCode
());
}
stat
.
execute
(
"drop table t"
);
}
}
编写
预览
Markdown
格式
0%
重试
或
添加新文件
添加附件
取消
您添加了
0
人
到此讨论。请谨慎行事。
请先完成此评论的编辑!
取消
请
注册
或者
登录
后发表评论