Generates SQL update table set ...
    Returns (sql, parameters)

    >>> sqlupdate('mytable', {'field1': 3, 'field2': 'hello'}, {'id': 5})
    ('update mytable set field1=%s, field2=%s where id=%s', [3, 'hello', 5])

def sqlupdate(table, rowupdate, where):
    """Generates SQL update table set ...
    Returns (sql, parameters)

    >>> sqlupdate('mytable', {'field1': 3, 'field2': 'hello'}, {'id': 5})
    ('update mytable set field1=%s, field2=%s where id=%s', [3, 'hello', 5])
    """
    validate_name(table)
    fields = sorted(rowupdate.keys())
    validate_names(fields)
    values = [rowupdate[field] for field in fields]
    setparts = [field + '=%s' for field in fields]
    setclause = ', '.join(setparts)
    sql = "update {} set ".format(table) + setclause
    (whereclause, wherevalues) = sqlwhere(where)
    if whereclause:
        sql = sql + " where " + whereclause
    return (sql, values + wherevalues)