From ae60e32d4044c44fd1cf4e2363f5f10715daedeb Mon Sep 17 00:00:00 2001 From: James Ahlborn Date: Sun, 7 May 2017 17:59:09 +0000 Subject: [PATCH] Allow inserting negative auto number fields, fixes pull request #3 git-svn-id: https://svn.code.sf.net/p/jackcess/code/jackcess/trunk@1094 f203690c-595d-4dc9-a70b-905162fa7fd2 --- src/changes/changes.xml | 4 ++++ .../jackcess/impl/ColumnImpl.java | 2 +- .../jackcess/impl/AutoNumberTest.java | 24 ++++++------------- 3 files changed, 12 insertions(+), 18 deletions(-) diff --git a/src/changes/changes.xml b/src/changes/changes.xml index 8b237bf..ba2583d 100644 --- a/src/changes/changes.xml +++ b/src/changes/changes.xml @@ -14,6 +14,10 @@ issue="2"> Cover the GENERIC_JET4 format in unit tests, thanks to Gord Thompson. + + Allow inserting negative auto number fields, thanks to Gord Thompson. + { throws IOException { int inAutoNum = toNumber(inRowValue).intValue(); - if(inAutoNum <= INVALID_AUTO_NUMBER) { + if(inAutoNum <= INVALID_AUTO_NUMBER && !getTable().isAllowAutoNumberInsert()) { throw new IOException(withErrorContext( "Invalid auto number value " + inAutoNum)); } diff --git a/src/test/java/com/healthmarketscience/jackcess/impl/AutoNumberTest.java b/src/test/java/com/healthmarketscience/jackcess/impl/AutoNumberTest.java index 37eec77..eae2c25 100644 --- a/src/test/java/com/healthmarketscience/jackcess/impl/AutoNumberTest.java +++ b/src/test/java/com/healthmarketscience/jackcess/impl/AutoNumberTest.java @@ -242,12 +242,7 @@ public class AutoNumberTest extends TestCase assertEquals(13, ((TableImpl)table).getLastLongAutoNumber()); - try { - table.addRow(-10, "uh-uh"); - fail("IOException should have been thrown"); - } catch(IOException e) { - // success - } + table.addRow(-10, "non-positives are now allowed"); row = table.addRow(Column.AUTO_NUMBER, "row14"); assertEquals(14, ((Integer)row[0]).intValue()); @@ -262,23 +257,18 @@ public class AutoNumberTest extends TestCase assertEquals(45, ((TableImpl)table).getLastLongAutoNumber()); - row13.put("a", -1); - - try { - table.updateRow(row13); - fail("IOException should have been thrown"); - } catch(IOException e) { - // success - } + row13.put("a", -1); // non-positives are now allowed + table.updateRow(row13); assertEquals(45, ((TableImpl)table).getLastLongAutoNumber()); row13.put("a", 55); - table.setAllowAutoNumberInsert(null); + // reset to db-level policy (which in this case is "false") + table.setAllowAutoNumberInsert(null); - row13 = table.updateRow(row13); - assertEquals(45, row13.get("a")); + row13 = table.updateRow(row13); // no change, as confirmed by... + assertEquals(-1, row13.get("a")); assertEquals(45, ((TableImpl)table).getLastLongAutoNumber()); -- 2.39.5