Generates SQL select ...
    Returns (sql, params)

    >>> sqlselect('t')
    ('select * from t', [])
    >>> sqlselect('t', fields=['name', 'address'])
    ('select name, address from t', [])
    >>> sqlselect('t', where={'name': 'Toto', 'country': 'US'})
    ('select * from t where country=%s and name=%s', ['US', 'Toto'])
    >>> sqlselect('t', orderby=['lastname', 'firstname'])
    ('select * from t order by lastname, firstname', [])
    >>> sqlselect('t', limit=1)
    ('select * from t limit 1', [])
    >>> sqlselect('t', limit='yes')
    Traceback (most recent call last):
        ...
    ValueError: Limit parameter must be an int
    >>> sqlselect('t', offset=20)
    ('select * from t offset 20', [])
    >>> sqlselect('t', offset='yes')
    Traceback (most recent call last):
        ...
    ValueError: Offset parameter must be an int

def sqlselect(table, fields=['*'], where=None, orderby=None, limit=None,
              offset=None):
    """Generates SQL select ...
    Returns (sql, params)

    >>> sqlselect('t')
    ('select * from t', [])
    >>> sqlselect('t', fields=['name', 'address'])
    ('select name, address from t', [])
    >>> sqlselect('t', where={'name': 'Toto', 'country': 'US'})
    ('select * from t where country=%s and name=%s', ['US', 'Toto'])
    >>> sqlselect('t', orderby=['lastname', 'firstname'])
    ('select * from t order by lastname, firstname', [])
    >>> sqlselect('t', limit=1)
    ('select * from t limit 1', [])
    >>> sqlselect('t', limit='yes')
    Traceback (most recent call last):
        ...
    ValueError: Limit parameter must be an int
    >>> sqlselect('t', offset=20)
    ('select * from t offset 20', [])
    >>> sqlselect('t', offset='yes')
    Traceback (most recent call last):
        ...
    ValueError: Offset parameter must be an int
    """
    validate_name(table)
    if fields != ['*']:
        validate_names(fields)
    fieldspart = ', '.join(fields)
    sql = "select {} from {}".format(fieldspart, table)
    values = []

    if where:
        (whereclause, wherevalues) = sqlwhere(where)
        if whereclause:
            sql = sql + " where " + whereclause
            values = wherevalues

    if orderby:
        validate_names(orderby)
        sql = sql + " order by " + ', '.join(orderby)

    if limit:
        if not isinstance(limit, int):
            raise ValueError("Limit parameter must be an int")
        sql = sql + " limit {}".format(limit)

    if offset:
        if not isinstance(offset, int):
            raise ValueError("Offset parameter must be an int")
        sql = sql + " offset {}".format(offset)

    return (sql, values)