diff options
author | James Ahlborn <jtahlborn@yahoo.com> | 2017-05-07 17:59:09 +0000 |
---|---|---|
committer | James Ahlborn <jtahlborn@yahoo.com> | 2017-05-07 17:59:09 +0000 |
commit | ae60e32d4044c44fd1cf4e2363f5f10715daedeb (patch) | |
tree | feacfd21e9f33fe56b18ad7a88d604fcfb6ea93b /src | |
parent | 54972c4de58d2e92f818a8adb8f772513a590d19 (diff) | |
download | jackcess-ae60e32d4044c44fd1cf4e2363f5f10715daedeb.tar.gz jackcess-ae60e32d4044c44fd1cf4e2363f5f10715daedeb.zip |
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
Diffstat (limited to 'src')
-rw-r--r-- | src/changes/changes.xml | 4 | ||||
-rw-r--r-- | src/main/java/com/healthmarketscience/jackcess/impl/ColumnImpl.java | 2 | ||||
-rw-r--r-- | src/test/java/com/healthmarketscience/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. </action> + <action dev="jahlborn" type="update" system="GitHubPullRequests" + issue="3"> + Allow inserting negative auto number fields, thanks to Gord Thompson. + </action> </release> <release version="2.1.6" date="2016-11-29"> <action dev="jahlborn" type="update" system="SourceForge2Features" diff --git a/src/main/java/com/healthmarketscience/jackcess/impl/ColumnImpl.java b/src/main/java/com/healthmarketscience/jackcess/impl/ColumnImpl.java index 998e80a..c5d0449 100644 --- a/src/main/java/com/healthmarketscience/jackcess/impl/ColumnImpl.java +++ b/src/main/java/com/healthmarketscience/jackcess/impl/ColumnImpl.java @@ -1939,7 +1939,7 @@ public class ColumnImpl implements Column, Comparable<ColumnImpl> { 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()); |