2017-09-14 1 views
0

Python의 장고 프레임 워크를 사용하여 웹 응용 프로그램을 만들고 DB는 Pyodbc를 사용하여 Azure server Azure를 구축했습니다.Python에서 SQL Server 쿼리를 실행할 때 오류가 발생합니다.

I가 내가 빈 첫 번째 경우의 결과와

에서
"sql = sql % tuple('?' * len(params)) 
      TypeError: not all arguments converted during string formatting" 

무엇입니까 매개 변수와 쿼리를 실행할 때, 내가 문자열입니다 parameter(file_name)을 받고 있어요 해결할 수없는 나는 문제 두 번째 경우, 내가 뭘 잘못하고 있니?

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() 
+2

Django에서 원시 SQL을 사용하는 이유는 무엇입니까? 특히 그처럼 간단한 쿼리의 경우? –

답변

3

pyodbc 파라미터 자리하지 %s?로를 사용한다.

sql = 'select * from banks_row_data where file_name = ?' 

장고를 사용하고 있으므로 실제로 장고 모델 레이어 털을 이런 종류의 쿼리를 사용해야합니다.

관련 문제