Hi everyone I and try to do a query with the params pass by URL in my case the uRL is like
http://127.0.0.1:8000/api/cpuProjects/cpp/es
http://127.0.0.1:8000/api/cpuProjects/cpp,ad/es
My code to create the query is like this
def findElem(request, **kwargs):
projects_name = str(kwargs['project_name']).split(',')
status = str(kwargs['status'])
list_project = tuple(projects_name)
print(list_project)
query = "SELECT * FROM proj_cpus WHERE project in '%s'" % projects_name
print(query)
result = run_query(query)
the first return this query
SELECT * FROM proj_cpus WHERE project in '['cpp']'
the second one has to by a query like this
SELECT * FROM proj_cpus WHERE project in '['cpp', 'ad']'
In this case when I execute the query return that I have a error in the syntax, yes I know the [] is no correct
So I convert my params in a tuple so now the query is like that
and the error is
SELECT * FROM proj_cpus WHERE project in ('cpp')
SELECT * FROM proj_cpus WHERE project in ('cpp', 'ad')
not all arguments converted during string formatting
What is the best way to create the query?
Thanks in advance