public static final int CODE_DUPLICATE_KEY = 2;\r
public static final int CODE_OBJECT_NOT_FOUND = 3;\r
public static final int CODE_OBJECT_ALREADY_EXISTS = 4;\r
+ public static final int CODE_CONSTRAINT_VIOLATION = 5;\r
\r
private static final String TOKEN_UNMAPPED_FIELD = "\\? (=|\\>|\\<|\\<\\>|!=|\\>=|\\<=|LIKE|BETWEEN) \\?";\r
\r
if ("23000".equals(state)) {\r
// MySQL duplicate primary key on insert\r
iciqlCode = CODE_DUPLICATE_KEY;\r
+ if (s.getErrorCode() == 1217) {\r
+ iciqlCode = CODE_CONSTRAINT_VIOLATION; \r
+ }\r
} else if ("23505".equals(state)) {\r
// Derby duplicate primary key on insert\r
iciqlCode = CODE_DUPLICATE_KEY;\r
} else if ("42504".equals(state)) {\r
// HSQL index already exists\r
iciqlCode = CODE_OBJECT_ALREADY_EXISTS;\r
+ } else if ("2BP01".equals(state)) {\r
+ // PostgreSQL constraint violation\r
+ iciqlCode = CODE_CONSTRAINT_VIOLATION;\r
+ } else if ("42533".equals(state)) {\r
+ // HSQL constraint violation\r
+ iciqlCode = CODE_CONSTRAINT_VIOLATION;\r
+ } else if ("X0Y25".equals(state)) {\r
+ // Derby constraint violation\r
+ iciqlCode = CODE_CONSTRAINT_VIOLATION;\r
}\r
}\r
}\r
package com.iciql.test;\r
\r
import static org.junit.Assert.assertEquals;\r
+import static org.junit.Assert.assertTrue;\r
\r
import org.junit.After;\r
import org.junit.Before;\r
import org.junit.Test;\r
\r
import com.iciql.Db;\r
+import com.iciql.IciqlException;\r
import com.iciql.test.models.CategoryAnnotationOnly;\r
import com.iciql.test.models.ProductAnnotationOnlyWithForeignKey;\r
\r
\r
assertEquals(count1, count2 + 2L);\r
}\r
-\r
+ \r
+ @Test\r
+ public void testForeignKeyDropReferenceTable() {\r
+ try {\r
+ db.dropTable(CategoryAnnotationOnly.class);\r
+ assertTrue("Should not be able to drop reference table!", false);\r
+ } catch (IciqlException e) {\r
+ assertEquals(e.getMessage(), IciqlException.CODE_CONSTRAINT_VIOLATION, e.getIciqlCode());\r
+ }\r
+ }\r
\r
}\r