def METHOD_NAME(matrices, connection):
    """
    Given an iterable of MatrixRows (which contain a BNF code plus all
    prescribing data for that presentation) yield tuples of values ready for
    insertion into SQLite
    """
    cursor = connection.cursor()
    num_presentations = next(cursor.execute("SELECT COUNT(*) FROM presentation"))[0]
    count = 0
    for row in matrices:
        count += 1
        # We make sure we have a row for every BNF code in the data, even ones
        # we didn't know about previously. This is a hack that we won't need
        # once we can use SQLite v3.24.0 which has proper UPSERT support.
        cursor.execute(
            "INSERT OR IGNORE INTO presentation (bnf_code) VALUES (?)", [row.bnf_code]
        )
        if should_log_message(count):
            logger.info(
                "Writing data for %s (%s/%s)", row.bnf_code, count, num_presentations
            )
        yield (
            serialize_compressed(row.items),
            serialize_compressed(row.quantity),
            serialize_compressed(row.actual_cost),
            serialize_compressed(row.net_cost),
            row.bnf_code,
        )
    logger.info("Finished writing data for %s presentations", count)