Working in V2 Python Cloud Function in Azure, I am trying to implement a parameter from URL to a query to Azure SQL database. I am unable to do so when using SQL LIKE.
I have managed to set up a connection to the database. I also managed to use parameters from URL within the query using the decorators:
@app.route("select_name/{name_string}")
@app.sql_input(arg_name="people",
command_text="SELECT * FROM dbo.test WHERE name = @Name",
command_type="Text",
parameters="@Name={name_string}",
connection_string_setting="SqlConnectionString")
However, when I try to change the query from WHERE TO LIKE and combine it with UPPER like this:
@app.route("select_name/{name_string}")
@app.sql_input(arg_name="people",
command_text="SELECT * FROM dbo.test WHERE UPPER(name) LIKE UPPER('%@Name%')",
command_type="Text",
parameters="@Name={name_string}",
connection_string_setting="SqlConnectionString")
... I get the error description:
System.Private.CoreLib: Exception while executing function: Functions.get_people_by_name. Microsoft.Azure.WebJobs.Host: '%@Name%' does not resolve to a value.
I understand that parsing variables within SQL query does not want to work with such syntax.
How can I fix this? And maybe there more flexible methos for querying Azure SQL from a cloud function? Maybe you would recommend more python-based solutions, not necessarily relying on decorators?
Meanwhile, if you can point me to some good resources related to doing SQL queries from cloud function and constructing APIs, it would be much appreciated. I have found Azure Documentation not easy to work with and would love to find some good resources elsewhere.