Reputation: 1483
I am unable to call STORED Procedure
from Django
. I am able to call use the STORED Procedure
from normal python
program.
Sample working python
code
cursor = connect.cursor()
params=('IBM','2016')
cursor.execute("EXEC SP_Competitor_Extract ?, ? ",params)
This piece of code is working fine . But when i am trying to execute from Django
it does not working .
def index(request):
cursor = connection.cursor()
try:
params=["IBM", "2015"]
cursor.execute("{call SP_Competitor_Extract (?,?)}",params)
while cursor.nextset():
try:
results={'results':cursor.fetchall()}
break
except pyodbc.ProgrammingError:
continue
This is giving me the error message not all arguments converted during string formatting
Upvotes: 2
Views: 976
Reputation: 1483
Its working now in PYodbc
there is no callproc
. you can pass the argument directly . you dont need the place holder . In my case cursor.execute("{call SP_Competitor_Extract IBM,2016}")
worked . i am getting all the values as variable
and creating the SQL
.cursor.execute(SQL)
Upvotes: 0
Reputation: 14311
Django's internal .cursor()
method differs from pyodbc's method. Try this:
cursor.execute(
"EXEC SP_Competitor_Extract %s, %s",
[params]
)
For more information, the documentation covers it well here: https://docs.djangoproject.com/en/1.11/topics/db/sql/#executing-custom-sql-directly
The other option is to import connection
from pyodbc
and create a connection manually like you do in Python, with your Django DATABASES
settings variables. Good luck!
Upvotes: 3