From 6d3704b7bad4732a289c0be68e8f18a1fdf8abac Mon Sep 17 00:00:00 2001 From: James Moger Date: Mon, 15 Oct 2012 12:17:02 -0400 Subject: Added drop reference table test (fails on H2) Unfortunately, it looks like H2 1.3.168 has a bug which allows you to drop a table even though there are active constraints referencing it. HSQL, Derby, MySQL, and PostgreSQL all throw a constraint violation exception, as expected, but H2 does not. --- src/com/iciql/IciqlException.java | 13 +++++++++++++ 1 file changed, 13 insertions(+) (limited to 'src/com/iciql/IciqlException.java') diff --git a/src/com/iciql/IciqlException.java b/src/com/iciql/IciqlException.java index 320604d..38c8fac 100644 --- a/src/com/iciql/IciqlException.java +++ b/src/com/iciql/IciqlException.java @@ -29,6 +29,7 @@ public class IciqlException extends RuntimeException { public static final int CODE_DUPLICATE_KEY = 2; public static final int CODE_OBJECT_NOT_FOUND = 3; public static final int CODE_OBJECT_ALREADY_EXISTS = 4; + public static final int CODE_CONSTRAINT_VIOLATION = 5; private static final String TOKEN_UNMAPPED_FIELD = "\\? (=|\\>|\\<|\\<\\>|!=|\\>=|\\<=|LIKE|BETWEEN) \\?"; @@ -97,6 +98,9 @@ public class IciqlException extends RuntimeException { if ("23000".equals(state)) { // MySQL duplicate primary key on insert iciqlCode = CODE_DUPLICATE_KEY; + if (s.getErrorCode() == 1217) { + iciqlCode = CODE_CONSTRAINT_VIOLATION; + } } else if ("23505".equals(state)) { // Derby duplicate primary key on insert iciqlCode = CODE_DUPLICATE_KEY; @@ -139,6 +143,15 @@ public class IciqlException extends RuntimeException { } else if ("42504".equals(state)) { // HSQL index already exists iciqlCode = CODE_OBJECT_ALREADY_EXISTS; + } else if ("2BP01".equals(state)) { + // PostgreSQL constraint violation + iciqlCode = CODE_CONSTRAINT_VIOLATION; + } else if ("42533".equals(state)) { + // HSQL constraint violation + iciqlCode = CODE_CONSTRAINT_VIOLATION; + } else if ("X0Y25".equals(state)) { + // Derby constraint violation + iciqlCode = CODE_CONSTRAINT_VIOLATION; } } } -- cgit v1.2.3