def DELETE(self):
input_data = web.data()
data = urlparse.parse_qs(input_data)
v_ct_fids = db.query("SELECT distinct c.name FROM t_ci_type c WHERE c.family_id = $fid and c.endtime = $endtime",
vars={'fid':data['fid'][0],'endtime':ENDTIME})
json_en = demjson.encode(v_ct_fids)
json_de = demjson.decode(json_en)
v_ct_fid_num = len(json_de)
if v_ct_fid_num == 0:
return 2 #there are no records to delete in table T_CI_TYPE
elif v_ct_fid_num > 1:
return 3 #there are more than one records to delete in table T_CI_TYPE
#Before deleting t_ci_type, we should ensure that there are no relative records in t_ci?t_ci_attribute_type?t_ci_relation_type
v_num = db.query('select count(*) num from t_ci a where a.type_fid = $fid and a.endtime = $endtime',vars={'fid':data['fid'][0],'endtime':ENDTIME})
ci_num = v_num[0]['NUM']
if ci_num <> 0:
return 4 #there are relative records in t_ci
# If there is no relative ci, there will be no relative attribute and relation. Then we can directly delete attribute type and relation type
# Delete ci_attribute_type
v_cat_fids = db.query('select distinct a.family_id from t_ci_attribute_type a where a.ci_type_fid = $fid and a.endtime = $endtime',vars={'fid':data['fid'][0],'endtime':ENDTIME})
json_en = demjson.encode(v_cat_fids)
json_de = demjson.decode(json_en)
v_curtime = time.strftime("%Y%m%d%H%M%S", time.localtime())
v_ct_fid_num = len(json_de)
if v_ct_fid_num <> 0:
for v_cat_fid in json_de:
n = webci_attr_type.fn_delete_ci_attrtype(v_cat_fid['FAMILY_ID'], v_curtime, data['change_log'][0])
#Delete ci_relation_type
v_crt_fids = db.query('select distinct a.family_id from t_ci_relation_type a where (a.source_type_fid = $fid or a.target_type_fid = $fid) and a.endtime = $endtime',vars={'fid':data['fid'][0],'endtime':ENDTIME})
json_en = demjson.encode(v_crt_fids)
json_de = demjson.decode(json_en)
v_ct_fid_num = len(json_de)
if v_ct_fid_num <> 0:
for v_crt_fid in json_de:
n = webci_relation_type.fn_delete_ci_relatype(v_crt_fid['FAMILY_ID'], v_curtime, data['change_log'][0])
#Delete t_ci_type
n = fn_delete_ci_type(data['fid'][0],v_curtime,data['change_log'][0])
return n
评论列表
文章目录