def dict_to_kv_str(env, data=None, sep=' AND '):
    """Converts a dictionary into a string and a list suitable for using as part
    of an SQL where clause like:
        ('key0=%s AND key1=%s', ['value0','value1'])
    The sep argument allows ' AND ' to be changed for ',' for UPDATE purposes
    """
    if data is None:
        return ('', [])
    qfn = env.get_read_db().quote
    return (sep.join('%s=%%s' % qfn(k) for k in data.keys()),
            data.values())