# update options and values where select options contains old dt
select_flds = sql("select parent, fieldname from `tabDocField` where parent not like 'old%%' and (options like '%%%s%%' or options like '%%%s%%') and options not like 'link:%%' and fieldtype = 'Select' and parent != '%s'" % ('\n' + old, old + '\n', new))
update_link_fld_values(select_flds, old, new)
sql("update `tabDocField` set options = replace(options, '%s', '%s') where parent not like 'old%%' and (options like '%%%s%%' or options like '%%%s%%') and options not like 'link:%%' and fieldtype = 'Select' and parent != '%s'" % (old, new, '\n' + old, old + '\n', new))
if not is_single_dt(old):
if not is_single_dt(new):
sql("RENAME TABLE `tab%s` TO `tab%s`" % (old, new))
else:
sql("update tabSingles set doctype = %s where doctype = %s", (new, old))