提交 82a06408 authored 作者: noelgrandin's avatar noelgrandin

Throw an explicit error to make it clear we don't support the TRIGGER…

Throw an explicit error to make it clear we don't support the TRIGGER combination of SELECT and FOR EACH ROW
上级 62c639da
......@@ -65,6 +65,7 @@ Change Log
</li><li>Fix issue #438:JdbcDatabaseMetaData#getSchemas() no longer supported as of 1.3.169
</li><li>MySQL compatibility: support for ALTER TABLE tbl_name MODIFY [COLUMN] col_name column_definition, patch from Ville Koskela.
</li><li>Fix issue #404:SHOW COLUMNS FROM table_name does not work with ALLOW_LITERALS=NUMBERS
</li><li>Throw an explicit error to make it clear we don't support the TRIGGER combination of SELECT and FOR EACH ROW
</li></ul>
<h2>Version 1.3.170 (2012-11-30)</h2>
......
......@@ -32,6 +32,7 @@
90002=Method is only allowed for a query. Use execute or executeUpdate instead of executeQuery
90003=Hexadecimal string with odd number of characters: {0}
90004=Hexadecimal string contains non-hex character: {0}
90005=Trigger {0}, we do not support the combination of SELECT and FOR EACH ROW
90007=The object is already closed
90008=Invalid value {0} for parameter {1}
90012=Parameter {0} is not set
......
......@@ -6,6 +6,7 @@
*/
package org.h2.command.ddl;
import org.h2.api.Trigger;
import org.h2.command.CommandInterface;
import org.h2.constant.ErrorCode;
import org.h2.engine.Database;
......@@ -88,6 +89,9 @@ public class CreateTrigger extends SchemaCommand {
}
throw DbException.get(ErrorCode.TRIGGER_ALREADY_EXISTS_1, triggerName);
}
if ((typeMask & Trigger.SELECT) == Trigger.SELECT && rowBased) {
throw DbException.get(ErrorCode.TRIGGER_SELECT_AND_ROW_BASED_NOT_SUPPORTED, triggerName);
}
int id = getObjectId();
Table table = getSchema().getTableOrView(session, tableName);
TriggerObject trigger = new TriggerObject(getSchema(), id, triggerName, table);
......
......@@ -797,7 +797,7 @@ public class ErrorCode {
* See the root cause for details.
*/
public static final int ERROR_EXECUTING_TRIGGER_3 = 90044;
/**
* The error with code <code>90045</code> is thrown when
* trying to create a constraint if an object with this name already exists.
......@@ -1849,7 +1849,14 @@ public class ErrorCode {
*/
public static final int RESULT_SET_READONLY = 90140;
// next are 90005, 90006, 90009, 90010, 90011, 90021, 90039,
/**
* The error with code <code>90005</code> is thrown when
* trying to create a trigger and using the combination of SELECT and FOR EACH ROW,
* which we do not support.
*/
public static final int TRIGGER_SELECT_AND_ROW_BASED_NOT_SUPPORTED = 90005;
// next are 90006, 90009, 90010, 90011, 90021, 90039,
// 90051, 90056, 90110, 90122, 90141
private ErrorCode() {
......
......@@ -42,6 +42,7 @@ public class TestTriggersConstraints extends TestBase implements Trigger {
testTriggerDeadlock();
testDeleteInTrigger();
testTriggerAdapter();
testTriggerSelectEachRow();
testViewTrigger();
testTriggerBeforeSelect();
testTriggerAlterTable();
......@@ -146,6 +147,23 @@ public class TestTriggersConstraints extends TestBase implements Trigger {
conn.close();
}
private void testTriggerSelectEachRow() throws SQLException {
Connection conn;
Statement stat;
conn = getConnection("trigger");
stat = conn.createStatement();
stat.execute("drop table if exists test");
stat.execute("create table test(id int)");
try {
stat.execute("create trigger test_insert before select on test " +
"for each row call \"" + TestTriggerAdapter.class.getName() + "\"");
fail();
} catch (SQLException ex) {
assertEquals(ErrorCode.TRIGGER_SELECT_AND_ROW_BASED_NOT_SUPPORTED, ex.getErrorCode());
}
conn.close();
}
private void testViewTrigger() throws SQLException {
Connection conn;
Statement stat;
......
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论