query SELECT r0 query_id FROM WHERE frm join rr_criteria for in range

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
query = "SELECT r0.query_id FROM %s WHERE %s"
frm = ', '.join('rr_criteria r%d' % (i,) for i in range(len(criteria
s)+1))
where = ' AND '.join("r0.query_id = r%(i)d.query_id AND "\
"r%(i)d.type_id = %(type_id)d AND "\
"r%(i)d.value = '%(value)s'" % {
'i': i+1,
'type_id': c.type.id,
'value': c.value.replace("'","\'")
} for i,c in enumerate(criterias))