Unverified 提交 2da82c8e authored 作者: Noel Grandin's avatar Noel Grandin 提交者: GitHub

Merge pull request #1080 from grandinj/improve_script_exceptions

Improve script exceptions
......@@ -21,6 +21,8 @@ Change Log
<h2>Next Version (unreleased)</h2>
<ul>
<li>Improve the script-based unit testing to check the error code of the exception thrown.
</li>
<li>Issue #1041: Support OR syntax while creating trigger
</li>
<li>Issue #1023: MVCC and existing page store file
......
......@@ -11,6 +11,8 @@ import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.LineNumberReader;
import java.io.PrintStream;
import java.lang.reflect.Field;
import java.lang.reflect.Modifier;
import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
......@@ -18,7 +20,10 @@ import java.sql.ResultSetMetaData;
import java.sql.SQLException;
import java.sql.Statement;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.Map;
import java.util.Random;
import org.h2.api.ErrorCode;
import org.h2.engine.SysProperties;
import org.h2.test.TestAll;
import org.h2.test.TestBase;
......@@ -454,16 +459,30 @@ public class TestScript extends TestBase {
return buff.toString();
}
private void writeException(String sql, SQLException e) throws Exception {
writeResult(sql, "exception", e);
/** Convert the error code to a symbolic name from ErrorCode. */
private static final Map<Integer, String> ERROR_CODE_TO_NAME = new HashMap<>();
static {
try {
for (Field field : ErrorCode.class.getDeclaredFields()) {
if (Modifier.isStatic(field.getModifiers())) {
ERROR_CODE_TO_NAME.put(field.getInt(null), field.getName());
}
}
} catch (IllegalAccessException ex) {
throw new RuntimeException(ex);
}
}
private void writeException(String sql, SQLException ex) throws Exception {
writeResult(sql, "exception " + ERROR_CODE_TO_NAME.get(ex.getErrorCode()), ex);
}
private void writeResult(String sql, String s, SQLException e) throws Exception {
writeResult(sql, s, e, "> ");
private void writeResult(String sql, String s, SQLException ex) throws Exception {
writeResult(sql, s, ex, "> ");
}
private void writeResult(String sql, String s, SQLException e, String prefix) throws Exception {
assertKnownException(sql, e);
private void writeResult(String sql, String s, SQLException ex, String prefix) throws Exception {
assertKnownException(sql, ex);
s = (prefix + s).trim();
String compare = readLine();
if (compare != null && compare.startsWith(">")) {
......@@ -472,11 +491,11 @@ public class TestScript extends TestBase {
return;
}
errors.append(fileName).append('\n');
errors.append("line: ").append(outputLineNo).append('\n');
errors.append("line: ").append(in.getLineNumber()).append('\n');
errors.append("exp: ").append(compare).append('\n');
errors.append("got: ").append(s).append('\n');
if (e != null) {
TestBase.logError("script", e);
if (ex != null) {
TestBase.logError("script", ex);
}
TestBase.logErrorMessage(errors.toString());
if (failFast) {
......
......@@ -7,7 +7,7 @@ CREATE MEMORY TABLE TEST(D1 DOUBLE, D2 DOUBLE PRECISION, D3 FLOAT, D4 FLOAT(25),
> ok
ALTER TABLE TEST ADD COLUMN D6 FLOAT(54);
> exception
> exception INVALID_VALUE_SCALE_PRECISION
SELECT COLUMN_NAME, DATA_TYPE, TYPE_NAME, COLUMN_TYPE FROM INFORMATION_SCHEMA.COLUMNS
WHERE TABLE_NAME = 'TEST' ORDER BY ORDINAL_POSITION;
......
......@@ -73,13 +73,13 @@ select * from card where rank = 5;
--- ENUM edge cases
insert into card (rank, suit) values(6, ' ');
> exception
> exception ENUM_VALUE_NOT_PERMITTED
alter table card alter column suit enum('hearts', 'clubs', 'spades', 'diamonds', 'clubs');
> exception
> exception ENUM_DUPLICATE
alter table card alter column suit enum('hearts', 'clubs', 'spades', 'diamonds', '');
> exception
> exception ENUM_EMPTY
drop table card;
> ok
......@@ -118,7 +118,7 @@ insert into card (rank, suit) values (0, 'clubs'), (3, 'hearts'), (1, 'clubs');
> update count: 3
insert into card (rank, suit) values (0, 'clubs');
> exception
> exception DUPLICATE_KEY_1
select rank from card where suit = 'clubs';
> RANK
......
......@@ -7,7 +7,7 @@ CREATE MEMORY TABLE TEST(D1 REAL, D2 FLOAT4, D3 FLOAT(0), D4 FLOAT(24));
> ok
ALTER TABLE TEST ADD COLUMN D5 FLOAT(-1);
> exception
> exception INVALID_VALUE_2
SELECT COLUMN_NAME, DATA_TYPE, TYPE_NAME, COLUMN_TYPE FROM INFORMATION_SCHEMA.COLUMNS
WHERE TABLE_NAME = 'TEST' ORDER BY ORDINAL_POSITION;
......
......@@ -37,7 +37,7 @@ SELECT COLUMN_NAME, DATA_TYPE, TYPE_NAME, COLUMN_TYPE, NUMERIC_SCALE FROM INFORM
> rows (ordered): 4
ALTER TABLE TEST ADD T5 TIME(10);
> exception
> exception INVALID_VALUE_SCALE_PRECISION
DROP TABLE TEST;
> ok
......
......@@ -49,7 +49,7 @@ SELECT COLUMN_NAME, DATA_TYPE, TYPE_NAME, COLUMN_TYPE, NUMERIC_SCALE FROM INFORM
> rows (ordered): 3
ALTER TABLE TEST ADD T4 TIMESTAMP (10) WITH TIME ZONE;
> exception
> exception INVALID_VALUE_SCALE_PRECISION
DROP TABLE TEST;
> ok
......
......@@ -34,13 +34,13 @@ SELECT COLUMN_NAME, DATA_TYPE, TYPE_NAME, COLUMN_TYPE, NUMERIC_SCALE FROM INFORM
> rows (ordered): 8
ALTER TABLE TEST ADD T5 TIMESTAMP(10);
> exception
> exception INVALID_VALUE_SCALE_PRECISION
ALTER TABLE TEST ADD DT4 DATETIME(10);
> exception
> exception INVALID_VALUE_SCALE_PRECISION
ALTER TABLE TEST ADD STD2 SMALLDATETIME(1);
> exception
> exception SYNTAX_ERROR_1
DROP TABLE TEST;
> ok
......
......@@ -52,7 +52,7 @@ CREATE TABLE TEST(A INT NOT NULL, B INT);
-- column B may be null
ALTER TABLE TEST ADD (CONSTRAINT PK_B PRIMARY KEY (B));
> exception
> exception COLUMN_MUST_NOT_BE_NULLABLE_1
ALTER TABLE TEST ADD (CONSTRAINT PK_A PRIMARY KEY (A));
> ok
......@@ -70,16 +70,16 @@ SELECT * FROM TEST;
> rows: 1
INSERT INTO TEST VALUES (11, 20, 30, 40);
> exception
> exception DUPLICATE_KEY_1
INSERT INTO TEST VALUES (10, 12, 30, 40);
> exception
> exception DUPLICATE_KEY_1
INSERT INTO TEST VALUES (10, 20, 1, 40);
> exception
> exception DUPLICATE_KEY_1
INSERT INTO TEST VALUES (10, 20, 30, 14);
> exception
> exception DUPLICATE_KEY_1
INSERT INTO TEST VALUES (10, 20, 30, 40);
> update count: 1
......
......@@ -16,7 +16,7 @@ ALTER TABLE IF EXISTS TEST DROP COLUMN A;
> ok
ALTER TABLE TEST DROP COLUMN A;
> exception
> exception TABLE_OR_VIEW_NOT_FOUND_1
CREATE TABLE TEST(A INT, B INT, C INT, D INT, E INT, F INT, G INT, H INT, I INT, J INT);
> ok
......@@ -25,7 +25,7 @@ ALTER TABLE TEST DROP COLUMN IF EXISTS J;
> ok
ALTER TABLE TEST DROP COLUMN J;
> exception
> exception COLUMN_NOT_FOUND_1
ALTER TABLE TEST DROP COLUMN B;
> ok
......@@ -39,7 +39,7 @@ SELECT * FROM TEST;
> rows: 0
ALTER TABLE TEST DROP COLUMN B, D;
> exception
> exception COLUMN_NOT_FOUND_1
ALTER TABLE TEST DROP COLUMN IF EXISTS B, D;
> ok
......@@ -58,7 +58,7 @@ SELECT * FROM TEST;
> rows: 0
ALTER TABLE TEST DROP COLUMN (B, H);
> exception
> exception COLUMN_NOT_FOUND_1
ALTER TABLE TEST DROP COLUMN IF EXISTS (B, H);
> ok
......
......@@ -4,13 +4,13 @@
--
create alias "SYSDATE" for "java.lang.Integer.parseInt(java.lang.String)";
> exception
> exception FUNCTION_ALIAS_ALREADY_EXISTS_1
create alias "MIN" for "java.lang.Integer.parseInt(java.lang.String)";
> exception
> exception FUNCTION_ALIAS_ALREADY_EXISTS_1
create alias "CAST" for "java.lang.Integer.parseInt(java.lang.String)";
> exception
> exception FUNCTION_ALIAS_ALREADY_EXISTS_1
--- function alias ---------------------------------------------------------------------------------------------
CREATE ALIAS MY_SQRT FOR "java.lang.Math.sqrt";
......@@ -54,13 +54,13 @@ CREATE SCHEMA TEST_SCHEMA;
> ok
CREATE ALIAS TRUNC FOR "java.lang.Math.floor(double)";
> exception
> exception FUNCTION_ALIAS_ALREADY_EXISTS_1
CREATE ALIAS PUBLIC.TRUNC FOR "java.lang.Math.floor(double)";
> exception
> exception FUNCTION_ALIAS_ALREADY_EXISTS_1
CREATE ALIAS TEST_SCHEMA.TRUNC FOR "java.lang.Math.round(double)";
> exception
> exception FUNCTION_ALIAS_ALREADY_EXISTS_1
SET BUILTIN_ALIAS_OVERRIDE=1;
> ok
......
......@@ -10,7 +10,7 @@ CREATE FORCE TRIGGER T_COUNT BEFORE INSERT ON COUNT CALL "com.Unknown";
> ok
INSERT INTO COUNT VALUES(NULL);
> exception
> exception ERROR_CREATING_TRIGGER_OBJECT_3
DROP TRIGGER T_COUNT;
> ok
......@@ -22,7 +22,7 @@ insert into items values(DEFAULT);
> update count: 1
DROP TABLE COUNT;
> exception
> exception CANNOT_DROP_2
insert into items values(DEFAULT);
> update count: 1
......@@ -47,7 +47,7 @@ CREATE FORCE TRIGGER T_COUNT BEFORE INSERT OR UPDATE ON COUNT CALL "com.Unknown"
> ok
INSERT INTO COUNT VALUES(NULL);
> exception
> exception ERROR_CREATING_TRIGGER_OBJECT_3
UPDATE COUNT SET X=2 WHERE X=1;
> exception
> exception ERROR_CREATING_TRIGGER_OBJECT_3
......@@ -16,7 +16,7 @@ CREATE TABLE TEST_SCHEMA.TEST();
> ok
DROP SCHEMA TEST_SCHEMA RESTRICT;
> exception
> exception CANNOT_DROP_2
DROP SCHEMA TEST_SCHEMA CASCADE;
> ok
......@@ -28,7 +28,7 @@ CREATE VIEW TEST_SCHEMA.TEST AS SELECT 1;
> ok
DROP SCHEMA TEST_SCHEMA RESTRICT;
> exception
> exception CANNOT_DROP_2
DROP SCHEMA TEST_SCHEMA CASCADE;
> ok
......@@ -43,7 +43,7 @@ CREATE SYNONYM TEST_SCHEMA.TEST FOR PUBLIC.SRC;
> ok
DROP SCHEMA TEST_SCHEMA RESTRICT;
> exception
> exception CANNOT_DROP_2
DROP SCHEMA TEST_SCHEMA CASCADE;
> ok
......@@ -58,7 +58,7 @@ CREATE SEQUENCE TEST_SCHEMA.TEST;
> ok
DROP SCHEMA TEST_SCHEMA RESTRICT;
> exception
> exception CANNOT_DROP_2
DROP SCHEMA TEST_SCHEMA CASCADE;
> ok
......@@ -70,7 +70,7 @@ CREATE CONSTANT TEST_SCHEMA.TEST VALUE 1;
> ok
DROP SCHEMA TEST_SCHEMA RESTRICT;
> exception
> exception CANNOT_DROP_2
DROP SCHEMA TEST_SCHEMA CASCADE;
> ok
......@@ -82,7 +82,7 @@ CREATE ALIAS TEST_SCHEMA.TEST FOR "java.lang.System.currentTimeMillis";
> ok
DROP SCHEMA TEST_SCHEMA RESTRICT;
> exception
> exception CANNOT_DROP_2
DROP SCHEMA TEST_SCHEMA CASCADE;
> ok
......@@ -34,16 +34,16 @@ SELECT A AS A1, B AS B1 FROM (VALUES(1, 2)) AS T(A, B) WHERE A <> B;
> rows: 1
SELECT A AS A1, B AS B1 FROM (VALUES(1, 2)) AS T(A, B) WHERE A1 <> B1;
> exception
> exception COLUMN_NOT_FOUND_1
SELECT * FROM (VALUES(1, 2)) AS T(A);
> exception
> exception COLUMN_COUNT_DOES_NOT_MATCH
SELECT * FROM (VALUES(1, 2)) AS T(A, a);
> exception
> exception DUPLICATE_COLUMN_NAME_1
SELECT * FROM (VALUES(1, 2)) AS T(A, B, C);
> exception
> exception COLUMN_COUNT_DOES_NOT_MATCH
SELECT V AS V1, A AS A1, B AS B1 FROM (VALUES (1)) T1(V) INNER JOIN (VALUES(1, 2)) T2(A, B) ON V = A;
> V1 A1 B1
......
......@@ -7,7 +7,7 @@ CREATE TABLE test (id INT NOT NULL, name VARCHAR);
> ok
select * from test where id = (1, 2);
> exception
> exception COMPARING_ARRAY_TO_SCALAR
drop table test;
> ok
\ No newline at end of file
......@@ -13,7 +13,7 @@ INSERT INTO TEST VALUES (1, 10), (2, 20), (3, 30), (4, 40);
> update count: 4
INSERT INTO TEST VALUES (3, 31), (5, 51);
> exception
> exception DUPLICATE_KEY_1
SELECT * FROM TEST ORDER BY ID;
> ID VALUE
......
......@@ -4,7 +4,7 @@
--
call hash('SHA256', 'Hello', 0);
> exception
> exception INVALID_VALUE_2
call hash('SHA256', 'Hello');
>> 185f8db32271fe25f561a6fc938b2e264306ec304eda518007d1764826381969
......@@ -22,4 +22,4 @@ CALL HASH('SHA256', STRINGTOUTF8('Password'), 1000);
>> c644a176ce920bde361ac336089b06cc2f1514dfa95ba5aabfe33f9a22d577f0
call hash('unknown', 'Hello', 1);
> exception
> exception INVALID_VALUE_2
......@@ -16,7 +16,7 @@ SELECT ORA_HASH(1);
>> 3509391659
SELECT ORA_HASH(1, -1);
> exception
> exception INVALID_VALUE_2
SELECT ORA_HASH(1, 0);
>> 0
......@@ -28,7 +28,7 @@ SELECT ORA_HASH(1, 4294967296)
> exception
SELECT ORA_HASH(1, 4294967295, -1);
> exception
> exception SYNTAX_ERROR_1
SELECT ORA_HASH(1, 4294967295, 0);
>> 3509391659
......@@ -40,7 +40,7 @@ SELECT ORA_HASH(1, 4294967295, 4294967295);
>> 3501171530
SELECT ORA_HASH(1, 4294967295, 4294967296);
> exception
> exception INVALID_VALUE_2
CREATE TABLE TEST(I BINARY, B BLOB, S VARCHAR, C CLOB);
> ok
......
......@@ -4,7 +4,7 @@
--
call regexp_replace('x', 'x', '\');
> exception
> exception LIKE_ESCAPE_ERROR_1
CALL REGEXP_REPLACE('abckaboooom', 'o+', 'o');
>> abckabom
......
......@@ -4,7 +4,7 @@
--
call select 1 from dual where regexp_like('x', 'x', '\');
> exception
> exception INVALID_VALUE_2
select x from dual where REGEXP_LIKE('A', '[a-z]', 'i');
>> 1
......
......@@ -89,7 +89,7 @@ select cast(cast('01020304-0506-0708-090a-0b0c0d0e0f00' as uuid) as binary);
>> 0102030405060708090a0b0c0d0e0f00
call cast('null' as uuid);
> exception
> exception DATA_CONVERSION_ERROR_1
select cast('12345678123456781234567812345678' as uuid);
>> 12345678-1234-5678-1234-567812345678
......
......@@ -1063,14 +1063,14 @@ SELECT DATE_TRUNC('MILLENNIUM', '2000-05-29 15:14:13');
-- Test unhandled time unit and bad date
--
SELECT DATE_TRUNC('---', '2015-05-29 15:14:13');
> exception
> exception INVALID_VALUE_2
SELECT DATE_TRUNC('', '2015-05-29 15:14:13');
> exception
> exception INVALID_VALUE_2
SELECT DATE_TRUNC('', '');
> exception
> exception INVALID_VALUE_2
SELECT DATE_TRUNC('YEAR', '');
> exception
> exception INVALID_DATETIME_CONSTANT_2
......@@ -88,7 +88,7 @@ SELECT DATEADD('MINUTE', 30, TIME '12:30:55');
>> 13:00:55
SELECT DATEADD('DAY', 1, TIME '12:30:55');
> exception
> exception INVALID_VALUE_2
SELECT DATEADD('QUARTER', 1, DATE '2010-11-16');
>> 2011-02-16
......
......@@ -84,7 +84,7 @@ INSERT INTO PARENT VALUES(1);
> update count: 1
SELECT * FROM PARENT P LEFT OUTER JOIN CHILD C ON C.PARENTID=P.ID;
> exception
> exception COLUMN_NOT_FOUND_1
DROP TABLE PARENT, CHILD;
> ok
......@@ -380,7 +380,7 @@ select * from left_hand left join right_hand on left_hand.id=right_hand.id where
-- h2: 0 (2 cols); postgresql: 0 (1 col), mysql: exception; derby, hsqldb: no natural join
select * from left_hand natural join right_hand where left_hand.id=1 having right_hand.id=2;
> exception
> exception MUST_GROUP_BY_COLUMN_1
-- h2, mysql, hsqldb: 0 rows; postgresql, derby: exception
select * from left_hand left outer join right_hand on left_hand.id=right_hand.id where left_hand.id=1 group by left_hand.id having right_hand.id=2;
......
......@@ -182,16 +182,16 @@ SELECT COUNT(*) FROM SYSTEM_RANGE(2, 1, 2);
>> 0
SELECT * FROM SYSTEM_RANGE(1, 2, 0);
> exception
> exception STEP_SIZE_MUST_NOT_BE_ZERO
SELECT COUNT(*) FROM SYSTEM_RANGE(1, 2, 0);
> exception
> exception STEP_SIZE_MUST_NOT_BE_ZERO
SELECT * FROM SYSTEM_RANGE(2, 1, 0);
> exception
> exception STEP_SIZE_MUST_NOT_BE_ZERO
SELECT COUNT(*) FROM SYSTEM_RANGE(2, 1, 0);
> exception
> exception STEP_SIZE_MUST_NOT_BE_ZERO
SELECT * FROM SYSTEM_RANGE(1, 8, 2);
> X
......
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论