← All posts tagged говнокод

Skyrzn
Python SQL говнокод Увидел сегодня в триггере таблицы просто феерический код. У кого-то из коллег явно в роду были индусы.

if (TD['new']['board'] is None) and (TD['new']['place'] is None) and (TD['new']['vendor_parts'] is None):
if plpy.execute("SELECT count(*) FROM rma.component_specification where ((board is NULL)and(place is NULL)and(vendor_parts is NULL)and(model_id=%s)and(id<>%s))"%(TD['new']['model_id'], TD['new']['id']))[0]['count'] > 0 :
raise Exception, 'Model, place, board and vendor_parts must be unique! Record for this combination already exists.'

if (TD['new']['board'] is not None) and (TD['new']['place'] is None) and (TD['new']['vendor_parts'] is None):
if plpy.execute("SELECT count(*) FROM rma.component_specification where ((board='%s')and(place is NULL)and(vendor_parts is NULL)and(model_id=%s)and(id<>%s))"%(TD['new']['board'], TD['new']['model_id'], TD['new']['id']))[0]['count'] > 0 :
raise Exception, 'Model, place, board and vendor_parts must be unique! Record for this combination already exists.'

if (TD['new']['board'] is None) and (TD['new']['place'] is not None) and (TD['new']['vendor_parts'] is None):
if plpy.execute("SELECT count(*) FROM rma.component_specification where ((board is NULL)and(place='%s')and(vendor_parts is NULL)and(model_id=%s)and(id<>%s))"%(TD['new']['place'], TD['new']['model_id'], TD['new']['id']))[0]['count'] > 0 :
raise Exception, 'Model, place, board and vendor_parts must be unique! Record for this combination already exists.'

if (TD['new']['board'] is not None) and (TD['new']['place'] is not None) and (TD['new']['vendor_parts'] is None):
if plpy.execute("SELECT count(*) FROM rma.component_specification where ((board='%s')and(place='%s')and(vendor_parts is NULL)and(model_id=%s)and(id<>%s))"%(TD['new']['board'], TD['new']['place'], TD['new']['model_id'], TD['new']['id']))[0]['count'] > 0 :
raise Exception, 'Model, place, board and vendor_parts must be unique! Record for this combination already exists.'

if (TD['new']['board'] is None) and (TD['new']['place'] is None) and (TD['new']['vendor_parts'] is not None):
if plpy.execute("SELECT count(*) FROM rma.component_specification where ((board is NULL)and(place is NULL)and(vendor_parts='%s')and(model_id=%s)and(id<>%s))"%(TD['new']['vendor_parts'], TD['new']['model_id'], TD['new']['id']))[0]['count'] > 0 :
raise Exception, 'Model, place, board and vendor_parts must be unique! Record for this combination already exists.'

if (TD['new']['board'] is not None) and (TD['new']['place'] is None) and (TD['new']['vendor_parts'] is not None):
if plpy.execute("SELECT count(*) FROM rma.component_specification where ((board='%s')and(place is NULL)and(vendor_parts='%s')and(model_id=%s)and(id<>%s))"%(TD['new']['board'], TD['new']['vendor_parts'], TD['new']['model_id'], TD['new']['id']))[0]['count'] > 0 :
raise Exception, 'Model, place, board and vendor_parts must be unique! Record for this combination already exists.'

if (TD['new']['board'] is None) and (TD['new']['place'] is not None) and (TD['new']['vendor_parts'] is not None):
if plpy.execute("SELECT count(*) FROM rma.component_specification where ((board is NULL)and(place='%s')and(vendor_parts='%s')and(model_id=%s)and(id<>%s))"%(TD['new']['place'], TD['new']['vendor_parts'], TD['new']['model_id'], TD['new']['id']))[0]['count'] > 0 :
raise Exception, 'Model, place, board and vendor_parts must be unique! Record for this combination already exists.'

if (TD['new']['board'] is not None) and (TD['new']['place'] is not None) and (TD['new']['vendor_parts'] is not None):
if plpy.execute("SELECT count(*) FROM rma.component_specification where ((board='%s')and(place='%s')and(vendor_parts='%s')and(model_id=%s)and(id<>%s))"%(TD['new']['board'], TD['new']['place'], TD['new']['vendor_parts'], TD['new']['model_id'], TD['new']['id']))[0]['count'] > 0 :
raise Exception, 'Model, place, board and vendor_parts must be unique! Record for this combination already exists.'