def limit(lower, upper):
    """
    Returns a SQlite-compliant LIMIT statement that
    takes the *lower* and *upper* bounds into account.

    :param lower: The lower bound.
    :param upper: The upper bound.
    """
    offset = lower or 0
    lim = (upper - offset) if upper else -1
    smt = 'LIMIT %d OFFSET %d' % (lim, offset)
    return smt, ()