Skip to content

Commit

Permalink
Fix bug in batch parameter handling
Browse files Browse the repository at this point in the history
  • Loading branch information
sykesd committed Sep 25, 2018
1 parent 5f66a92 commit fd49938
Show file tree
Hide file tree
Showing 3 changed files with 43 additions and 2 deletions.
2 changes: 1 addition & 1 deletion build.xml
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
<property name="lib" value="${basedir}/lib" />
<property name="test-lib" value="${basedir}/lib-test" />

<property name="version" value="0.9.3" />
<property name="version" value="0.9.4" />

<property name="product-jar" value="${basedir}/${ant.project.name}-${version}.jar" />
</target>
Expand Down
2 changes: 1 addition & 1 deletion src/org/dt/japper/ParameterParser.java
Original file line number Diff line number Diff line change
Expand Up @@ -310,7 +310,7 @@ private boolean handleParamName(int ch) {

private void addParamRef() {
String name = paramName.toString().toLowerCase();
if (parsingForBatch) {
if (parsingForBatch && !paramValueMap.containsKey(name)) {
paramValueMap.put(name, new ParameterValue(name, null));
}

Expand Down
41 changes: 41 additions & 0 deletions test-src/org/dt/japper/BatchParameterReuseTest.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
package org.dt.japper;

import org.junit.BeforeClass;
import org.junit.Test;

import java.sql.Connection;

import static org.dt.japper.Japper.paramLists;
import static org.dt.japper.Japper.params;
import static org.junit.Assert.assertEquals;

public class BatchParameterReuseTest {

private static TestData testData;

@BeforeClass
public static void setupDB() throws Exception {
testData = new TestData();
testData.create();
}

@Test
public void insertBatch() throws Exception {
String sql =
" insert into part(partno, description, part_type, dyn_field) " +
" values(:PARTNO, :DESCRIPTION, :PARTNO, :DYN_FIELD) "
;

Connection conn = testData.connect();
try {
int rowsAffected = Japper.executeBatch(conn, sql, paramLists(
params("PARTNO", "ZZ1", "DESCRIPTION", "Batch part 1", "PART_TYPE", "FAB", "DYN_FIELD", "C:30")
, params("PARTNO", "ZZ2", "PART_TYPE", "BUY", "DESCRIPTION", "Batch part 2")
));
assertEquals(2, rowsAffected);
}
finally {
try { conn.close(); } catch (Exception ignored) {}
}
}
}

0 comments on commit fd49938

Please sign in to comment.