def execute(stmt, args=()):
    """
    Execute an SQL statement. Returns the number of affected rows.
    """
    ctx = Context.current()
    with ctx.mdr:
        cursor = ctx.execute(stmt, args)
        row_count = cursor.rowcount
        _safe_close(cursor)
    return row_count