I am building a web app using Django framework of Python , DB is Sql server Azure ,using Pyodbc.
I have an issue i am unable to resolve , i am getting a parameter(file_name) which is a string and when running the query with the parameter i am getting empty results in the first case and
"sql = sql % tuple('?' * len(params))
TypeError: not all arguments converted during string formatting"
in the 2nd case , what am i doing wrong?
file_name=request.POST.get('filetodelete')
with connections['default'].cursor() as c:
1st case
parms=[file_name]
sql='select * from banks_row_data where file_name=%s'
c.execute (sql,parms)
test=c.fetchall()
2nd case
c.execute (sql,file_name)
test=c.fetchall()
Exprator
27.8k6 gold badges54 silver badges64 bronze badges
-
2Why are you using raw SQL in Django, especially for such a trivial query?Daniel Roseman– Daniel Roseman2017年09月14日 07:21:40 +00:00Commented Sep 14, 2017 at 7:21
1 Answer 1
pyodbc uses ? as the parameter placeholder, not %s.
sql = 'select * from banks_row_data where file_name = ?'
Note though that since you are using Django you really should be using the Django model layer fur this kind of query.
answered Sep 14, 2017 at 7:24
Daniel Roseman
602k68 gold badges911 silver badges924 bronze badges
Sign up to request clarification or add additional context in comments.
Comments
Explore related questions
See similar questions with these tags.
default