private void updateRecordsIterator(boolean testStoredDB, int schemaType, int recordCnt,
			long keyIncrement, int varDataSize) throws IOException {
		DBRecord[] recs = null;
		if (keyIncrement == 0) {
			recs = createRandomTableRecords(schemaType, recordCnt, varDataSize);
		}
		else {
			recs = createOrderedTableRecords(schemaType, recordCnt, keyIncrement, varDataSize);
		}
		if (testStoredDB) {
			saveAsAndReopen(dbName);
		}
		Table table = dbh.getTable(table1Name);

		// Find string and binary columns
		int strColumn = -1;
		int binColumn = -1;
		Field[] fields = table.getSchema().getFields();
		for (int i = 0; i < fields.length; i++) {
			if (!fields[i].isVariableLength()) {
				continue;
			}
			if (fields[i] instanceof StringField) {
				strColumn = i;
			}
			else if (fields[i] instanceof BinaryField) {
				binColumn = i;
			}
		}

		// Random update
		long txId = dbh.startTransaction();
		Random random = new Random(1);
		int updateCnt = recordCnt / 4;// update 1/4th of the records
		int varFldUpdate = 0;
		updateCnt = 206;
		for (int i = 0; i < updateCnt; i++) {
			int ran = random.nextInt();
			if (ran < 0) {
				ran = -ran;
			}
			int ix = ran % recordCnt;

			DBTestUtils.fillRecord(recs[ix], varDataSize);
			int r = varFldUpdate % 4;
			if ((r & 0x01) == 1 && strColumn >= 0) {
				// Update String field with null
				StringField sf = (StringField) recs[ix].getField(strColumn);
				sf.setString(null);
			}
			else if ((r & 0x02) == 2 && binColumn >= 0) {
				// Update binary field with null
				BinaryField bf = (BinaryField) recs[ix].getField(binColumn);
				bf.setBinaryData(null);
			}
			table.putRecord(recs[ix]);
			++varFldUpdate;
		}
		dbh.endTransaction(txId, true);

		assertEquals(recordCnt, table.getRecordCount());

		for (int colIx : table.getIndexedColumns()) {

			Arrays.sort(recs, new RecColumnComparator(colIx));

			// Forward iteration (no start)
			int recIx = 0;
			RecordIterator iter = table.indexIterator(colIx);
			while (iter.hasNext()) {
				DBRecord rec = iter.next();
				assertEquals(recs[recIx++], rec);
			}
			assertEquals(recordCnt, recIx);

			// Forward iteration (start in middle - specify primary key)
			recIx = recordCnt / 2;
			iter = table.indexIteratorBefore(colIx, recs[recIx].getField(colIx),
				recs[recIx].getKeyField());
			while (iter.hasNext()) {
				DBRecord rec = iter.next();
				assertEquals(recs[recIx++], rec);
			}
			assertEquals(recordCnt, recIx);

			// Reverse iteration (end - specify primary key)
			recIx = recordCnt - 1;
			iter = table.indexIteratorAfter(colIx, recs[recIx].getField(colIx),
				recs[recIx].getKeyField());
			while (iter.hasPrevious()) {
				DBRecord rec = iter.previous();
				assertEquals(recs[recIx--], rec);
			}
			assertEquals(-1, recIx);

			// Reverse iteration (start in middle - specify primary key)
			recIx = recordCnt / 2;
			iter = table.indexIteratorAfter(colIx, recs[recIx].getField(colIx),
				recs[recIx].getKeyField());
			while (iter.hasPrevious()) {
				DBRecord rec = iter.previous();
				assertEquals(recs[recIx--], rec);
			}
			assertEquals(-1, recIx);

			// Forward iteration (start in middle)
			recIx = findStart(recs, recordCnt / 2, colIx);
			iter = table.indexIteratorBefore(colIx, recs[recIx].getField(colIx));
			while (iter.hasNext()) {
				DBRecord rec = iter.next();
				assertEquals(recs[recIx++], rec);
			}
			assertEquals(recordCnt, recIx);

			// Reverse iteration (end)
			recIx = recordCnt - 1;
			iter = table.indexIteratorAfter(colIx, recs[recIx].getField(colIx));
			while (iter.hasPrevious()) {
				DBRecord rec = iter.previous();
				assertEquals(recs[recIx--], rec);
			}
			assertEquals(-1, recIx);

			// Reverse iteration (start in middle)
			recIx = findEnd(recs, recordCnt / 2, colIx);
			iter = table.indexIteratorAfter(colIx, recs[recIx].getField(colIx));
			while (iter.hasPrevious()) {
				DBRecord rec = iter.previous();
				assertEquals(recs[recIx--], rec);
			}
			assertEquals(-1, recIx);

			if (recs[0].getField(colIx) instanceof LongField) {

				// Forward iteration (start in middle - specify primary key)
				recIx = findStart(recs, recordCnt / 2, colIx);
				Field startValue = new LongField();
				startValue.setLongValue(recs[recIx].getField(colIx).getLongValue() - 1);
				iter = table.indexIteratorAfter(colIx, startValue);
				while (iter.hasNext()) {
					DBRecord rec = iter.next();
					assertEquals(recs[recIx++], rec);
				}
				assertEquals(recordCnt, recIx);

				// Reverse iteration (start in middle)
				recIx = findEnd(recs, recordCnt / 2, colIx);
				startValue.setLongValue(recs[recIx].getField(colIx).getLongValue() + 1);
				iter = table.indexIteratorBefore(colIx, startValue);
				while (iter.hasPrevious()) {
					DBRecord rec = iter.previous();
					assertEquals(recs[recIx--], rec);
				}
				assertEquals(-1, recIx);

			}

		}

	}
Insert the specified number of records using random keys.

@param recordCnt number of records to insert.
@param varDataSize size of variable length data fields.
@return Record[] records which were inserted.
Ghidra/Framework/DB/src/test/java/db/DBIndexedTableTest.java