0

I have a dictionary:

queryParameters = {
    "email":None,
    "party_type":'BUYER',
    "mobile":'9953610508'
}

I need to convert this into a sql where query excluding the None values. For this dict it would be something like this

select id from tff_party where deleted_at is null and mobile=9953610508 and party_type='BUYER';

I have created a function but string concatenation seems a problem here.

for key in queryParameters.keys():
    if queryParameters[key] is not None:
        res = key + "=" + queryParameters[key]
  • Writing fully dynamic and safe SQL queries is hard; you might want to consider using an ORM. At least, understand how to inject values safely, as demonstrated in [this Q&A](https://stackoverflow.com/q/902408/5320906). – snakecharmerb Sep 22 '22 at 18:49
  • Please provide enough code so others can better understand or reproduce the problem. – Community Sep 23 '22 at 11:01

0 Answers0