Browse Source

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
tags/jackcess-2.1.7
James Ahlborn 7 years ago
parent
commit
ae60e32d40

+ 4
- 0
src/changes/changes.xml View File

@@ -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"

+ 1
- 1
src/main/java/com/healthmarketscience/jackcess/impl/ColumnImpl.java View File

@@ -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));
}

+ 7
- 17
src/test/java/com/healthmarketscience/jackcess/impl/AutoNumberTest.java View File

@@ -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());

Loading…
Cancel
Save