Python Check If Variable Exists And In Sql