0

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()
1
  • 2
    Why are you using raw SQL in Django, especially for such a trivial query? Commented Sep 14, 2017 at 7:21

1 Answer 1

4

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.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.