I am fetching data from database using four select queries. The data is in such a way that there are cases when the input to select query may be empty. In that case it is okay for that particular select statement to not work. In short, what I want is that the four select statements should fire and whichever statements work should work irrespective of other query getting failed.
try:
cur.execute("select IP_ADD,VENDOR,DVC_ROLE,CIRCLE,SSA,REGION from DVC_SUMMARY_DATA where IP_ADD in (%s);" % ip_i)
except Exception as e:
print("error while fetching details " + str(e))
result_i = cur.fetchall()
try:
cur.execute("select IP_ADD,VENDOR,DVC_ROLE,CIRCLE,SSA,REGION from DVC_SUMMARY_DATA where IP_ADD in (%s);" % ip_n)
except Exception as e:
print("error while fetching details " + str(e))
result_n = cur.fetchall()
try:
cur.execute("select IP_ADD,VENDOR,DVC_ROLE,CIRCLE,SSA,REGION from DVC_SUMMARY_DATA where IP_ADD in (%s);" % ip_c)
except Exception as e:
print("error while fetching details " + str(e))
result_c = cur.fetchall()
try:
cur.execute("select IP_ADD,VENDOR,DVC_ROLE,CIRCLE,SSA,REGION from DVC_SUMMARY_DATA where IP_ADD in (%s);" % ip_b)
except Exception as e:
print("error while fetching details " + str(e))
result_b = cur.fetchall()
fetchall?forloop!ip_xvalues in a list and iterate through it. Side note: don't use string formatting to build queries.list.