Skip to content
项目
群组
代码片段
帮助
正在加载...
帮助
为 GitLab 提交贡献
登录/注册
切换导航
H
h2database
项目
项目
详情
活动
周期分析
仓库
仓库
文件
提交
分支
标签
贡献者
分枝图
比较
统计图
议题
0
议题
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
CI / CD
CI / CD
流水线
作业
计划
统计图
Wiki
Wiki
代码片段
代码片段
成员
成员
折叠边栏
关闭边栏
活动
分枝图
统计图
创建新议题
作业
提交
议题看板
打开侧边栏
Administrator
h2database
Commits
c9e8941a
提交
c9e8941a
authored
1月 30, 2012
作者:
Thomas Mueller
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
TriggerAdapter: in "before" triggers, values can be changed using the ResultSet.updateX methods.
上级
c34aff38
显示空白字符变更
内嵌
并排
正在显示
3 个修改的文件
包含
80 行增加
和
6 行删除
+80
-6
changelog.html
h2/src/docsrc/html/changelog.html
+8
-1
TriggerAdapter.java
h2/src/main/org/h2/tools/TriggerAdapter.java
+38
-1
TestTriggersConstraints.java
h2/src/test/org/h2/test/db/TestTriggersConstraints.java
+34
-4
没有找到文件。
h2/src/docsrc/html/changelog.html
浏览文件 @
c9e8941a
...
@@ -18,7 +18,14 @@ Change Log
...
@@ -18,7 +18,14 @@ Change Log
<h1>
Change Log
</h1>
<h1>
Change Log
</h1>
<h2>
Next Version (unreleased)
</h2>
<h2>
Next Version (unreleased)
</h2>
<ul><li>
The script created by SCRIPT DROP did not always work if multiple views
<ul><li>
TriggerAdapter: in "before" triggers, values can be changed using the ResultSet.updateX methods.
</li><li>
Creating a table with column data type NULL now works (even if not very useful).
</li><li>
ALTER TABLE ALTER COLUMN no longer copies the data for widening conversions
(for example if only the precision was increased) unless necessary.
</li><li>
Multi-threaded kernel: concurrently running an online backup
and updating the database resulted in a broken (transactionally incorrect)
backup file in some cases.
</li><li>
The script created by SCRIPT DROP did not always work if multiple views
existed that depend on each other.
existed that depend on each other.
</li><li>
MathUtils.getSecureRandom could log a warning to System.err in case
</li><li>
MathUtils.getSecureRandom could log a warning to System.err in case
the /dev/random is very slow, and the System.getProperties().toString()
the /dev/random is very slow, and the System.getProperties().toString()
...
...
h2/src/main/org/h2/tools/TriggerAdapter.java
浏览文件 @
c9e8941a
...
@@ -17,6 +17,33 @@ import org.h2.api.Trigger;
...
@@ -17,6 +17,33 @@ import org.h2.api.Trigger;
*/
*/
public
abstract
class
TriggerAdapter
implements
Trigger
{
public
abstract
class
TriggerAdapter
implements
Trigger
{
/**
* The schema name.
*/
protected
String
schemaName
;
/**
* The name of the trigger.
*/
protected
String
triggerName
;
/**
* The name of the table.
*/
protected
String
tableName
;
/**
* Whether the fire method is called before or after the operation is
* performed.
*/
protected
boolean
before
;
/**
* The trigger type: INSERT, UPDATE, DELETE, SELECT, or a combination (a bit
* field).
*/
protected
int
type
;
private
SimpleResultSet
oldResultSet
,
newResultSet
;
private
SimpleResultSet
oldResultSet
,
newResultSet
;
private
TriggerRowSource
oldSource
,
newSource
;
private
TriggerRowSource
oldSource
,
newSource
;
...
@@ -33,7 +60,8 @@ public abstract class TriggerAdapter implements Trigger {
...
@@ -33,7 +60,8 @@ public abstract class TriggerAdapter implements Trigger {
* @param tableName the name of the table
* @param tableName the name of the table
* @param before whether the fire method is called before or after the
* @param before whether the fire method is called before or after the
* operation is performed
* operation is performed
* @param type the operation type: INSERT, UPDATE, or DELETE
* @param type the operation type: INSERT, UPDATE, DELETE, SELECT, or a
* combination (this parameter is a bit field)
*/
*/
public
void
init
(
Connection
conn
,
String
schemaName
,
public
void
init
(
Connection
conn
,
String
schemaName
,
String
triggerName
,
String
tableName
,
String
triggerName
,
String
tableName
,
...
@@ -52,6 +80,11 @@ public abstract class TriggerAdapter implements Trigger {
...
@@ -52,6 +80,11 @@ public abstract class TriggerAdapter implements Trigger {
oldResultSet
.
addColumn
(
column
,
dataType
,
precision
,
scale
);
oldResultSet
.
addColumn
(
column
,
dataType
,
precision
,
scale
);
newResultSet
.
addColumn
(
column
,
dataType
,
precision
,
scale
);
newResultSet
.
addColumn
(
column
,
dataType
,
precision
,
scale
);
}
}
this
.
schemaName
=
schemaName
;
this
.
triggerName
=
triggerName
;
this
.
tableName
=
tableName
;
this
.
before
=
before
;
this
.
type
=
type
;
}
}
/**
/**
...
@@ -112,6 +145,10 @@ public abstract class TriggerAdapter implements Trigger {
...
@@ -112,6 +145,10 @@ public abstract class TriggerAdapter implements Trigger {
* fire(Connection conn, Object[] oldRow, Object[] newRow) method.
* fire(Connection conn, Object[] oldRow, Object[] newRow) method.
* ResultSet.next does not need to be called (and calling it has no effect;
* ResultSet.next does not need to be called (and calling it has no effect;
* it will always return true).
* it will always return true).
* <p>
* For "before" triggers, the new values of the new row may be changed
* using the ResultSet.updateX methods.
* </p>
*
*
* @param conn a connection to the database
* @param conn a connection to the database
* @param oldRow the old row, or null if no old row is available (for
* @param oldRow the old row, or null if no old row is available (for
...
...
h2/src/test/org/h2/test/db/TestTriggersConstraints.java
浏览文件 @
c9e8941a
...
@@ -121,19 +121,25 @@ public class TestTriggersConstraints extends TestBase implements Trigger {
...
@@ -121,19 +121,25 @@ public class TestTriggersConstraints extends TestBase implements Trigger {
stat
.
execute
(
"drop table if exists test"
);
stat
.
execute
(
"drop table if exists test"
);
stat
.
execute
(
"create table test(id int)"
);
stat
.
execute
(
"create table test(id int)"
);
stat
.
execute
(
"create table message(name varchar)"
);
stat
.
execute
(
"create table message(name varchar)"
);
stat
.
execute
(
"create trigger test_insert
after
insert, update, delete on test "
+
stat
.
execute
(
"create trigger test_insert
before
insert, update, delete on test "
+
"for each row call \""
+
TestTriggerAdapter
.
class
.
getName
()
+
"\""
);
"for each row call \""
+
TestTriggerAdapter
.
class
.
getName
()
+
"\""
);
stat
.
execute
(
"insert into test values(1)"
);
stat
.
execute
(
"insert into test values(1)"
);
ResultSet
rs
;
rs
=
stat
.
executeQuery
(
"select * from test"
);
rs
.
next
();
assertEquals
(
10
,
rs
.
getInt
(
1
));
stat
.
execute
(
"update test set id = 2"
);
stat
.
execute
(
"update test set id = 2"
);
rs
=
stat
.
executeQuery
(
"select * from test"
);
rs
.
next
();
assertEquals
(
20
,
rs
.
getInt
(
1
));
stat
.
execute
(
"delete from test"
);
stat
.
execute
(
"delete from test"
);
ResultSet
rs
;
rs
=
stat
.
executeQuery
(
"select * from message"
);
rs
=
stat
.
executeQuery
(
"select * from message"
);
assertTrue
(
rs
.
next
());
assertTrue
(
rs
.
next
());
assertEquals
(
"+1;"
,
rs
.
getString
(
1
));
assertEquals
(
"+1;"
,
rs
.
getString
(
1
));
assertTrue
(
rs
.
next
());
assertTrue
(
rs
.
next
());
assertEquals
(
"-1;+2;"
,
rs
.
getString
(
1
));
assertEquals
(
"-1
0
;+2;"
,
rs
.
getString
(
1
));
assertTrue
(
rs
.
next
());
assertTrue
(
rs
.
next
());
assertEquals
(
"-2;"
,
rs
.
getString
(
1
));
assertEquals
(
"-2
0
;"
,
rs
.
getString
(
1
));
assertFalse
(
rs
.
next
());
assertFalse
(
rs
.
next
());
stat
.
execute
(
"drop table test, message"
);
stat
.
execute
(
"drop table test, message"
);
conn
.
close
();
conn
.
close
();
...
@@ -182,6 +188,30 @@ public class TestTriggersConstraints extends TestBase implements Trigger {
...
@@ -182,6 +188,30 @@ public class TestTriggersConstraints extends TestBase implements Trigger {
if
(
newRow
!=
null
)
{
if
(
newRow
!=
null
)
{
buff
.
append
(
"+"
).
append
(
newRow
.
getString
(
"id"
)).
append
(
';'
);
buff
.
append
(
"+"
).
append
(
newRow
.
getString
(
"id"
)).
append
(
';'
);
}
}
if
(!
"TEST_INSERT"
.
equals
(
triggerName
))
{
throw
new
RuntimeException
(
"Wrong trigger name: "
+
triggerName
);
}
if
(!
"TEST"
.
equals
(
tableName
))
{
throw
new
RuntimeException
(
"Wrong table name: "
+
tableName
);
}
if
(!
"PUBLIC"
.
equals
(
schemaName
))
{
throw
new
RuntimeException
(
"Wrong schema name: "
+
schemaName
);
}
if
(
type
!=
(
Trigger
.
INSERT
|
Trigger
.
UPDATE
|
Trigger
.
DELETE
))
{
throw
new
RuntimeException
(
"Wrong type: "
+
type
);
}
if
(
newRow
!=
null
)
{
if
(
oldRow
==
null
)
{
if
(
newRow
.
getInt
(
1
)
!=
1
)
{
throw
new
RuntimeException
(
"Expected: 1 got: "
+
newRow
.
getString
(
1
));
}
}
else
{
if
(
newRow
.
getInt
(
1
)
!=
2
)
{
throw
new
RuntimeException
(
"Expected: 2 got: "
+
newRow
.
getString
(
1
));
}
}
newRow
.
updateInt
(
1
,
newRow
.
getInt
(
1
)
*
10
);
}
conn
.
createStatement
().
execute
(
"insert into message values('"
+
buff
.
toString
()
+
"')"
);
conn
.
createStatement
().
execute
(
"insert into message values('"
+
buff
.
toString
()
+
"')"
);
}
}
...
...
编写
预览
Markdown
格式
0%
重试
或
添加新文件
添加附件
取消
您添加了
0
人
到此讨论。请谨慎行事。
请先完成此评论的编辑!
取消
请
注册
或者
登录
后发表评论