Fixed to do index++ when fetching generated ids (with test coverage)

This commit is contained in:
Darin Kelkhoff
2021-12-01 22:58:08 -06:00
parent 3956a28e70
commit b6a664ac89
2 changed files with 3 additions and 3 deletions

View File

@ -80,7 +80,7 @@ public class RDBMSInsertAction extends AbstractRDBMSAction implements InsertInte
int index = 0;
for(QRecord record : insertRequest.getRecords())
{
Integer id = idList.get(index);
Integer id = idList.get(index++);
QRecordWithStatus recordWithStatus = new QRecordWithStatus(record);
recordWithStatus.setPrimaryKey(id);
recordWithStatus.setValue(table.getPrimaryKeyField(), id);

View File

@ -81,8 +81,8 @@ public class RDBMSInsertActionTest extends RDBMSActionTest
insertRequest.setRecords(List.of(record1, record2));
InsertResult insertResult = new RDBMSInsertAction().execute(insertRequest);
assertEquals(2, insertResult.getRecords().size(), "Should return 1 row");
assertNotNull(insertResult.getRecords().get(0).getValue("id"), "Should have an id in the row");
assertNotNull(insertResult.getRecords().get(1).getValue("id"), "Should have an id in the row");
assertEquals(6, insertResult.getRecords().get(0).getValue("id"), "Should have next id in the row");
assertEquals(7, insertResult.getRecords().get(1).getValue("id"), "Should have next id in the row");
assertTrue(insertResult.getRecords().stream().noneMatch(qrs -> CollectionUtils.nullSafeHasContents(qrs.getErrors())), "There should be no errors");
runTestSql("SELECT * FROM person WHERE last_name = 'Picard'", (rs -> {
int rowsFound = 0;