(row, tbl, pkey_list, field_map = None)
return "update only %s set %s where %s;" % (skytools.quote_fqident(tbl),
            ", ".join(set_list), " and ".join(whe_list))
r"""Generate UPDATE statement from dict data.

    >>> mk_update_sql({'id': 0, 'id2': '2', 'data': 'str\\'}, 'Table', ['id', 'id2'])
    'update only public."Table" set data = E\'str\\\\\' where id = \'0\' and id2 = \'2\';'
r"""Generate UPDATE statement from dict data.
r Generate UPDATE statement from dict data .
def mk_update_sql(row, tbl, pkey_list, field_map = None):
    r"""Generate UPDATE statement from dict data.

    >>> mk_update_sql({'id': 0, 'id2': '2', 'data': 'str\\'}, 'Table', ['id', 'id2'])
    'update only public."Table" set data = E\'str\\\\\' where id = \'0\' and id2 = \'2\';'
    """

    if len(pkey_list) < 1:
        raise Exception("update needs pkeys")
    set_list = []
    whe_list = []
    pkmap = {}
    for k in pkey_list:
        pkmap[k] = 1
        new_k = field_map and field_map[k] or k
        col = skytools.quote_ident(new_k)
        val = skytools.quote_literal(row[k])
        whe_list.append("%s = %s" % (col, val))

    if field_map:
        for src, dst in field_map.iteritems():
            if src not in pkmap:
                col = skytools.quote_ident(dst)
                val = skytools.quote_literal(row[src])
                set_list.append("%s = %s" % (col, val))
    else:
        for col, val in row.iteritems():
            if col not in pkmap:
                col = skytools.quote_ident(col)
                val = skytools.quote_literal(val)
                set_list.append("%s = %s" % (col, val))
    return "update only %s set %s where %s;" % (skytools.quote_fqident(tbl),
            ", ".join(set_list), " and ".join(whe_list))
def mk_update_sql ( row , tbl , pkey_list , field_map = None ) : if len ( pkey_list ) < 1 : raise Exception ( "update needs pkeys" ) set_list = [ ] whe_list = [ ] pkmap = { } for k in pkey_list : pkmap [ k ] = 1 new_k = field_map and field_map [ k ] or k col = skytools . quote_ident ( new_k ) val = skytools . quote_literal ( row [ k ] ) whe_list . append ( "%s = %s" % ( col , val ) ) if field_map : for src , dst in field_map . iteritems ( ) : if src not in pkmap : col = skytools . quote_ident ( dst ) val = skytools . quote_literal ( row [ src ] ) set_list . append ( "%s = %s" % ( col , val ) ) else : for col , val in row . iteritems ( ) : if col not in pkmap : col = skytools . quote_ident ( col ) val = skytools . quote_literal ( val ) set_list . append ( "%s = %s" % ( col , val ) ) return "update only %s set %s where %s;" % ( skytools . quote_fqident ( tbl ) , ", " . join ( set_list ) , " and " . join ( whe_list ) )